From 7656707177db2d156b9d1c6c02f1500946779c2c Mon Sep 17 00:00:00 2001 From: Perry Date: Wed, 11 Mar 2026 22:35:30 +0100 Subject: [PATCH] =?UTF-8?q?Hlavn=C3=AD=20menu,=20synchronizace=20jmen=20hr?= =?UTF-8?q?=C3=A1=C4=8D=C5=AF.=20Client=20hru=20spust=C3=AD=20a=C5=BE=20ve?= =?UTF-8?q?=20chv=C3=ADli=20kdy=20dostane=20spr=C3=A1vn=C3=BD=20packet.=20?= =?UTF-8?q?Oprava=20bugu=20v=20se=20scalov=C3=A1n=C3=ADm=20UIElementu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FNAF_Clone.sln.DotSettings.user | 2 + FNAF_Clone/Client.cs | 33 ++++++-- FNAF_Clone/CommandManager.cs | 2 +- FNAF_Clone/Content/ponderosa.spritefont | 2 +- FNAF_Clone/EventProcessor.cs | 5 ++ FNAF_Clone/GUI/LoadingUIElement.cs | 37 ++++++++ FNAF_Clone/GUI/MenuInputField.cs | 45 ++++++++++ FNAF_Clone/GUI/PointExtensions.cs | 2 + FNAF_Clone/GUI/Screen.cs | 16 ++-- FNAF_Clone/GUI/TextBoxUIElement.cs | 42 +++++++++ FNAF_Clone/GUI/TextUIElement.cs | 39 +++++++-- FNAF_Clone/GUI/TimerUIElement.cs | 2 +- FNAF_Clone/GUI/UIElement.cs | 12 +-- FNAF_Clone/GUI/UIManager.cs | 108 +++++++++++++++++++----- FNAF_Clone/GameMain.cs | 9 +- FNAF_Server/GameLogic.cs | 6 +- FNAF_Server/Server.cs | 4 +- PacketLib/GameEvent.cs | 1 + PacketLib/OpponentInitPacket.cs | 1 + 19 files changed, 315 insertions(+), 53 deletions(-) create mode 100644 FNAF_Clone/GUI/LoadingUIElement.cs create mode 100644 FNAF_Clone/GUI/MenuInputField.cs create mode 100644 FNAF_Clone/GUI/TextBoxUIElement.cs diff --git a/FNAF_Clone.sln.DotSettings.user b/FNAF_Clone.sln.DotSettings.user index f51aa32..407f818 100644 --- a/FNAF_Clone.sln.DotSettings.user +++ b/FNAF_Clone.sln.DotSettings.user @@ -5,11 +5,13 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file diff --git a/FNAF_Clone/Client.cs b/FNAF_Clone/Client.cs index 3fa6d5c..6955f2b 100644 --- a/FNAF_Clone/Client.cs +++ b/FNAF_Clone/Client.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Net; using System.Net.Sockets; +using System.Threading; using FNAF_Clone.GUI; using FNAF_Clone.Map; using GlobalClassLib; @@ -11,7 +12,21 @@ using PacketLib; namespace FNAF_Clone; -public class Client { +public class Client { + public enum ConnectionState { + IDLE, + CONNECTING, + CONNECTED, + ACCEPTED, + GAME_STARTING, + GAME_IN_PROGRESS, + SERVER_NOT_FOUND, + SERVER_FULL, + ERROR + } + + public static ConnectionState State { get; private set; } = ConnectionState.IDLE; + private static EventBasedNetListener listener = new(); private static NetManager client; private static NetPeer server; @@ -24,6 +39,7 @@ public class Client { public static ClientPlayer GetPlayer(int pid) => Player.state.pid == pid ? Player : Opponent; public static void Connect(string endPoint, int port) { + State = ConnectionState.CONNECTING; writer = new NetDataWriter(); processor = new NetPacketProcessor(); @@ -32,7 +48,11 @@ public class Client { processor.SubscribeReusable(OnJoinAccept); processor.SubscribeReusable(OnPlayerUpdate); processor.SubscribeReusable(OnMapInit); - processor.SubscribeReusable(packet => Opponent.state = packet.state); + processor.SubscribeReusable(packet => { // TODO: move this to a method + Opponent.state = packet.state; + Opponent.username = packet.username; + State = ConnectionState.GAME_STARTING; + }); client = new NetManager(listener){ AutoRecycle = true @@ -48,10 +68,11 @@ public class Client { listener.PeerConnectedEvent += peer => { Console.WriteLine("Connected to Server"); server = peer; - SendPacket(new JoinPacket {username = "Player1"}, DeliveryMethod.ReliableOrdered); + State = ConnectionState.CONNECTED; + SendPacket(new JoinPacket {username = Player.username == "" ? "Anonymous" : Player.username}, DeliveryMethod.ReliableOrdered); }; - client.Connect(endPoint, port, ""); // TODO: figure out how keys work + new Thread(() => client.Connect(endPoint, port, "")).Start(); // TODO: figure out how keys work } public static void SendPacket(T packet, DeliveryMethod deliveryMethod) where T : class, new() { @@ -71,6 +92,7 @@ public class Client { private static void OnJoinAccept(JoinAcceptPacket packet) { Console.WriteLine($"Accepted by server, pid: {packet.state.pid}"); + State = ConnectionState.ACCEPTED; Player.state = packet.state; } @@ -83,8 +105,7 @@ public class Client { TileConnectorProjection[] connectors = connectorsData.Select(c => new TileConnectorProjection(ClientMapManager.Get(c.id1), ClientMapManager.Get(c.id2), c.type)).ToArray(); ClientMapManager.InitConnectors(connectors); - UIManager.InitUI(); - UIManager.SpawnDoors(connectors.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray()); + UIManager.SpawnMapElements(connectors.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray()); } diff --git a/FNAF_Clone/CommandManager.cs b/FNAF_Clone/CommandManager.cs index c21cdbe..73cba39 100644 --- a/FNAF_Clone/CommandManager.cs +++ b/FNAF_Clone/CommandManager.cs @@ -25,7 +25,7 @@ public class CommandManager { Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, allControlsHook)); } - public static void AllowInput(bool state) { + public static void AllowGameControls(bool state) { allControlsHook.Enabled = state; } diff --git a/FNAF_Clone/Content/ponderosa.spritefont b/FNAF_Clone/Content/ponderosa.spritefont index fa8b598..27d8754 100755 --- a/FNAF_Clone/Content/ponderosa.spritefont +++ b/FNAF_Clone/Content/ponderosa.spritefont @@ -17,7 +17,7 @@ with. Size is a float value, measured in points. Modify this value to change the size of the font. --> - 20 + 40