From b968b12090d910364e10c56f59c66ba5e0526ed0 Mon Sep 17 00:00:00 2001 From: Perry Date: Thu, 15 Jan 2026 19:56:50 +0100 Subject: [PATCH] =?UTF-8?q?P=C5=99id=C3=A1ny=20z=C3=A1klady=20u=C5=BEivate?= =?UTF-8?q?lsk=C3=A9ho=20rozhran=C3=AD=20a=20testovac=C3=AD=20textury.=20A?= =?UTF-8?q?ktualizovan=C3=A1=20Monogame=20library=20pro=20podporu=20my?= =?UTF-8?q?=C5=A1i?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FNAF_Clone.sln.DotSettings.user | 1 + FNAF_Clone/CommandManager.cs | 2 +- FNAF_Clone/Content/Content.mgcb | 15 +++ .../Content/images/SpriteSheet_testBlocks.png | Bin 0 -> 1978 bytes .../Content/images/testBlocks-definition.xml | 10 ++ FNAF_Clone/GUI/Screen.cs | 91 ++++++++++++++++++ FNAF_Clone/GUI/UIElement.cs | 40 ++++++++ FNAF_Clone/GameMain.cs | 34 +++++-- MonoGameLibrary | 2 +- 9 files changed, 184 insertions(+), 11 deletions(-) create mode 100644 FNAF_Clone/Content/images/SpriteSheet_testBlocks.png create mode 100755 FNAF_Clone/Content/images/testBlocks-definition.xml create mode 100644 FNAF_Clone/GUI/Screen.cs create mode 100644 FNAF_Clone/GUI/UIElement.cs diff --git a/FNAF_Clone.sln.DotSettings.user b/FNAF_Clone.sln.DotSettings.user index eba5de7..ac6c023 100644 --- a/FNAF_Clone.sln.DotSettings.user +++ b/FNAF_Clone.sln.DotSettings.user @@ -1,4 +1,5 @@  True + ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file diff --git a/FNAF_Clone/CommandManager.cs b/FNAF_Clone/CommandManager.cs index d2321f7..4f5763f 100644 --- a/FNAF_Clone/CommandManager.cs +++ b/FNAF_Clone/CommandManager.cs @@ -14,7 +14,7 @@ public class CommandManager { private static InputListenerHook toggleCamHook = new(true); 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() { diff --git a/FNAF_Clone/Content/Content.mgcb b/FNAF_Clone/Content/Content.mgcb index ddc4c36..9060f47 100644 --- a/FNAF_Clone/Content/Content.mgcb +++ b/FNAF_Clone/Content/Content.mgcb @@ -13,3 +13,18 @@ #---------------------------------- 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 + diff --git a/FNAF_Clone/Content/images/SpriteSheet_testBlocks.png b/FNAF_Clone/Content/images/SpriteSheet_testBlocks.png new file mode 100644 index 0000000000000000000000000000000000000000..87eba718768fa52ec9c7426f10893f2f8fdbc1b2 GIT binary patch literal 1978 zcmbuAc~sL^7RTT32P8C#Kv9x%#4zIsD66f-QIw#F2o4lb6j=;l8$j9wmB=O`MOvsh zCda8(Km^=aA_+7=fS3h$MX-txRw*cZ0!hG-1;YI3c219{=d?5byzRbo?>q0_@8^CK z7~o@qvBCfVOnmq33I+f|mOyNbLdHp%fP_rYiC~|dfZeuw8~}8Z@2(yDQ!dN;1p$+; zxCaVsHm(62V3s&}#o8YDM<}i#5M{}1F!(wkvYlmZ;`1@)e*vCanikb zKW1b~aYKLwKEj_OT>gE)IfB<_2(n(axCPJfsz1W%JT%hJp11nf?rWY--6HQR={yG^ zDu)!7sV3?58$>9-pB9zK*_XZMXT!nK`;6nwtW~1P@`dmh-h&DIoaeKo#=tYjTs+>L z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+1EQ@7kg(^)_(z+rAgBO literal 0 HcmV?d00001 diff --git a/FNAF_Clone/Content/images/testBlocks-definition.xml b/FNAF_Clone/Content/images/testBlocks-definition.xml new file mode 100755 index 0000000..7da4afc --- /dev/null +++ b/FNAF_Clone/Content/images/testBlocks-definition.xml @@ -0,0 +1,10 @@ + + + images/SpriteSheet_testBlocks + + + + + + + diff --git a/FNAF_Clone/GUI/Screen.cs b/FNAF_Clone/GUI/Screen.cs new file mode 100644 index 0000000..962a742 --- /dev/null +++ b/FNAF_Clone/GUI/Screen.cs @@ -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 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 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 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); + } + } +} \ No newline at end of file diff --git a/FNAF_Clone/GUI/UIElement.cs b/FNAF_Clone/GUI/UIElement.cs new file mode 100644 index 0000000..bef026e --- /dev/null +++ b/FNAF_Clone/GUI/UIElement.cs @@ -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); + } +} \ No newline at end of file diff --git a/FNAF_Clone/GameMain.cs b/FNAF_Clone/GameMain.cs index 95f2e8f..b6076c9 100644 --- a/FNAF_Clone/GameMain.cs +++ b/FNAF_Clone/GameMain.cs @@ -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.Input; using MonoGameLibrary; +using MonoGameLibrary.Graphics; using MonoGameLibrary.Input; namespace FNAF_Clone; -public class GameMain() : Core("fnafkooo", 1920, 1080, false) { - private GraphicsDeviceManager _graphics; - private SpriteBatch _spriteBatch; +public class GameMain() : Core("fnafkooo", 640, 360, false) { + // private GraphicsDeviceManager _graphics; + // private SpriteBatch _spriteBatch; + + private Screen officeScreen = new(Screen.ScreenType.OFFICE); + + private TextureAtlas testAtlas; protected override void Initialize() { Client.Connect("127.0.0.1", 9012); CommandManager.InitInputListeners(); + InputManager.AddListener(InputManager.MouseButton.LEFT, (() => Console.WriteLine("LMB pressed at: " + InputManager.MouseState.Position)), InputTiming.PRESS, new InputListenerHook(true)); + + base.Initialize(); } protected override void LoadContent() { - _spriteBatch = new SpriteBatch(GraphicsDevice); - + // spriteBatch = new SpriteBatch(GraphicsDevice); + testAtlas = TextureAtlas.FromFile(content, "images/testBlocks-definition.xml"); - // TODO: use this.Content to load your game content here + Screen.AddScreen("office", officeScreen, true); + officeScreen.AddElement("test", + new UIElement(testAtlas[0], Point.Zero) + {Pressable = true, OnMousePress = () => Console.WriteLine("Pressed!")} + ); } protected override void Update(GameTime gameTime) { @@ -39,9 +53,11 @@ public class GameMain() : Core("fnafkooo", 1920, 1080, false) { protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); + spriteBatch.Begin(); + + Screen.CurrentScreen.Draw(spriteBatch); - // TODO: Add your drawing code here - + spriteBatch.End(); base.Draw(gameTime); } } \ No newline at end of file diff --git a/MonoGameLibrary b/MonoGameLibrary index a2b524e..182ebfc 160000 --- a/MonoGameLibrary +++ b/MonoGameLibrary @@ -1 +1 @@ -Subproject commit a2b524ee04772d483750047c997172cc62090a9a +Subproject commit 182ebfc31c37c0759b5a41c1921273f1ba55b759