Renderování textu, jumpscary, win a lose screen

This commit is contained in:
Perry 2026-03-09 20:05:21 +01:00
parent 9bfe63a166
commit e6128dc9f5
21 changed files with 360 additions and 84 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Microsoft.VisualBasic.CompilerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGameLibrary.Input;
@ -10,6 +11,7 @@ public class Screen {
public static Dictionary<string, Screen> Screens = new();
public static Screen CurrentScreen{ get; private set; } = Empty;
public static Screen OverlayScreen{ get; private set; } = Empty;
public static void AddScreens(Screen[] screens) {
foreach (var screen in screens){
@ -22,7 +24,10 @@ public class Screen {
}
public static void SetScreen(string id) {
if (CurrentScreen != null){
if (CurrentScreen.temporary){
Screens.Remove(CurrentScreen.Label);
}
else if (CurrentScreen != null){
CurrentScreen.Active = false;
}
CurrentScreen = Screens[id];
@ -33,14 +38,35 @@ public class Screen {
Screens.Remove(id);
}
public static Screen Empty => new("");
public static void UpdateAll() {
foreach (var screen in Screens.Values){
// if (!screen.Active) continue;
screen.Update();
}
}
public static Screen Empty => new(""){temporary = true};
public static void SetOverlayScreen(string id) {
OverlayScreen = Screens[id];
}
public static void DisableOverlay() {
OverlayScreen = Empty;
}
public static void DrawCurrentAndOverlay(SpriteBatch spriteBatch) {
CurrentScreen.Draw(spriteBatch);
OverlayScreen.Draw(spriteBatch);
}
public string Label;
public string Label{ get; }
private Dictionary<string, UIElement> elements = new();
public bool Active { get; private set; } = false;
private InputListenerHook mouseInputHook = new(true);
private bool temporary = false;
public Screen(string label) {
Label = label;
InputManager.AddListener(InputManager.MouseButton.LEFT, () => ProcessMouseInput(InputManager.MouseState), InputTiming.PRESS, mouseInputHook);
@ -81,8 +107,9 @@ public class Screen {
}
public void Update() {
foreach (var keyValuePair in elements){
keyValuePair.Value.Update();
foreach (var element in elements.Values){
if (!element.Active) continue;
element.Update();
}
}