Přidány základy uživatelského rozhraní a testovací textury. Aktualizovaná Monogame library pro podporu myši
This commit is contained in:
parent
4561e254d4
commit
b968b12090
9 changed files with 184 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003Fb5_003F8dc24573_003FCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||||
|
|
@ -14,7 +14,7 @@ public class CommandManager {
|
||||||
private static InputListenerHook toggleCamHook = new(true);
|
private static InputListenerHook toggleCamHook = new(true);
|
||||||
|
|
||||||
public static void InitInputListeners() {
|
public static void InitInputListeners() {
|
||||||
Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, _ => tuple.action(), InputTiming.PRESS, toggleCamHook));
|
Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, toggleCamHook));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ToggleCamera() {
|
private static void ToggleCamera() {
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,18 @@
|
||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
||||||
|
#begin images/SpriteSheet_testBlocks.png
|
||||||
|
/importer:TextureImporter
|
||||||
|
/processor:TextureProcessor
|
||||||
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
/processorParam:ColorKeyEnabled=True
|
||||||
|
/processorParam:GenerateMipmaps=False
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
|
/processorParam:MakeSquare=False
|
||||||
|
/processorParam:TextureFormat=Color
|
||||||
|
/build:images/SpriteSheet_testBlocks.png
|
||||||
|
|
||||||
|
#begin images/testBlocks-definition.xml
|
||||||
|
/copy:images/testBlocks-definition.xml
|
||||||
|
|
||||||
|
|
|
||||||
BIN
FNAF_Clone/Content/images/SpriteSheet_testBlocks.png
Normal file
BIN
FNAF_Clone/Content/images/SpriteSheet_testBlocks.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
10
FNAF_Clone/Content/images/testBlocks-definition.xml
Executable file
10
FNAF_Clone/Content/images/testBlocks-definition.xml
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextureAtlas count="4">
|
||||||
|
<Texture>images/SpriteSheet_testBlocks</Texture>
|
||||||
|
<Regions>
|
||||||
|
<Region id = "0" name="R128" x="0" y="0" width="128" height="128"/>
|
||||||
|
<Region id = "1" name="B128" x="128" y="0" width="128" height="128"/>
|
||||||
|
<Region id = "2" name="R64" x="0" y="128" width="64" height="64"/>
|
||||||
|
<Region id = "3" name="B64" x="64" y="128" width="64" height="64"/>
|
||||||
|
</Regions>
|
||||||
|
</TextureAtlas>
|
||||||
91
FNAF_Clone/GUI/Screen.cs
Normal file
91
FNAF_Clone/GUI/Screen.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonoGameLibrary.Input;
|
||||||
|
|
||||||
|
namespace FNAF_Clone.GUI;
|
||||||
|
|
||||||
|
|
||||||
|
public class Screen {
|
||||||
|
|
||||||
|
public static Dictionary<string, Screen> Screens = new();
|
||||||
|
public static Screen CurrentScreen{ get; private set; }
|
||||||
|
|
||||||
|
public static void AddScreens((string id, Screen screen)[] screens) {
|
||||||
|
foreach (var tuple in screens){
|
||||||
|
Screens.Add(tuple.id, tuple.screen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void AddScreen(string id, Screen screen, bool activate = false) {
|
||||||
|
Screens.Add(id, screen);
|
||||||
|
if (activate) SetScreen(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetScreen(string id) {
|
||||||
|
CurrentScreen = Screens[id];
|
||||||
|
CurrentScreen.Active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveScreen(string id) {
|
||||||
|
Screens.Remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ScreenType {
|
||||||
|
MAIN_MENU,
|
||||||
|
OFFICE,
|
||||||
|
CAMERAS
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ScreenType Type{ get; private set; }
|
||||||
|
private Dictionary<string, UIElement> elements = new();
|
||||||
|
public bool Active { get; private set; } = false;
|
||||||
|
private InputListenerHook mouseInputHook = new(true);
|
||||||
|
|
||||||
|
public Screen(ScreenType type) {
|
||||||
|
Type = type;
|
||||||
|
InputManager.AddListener(InputManager.MouseButton.LEFT, () => ProcessMouseInput(InputManager.MouseState), InputTiming.PRESS, mouseInputHook);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Screen(ScreenType type, Dictionary<string, UIElement> elements) {
|
||||||
|
this.elements = elements;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddElement(string id, UIElement element) {
|
||||||
|
elements.Add(id, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetActive(bool active) {
|
||||||
|
Active = active;
|
||||||
|
if (Active == active) return;
|
||||||
|
foreach (var keyValuePair in elements){
|
||||||
|
keyValuePair.Value.Active = Active;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessMouseInput(MouseState mouseState) {
|
||||||
|
foreach (var element in elements.Values){
|
||||||
|
if (!element.Pressable) continue;
|
||||||
|
|
||||||
|
if (element.IsWithinBounds(mouseState.Position)){
|
||||||
|
element.OnMousePress(); // TODO: differentiate between press, hold and release events
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update() {
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var keyValuePair in elements){
|
||||||
|
keyValuePair.Value.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(SpriteBatch spriteBatch) {
|
||||||
|
foreach (var val in elements.Values){
|
||||||
|
val.Draw(spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
FNAF_Clone/GUI/UIElement.cs
Normal file
40
FNAF_Clone/GUI/UIElement.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
using System;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using MonoGameLibrary.Graphics;
|
||||||
|
using MonoGameLibrary.Input;
|
||||||
|
|
||||||
|
namespace FNAF_Clone.GUI;
|
||||||
|
|
||||||
|
public class UIElement {
|
||||||
|
public bool Active { get; set; } = false;
|
||||||
|
public bool Pressable { get; set; } = false;
|
||||||
|
|
||||||
|
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes
|
||||||
|
private TextureRegion texture;
|
||||||
|
|
||||||
|
public UIElement(TextureRegion texture, Point position) {
|
||||||
|
this.texture = texture;
|
||||||
|
bounds = (position, position + new Point(texture.Width, texture.Height));
|
||||||
|
}
|
||||||
|
public void Update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsWithinBounds(Point pos) {
|
||||||
|
return pos.X >= Math.Min(bounds.Item1.X, bounds.Item2.X) && pos.X <= Math.Max(bounds.Item1.X, bounds.Item2.X) &&
|
||||||
|
pos.Y >= Math.Min(bounds.Item1.Y, bounds.Item2.Y) && pos.Y <= Math.Max(bounds.Item1.Y, bounds.Item2.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action OnMousePress{ get; set; }
|
||||||
|
|
||||||
|
// public virtual void OnMousePress() { }
|
||||||
|
|
||||||
|
public virtual void OnMouseRelease() { }
|
||||||
|
|
||||||
|
public virtual void OnMouseHold() { }
|
||||||
|
|
||||||
|
public void Draw(SpriteBatch spriteBatch) {
|
||||||
|
texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,27 +1,41 @@
|
||||||
using Microsoft.Xna.Framework;
|
using System;
|
||||||
|
using FNAF_Clone.GUI;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MonoGameLibrary;
|
using MonoGameLibrary;
|
||||||
|
using MonoGameLibrary.Graphics;
|
||||||
using MonoGameLibrary.Input;
|
using MonoGameLibrary.Input;
|
||||||
|
|
||||||
namespace FNAF_Clone;
|
namespace FNAF_Clone;
|
||||||
|
|
||||||
public class GameMain() : Core("fnafkooo", 1920, 1080, false) {
|
public class GameMain() : Core("fnafkooo", 640, 360, false) {
|
||||||
private GraphicsDeviceManager _graphics;
|
// private GraphicsDeviceManager _graphics;
|
||||||
private SpriteBatch _spriteBatch;
|
// private SpriteBatch _spriteBatch;
|
||||||
|
|
||||||
|
private Screen officeScreen = new(Screen.ScreenType.OFFICE);
|
||||||
|
|
||||||
|
private TextureAtlas testAtlas;
|
||||||
|
|
||||||
protected override void Initialize() {
|
protected override void Initialize() {
|
||||||
Client.Connect("127.0.0.1", 9012);
|
Client.Connect("127.0.0.1", 9012);
|
||||||
CommandManager.InitInputListeners();
|
CommandManager.InitInputListeners();
|
||||||
|
|
||||||
|
InputManager.AddListener(InputManager.MouseButton.LEFT, (() => Console.WriteLine("LMB pressed at: " + InputManager.MouseState.Position)), InputTiming.PRESS, new InputListenerHook(true));
|
||||||
|
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadContent() {
|
protected override void LoadContent() {
|
||||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
// spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
|
testAtlas = TextureAtlas.FromFile(content, "images/testBlocks-definition.xml");
|
||||||
|
|
||||||
|
Screen.AddScreen("office", officeScreen, true);
|
||||||
// TODO: use this.Content to load your game content here
|
officeScreen.AddElement("test",
|
||||||
|
new UIElement(testAtlas[0], Point.Zero)
|
||||||
|
{Pressable = true, OnMousePress = () => Console.WriteLine("Pressed!")}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime) {
|
protected override void Update(GameTime gameTime) {
|
||||||
|
|
@ -39,9 +53,11 @@ public class GameMain() : Core("fnafkooo", 1920, 1080, false) {
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime) {
|
protected override void Draw(GameTime gameTime) {
|
||||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
|
spriteBatch.Begin();
|
||||||
|
|
||||||
// TODO: Add your drawing code here
|
Screen.CurrentScreen.Draw(spriteBatch);
|
||||||
|
|
||||||
|
spriteBatch.End();
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit a2b524ee04772d483750047c997172cc62090a9a
|
Subproject commit 182ebfc31c37c0759b5a41c1921273f1ba55b759
|
||||||
Loading…
Add table
Add a link
Reference in a new issue