Bugfixy, odstranění nepoužívaných tříd CameraSystem a ITargetingEnemy, přidání dedikované třídy ReturnToMenuElement, předělání pathfinding algoritmu z DFS na BFS, přesun správy obtížnosti do abstraktní třídy Enemy, přidání scriptů pro kompilaci na aplikaci nevyžadující dotnet

This commit is contained in:
Perry 2026-03-25 16:37:18 +01:00
parent ceac37920b
commit e5d746d597
24 changed files with 258 additions and 138 deletions

View file

@ -1,14 +1,15 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace ONDClient.GUI;
public class LoadingUIElement : TextUIElement {
private string expectedEndpoint;
private Func<string> expectedEndpointGetter;
private Client.ConnectionState lastState = Client.ConnectionState.IDLE;
public LoadingUIElement(Point corner1, SpriteFont font, string expectedEndpoint, Alignment alignment = Alignment.CENTER, bool autoBounds = true) : base(corner1, font, alignment, autoBounds) {
this.expectedEndpoint = expectedEndpoint;
public LoadingUIElement(Point corner1, SpriteFont font, Func<string> expectedEndpointGetter, Alignment alignment = Alignment.CENTER, bool autoBounds = true) : base(corner1, font, alignment, autoBounds) {
this.expectedEndpointGetter = expectedEndpointGetter;
Active = true;
// Color = Color.LightGray;
}
@ -19,10 +20,10 @@ public class LoadingUIElement : TextUIElement {
switch (Client.State){
case Client.ConnectionState.CONNECTING:
Text = "Connecting to " + expectedEndpoint;
Text = "Connecting to " + expectedEndpointGetter();
break;
case Client.ConnectionState.CONNECTED:
Text = "Connected to " + expectedEndpoint;
Text = "Connected to " + expectedEndpointGetter();
break;
case Client.ConnectionState.ACCEPTED:
Text = "Waiting for opponent...";
@ -32,6 +33,12 @@ public class LoadingUIElement : TextUIElement {
Color = Color.White;
// ScaleMultiplier = 1.5f;
break;
case Client.ConnectionState.IDLE:
Text = "Idle";
break;
case Client.ConnectionState.DISCONNECTED:
Text = "Disconnected: " + Client.StatusText;
break;
}
}
}

View file

@ -0,0 +1,40 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGameLibrary.Input;
namespace ONDClient.GUI;
public class ReturnToMenuElement : TextUIElement{
private bool listening = false;
private InputListenerHook inputHook;
public ReturnToMenuElement(Point corner1, SpriteFont font, Alignment alignment = Alignment.CENTER) : base(corner1, font, alignment, false) {
Visible = false;
Text = "Press Space to return to main menu";
inputHook = new InputListenerHook(false);
InputManager.AddListener("return-to-menu",Keys.Space, () => {
UIManager.DisplayMainMenu();
listening = false;
Visible = false;
Client.Disconnect();
},
InputTiming.PRESS, inputHook);
}
public override void Update() {
if ((Client.State == Client.ConnectionState.IDLE || Client.State == Client.ConnectionState.DISCONNECTED || Client.State == Client.ConnectionState.ACCEPTED) &&
(Screen.CurrentScreen.Label == UIManager.ScreenTypes.LOADING || Screen.CurrentScreen.Label == UIManager.ScreenTypes.LOSE || Screen.CurrentScreen.Label == UIManager.ScreenTypes.WIN)){
if (!listening){
listening = true;
Visible = true;
inputHook.Enabled = true;
}
}
else {
Visible = false;
listening = false;
inputHook.Enabled = false;
}
}
}

View file

@ -27,13 +27,16 @@ public class TextUIElement : UIElement {
Font = font;
AutoBounds = autoBounds;
Align(alignment);
Visible = true;
}
public TextUIElement(Point corner1, Point corner2, SpriteFont font, Alignment alignment = Alignment.LEFT) : base(corner1, corner2) {
Font = font;
Align(alignment);
Visible = true;
}
public override void Draw(SpriteBatch spriteBatch) {
if(!Visible || !Active) return;
base.Draw(spriteBatch);
align();
spriteBatch.DrawString(Font, Text, screenSpaceBounds.Item1.ToVector2(), Color, 0, origin, pixelScaleMultiplier * UNIVERSAL_TEXT_SCALE_MULTIPLIER, SpriteEffects.None, 0);

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net.Mime;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGameLibrary;
@ -89,9 +90,10 @@ public class UIElement {
public virtual void OnMouseHold() { }
public virtual void Draw(SpriteBatch spriteBatch) {
if (!Visible || !Active){
if (!Visible || !Active || Textures.Count == 0){
return;
}
Textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
}

View file

@ -107,9 +107,13 @@ public class UIManager {
TextUIElement powerP1 = (TextUIElement)
monitorScreen.AddElement("power-p2", new PowerIndicator(new(powerLabel.Bounds.Item1.X + 10, powerLabel.Bounds.Item2.Y + 10), PixelMonoFont, Client.Opponent, ""){Color = new Color(220, 10, 10, 255)});
monitorScreen.AddElement("power-p1", new PowerIndicator( new (powerP1.Bounds.Item1.X, powerP1.Bounds.Item2.Y + 5), PixelMonoFont, Client.Player, ""){Color = new Color(15, 190, 247, 255)});
ReturnToMenuElement returnToMenuElement = new ReturnToMenuElement(new(320, 290), PixelMonoFont);
winScreen.AddElement("win-text", new TextUIElement(new(320, 180), PixelMonoFont, TextUIElement.Alignment.CENTER){Text = "YOU WIN", Color = Color.Green});
loseScreen.AddElement("lose-text", new TextUIElement(new(320, 180), PixelMonoFont, TextUIElement.Alignment.CENTER){Text = "YOU LOSE", Color = Color.Red});
winScreen.AddElement("press-space", returnToMenuElement);
loseScreen.AddElement("press-space", returnToMenuElement);
loadingScreen.AddElement("press-space", returnToMenuElement);
MenuInputField usernameField = (MenuInputField)menuScreen.AddElement("username-field", new MenuInputField(PixelMonoFont, new(20, 20), "USERNAME: "));
MenuInputField field = (MenuInputField)menuScreen.AddElement("server-ip-field", new MenuInputField(PixelMonoFont, new(usernameField.Bounds.Item1.X, usernameField.Bounds.Item2.Y + 20), "SERVER IP: ", "127.0.0.1"));
@ -118,9 +122,7 @@ public class UIManager {
Text = "CONNECT",
Pressable = true,
OnMousePress = () => {
// string[] input = serverIpTextBox.Text.Split(":");
// if(input.Length != 2 || !int.TryParse(input[0], out var port)) return;
// Client.Connect(input[0], port);
Client.Player.username = usernameField.Text;
Client.Connect(field.Text, 9012);
Screen.SetScreen(ScreenTypes.LOADING);
@ -136,7 +138,7 @@ public class UIManager {
}});
loadingScreen.AddElement("loading-text", new LoadingUIElement(new(320, 180), PixelMonoFont, field.Text));
loadingScreen.AddElement("loading-text", new LoadingUIElement(new(320, 180), PixelMonoFont, () => field.Text));
}
@ -319,7 +321,8 @@ public class UIManager {
Screen.DisableOverlay();
CommandManager.AllowGameControls(false);
SoundManager.StopAmbience();
InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
SoundManager.StopNekoPurr();
// InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
}
public static void ShowDeathScreen() {
@ -327,8 +330,8 @@ public class UIManager {
Screen.DisableOverlay();
CommandManager.AllowGameControls(false);
SoundManager.StopAmbience();
InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
SoundManager.StopNekoPurr();
// InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
}
public static void ResetUI() {
@ -345,4 +348,8 @@ public class UIManager {
// return new Point(336 + (32 * pos.x), 144 + (32 * pos.y));
// }
public static void SetLoadingScreenMessage(string text) {
}
}