Rozsvěcení a zhasínání světel, sprity pro místnosti, indikátory rozsvícených světel, po konci hry je hráč vrácen do hlavního menu
This commit is contained in:
parent
25a62af483
commit
55fd052072
27 changed files with 338 additions and 113 deletions
33
FNAF_Clone/GUI/EnemyUIElement.cs
Normal file
33
FNAF_Clone/GUI/EnemyUIElement.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MonoGameLibrary.Graphics;
|
||||
|
||||
namespace FNAF_Clone.GUI;
|
||||
|
||||
public class EnemyUIElement : UIElement {
|
||||
private int unlitTexturesId;
|
||||
private bool currentlyLit = true;
|
||||
|
||||
public EnemyUIElement(TextureRegion litTexture, TextureRegion unlitTexture, Point position, int drawPriority = 0) : base([litTexture, unlitTexture], position, drawPriority) {
|
||||
unlitTexturesId = 1;
|
||||
}
|
||||
|
||||
public EnemyUIElement(TextureRegion[] litTextures, TextureRegion[] unlitTextures, Point position, int drawPriority = 0) : base(litTextures.Concat(unlitTextures).ToArray(), position, drawPriority) {
|
||||
unlitTexturesId = litTextures.Length;
|
||||
}
|
||||
|
||||
public void SetTexture(bool lit, int id) {
|
||||
currentlyLit = lit;
|
||||
base.SetTexture(lit ? id : id + unlitTexturesId);
|
||||
}
|
||||
|
||||
public override void SetTexture(int id) {
|
||||
base.SetTexture(currentlyLit ? id : id + unlitTexturesId);
|
||||
}
|
||||
|
||||
public void SetTexture(bool lit) {
|
||||
if(lit == currentlyLit) return;
|
||||
currentlyLit = lit;
|
||||
SetTexture(lit ? currentTextureId - unlitTexturesId : currentTextureId);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,6 +68,8 @@ public class Screen {
|
|||
|
||||
public string Label{ get; }
|
||||
private Dictionary<string, UIElement> elements = new();
|
||||
private List<UIElement> elementsInDrawOrder = new();
|
||||
|
||||
public bool Active { get; private set; } = false;
|
||||
private InputListenerHook mouseInputHook = new(true);
|
||||
private bool temporary = false;
|
||||
|
|
@ -87,6 +89,15 @@ public class Screen {
|
|||
|
||||
public UIElement AddElement(string id, UIElement element) {
|
||||
elements.Add(id, element);
|
||||
|
||||
int insertIndex = elementsInDrawOrder.FindLastIndex(e => e.DrawPriority == element.DrawPriority);
|
||||
if (insertIndex == -1){
|
||||
elementsInDrawOrder.Add(element);
|
||||
}
|
||||
else{
|
||||
elementsInDrawOrder.Insert(insertIndex + 1, element);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +131,7 @@ public class Screen {
|
|||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch) {
|
||||
foreach (var val in elements.Values){
|
||||
foreach (var val in elementsInDrawOrder){
|
||||
val.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public class UIElement {
|
|||
public bool Active { get; set; } = true;
|
||||
public bool Pressable { get; set; } = false;
|
||||
public bool Visible { get; set; } = true;
|
||||
public int DrawPriority { get; } = 0;
|
||||
|
||||
protected (Point, Point) _bounds;
|
||||
public (Point, Point) Bounds{
|
||||
|
|
@ -45,14 +46,16 @@ public class UIElement {
|
|||
screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||
}
|
||||
|
||||
public UIElement(TextureRegion texture, Point position) {
|
||||
public UIElement(TextureRegion texture, Point position, int drawPriority = 0) {
|
||||
Textures.Add(texture);
|
||||
Bounds = (position, position + new Point(texture.Width, texture.Height));
|
||||
DrawPriority = drawPriority;
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
public UIElement(TextureRegion[] textures, Point position) {
|
||||
public UIElement(TextureRegion[] textures, Point position, int drawPriority = 0) {
|
||||
this.Textures.AddRange(textures);
|
||||
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||
DrawPriority = drawPriority;
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +65,7 @@ public class UIElement {
|
|||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
public void SetTexture(int textureId) {
|
||||
public virtual void SetTexture(int textureId) {
|
||||
if (textureId >= Textures.Count){
|
||||
Console.WriteLine($"WARNING: TEXTURE {textureId} OUT OF BOUNDS");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using FNAF_Clone.Map;
|
|||
using GlobalClassLib;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MonoGameLibrary;
|
||||
using MonoGameLibrary.Graphics;
|
||||
using MonoGameLibrary.Input;
|
||||
|
|
@ -37,6 +38,7 @@ public class UIManager {
|
|||
public static TextureAtlas OfficeAtlas{ get; private set; }
|
||||
public static TextureAtlas MonitorAtlas{ get; private set; }
|
||||
public static TextureAtlas EnemyAtlas{ get; private set; }
|
||||
public static TextureAtlas RoomAtlas{ get; private set; }
|
||||
public static SpriteFont PixelMonoFont{ get; private set; }
|
||||
|
||||
public static int GlobalPixelMultiplier{ get; private set; }
|
||||
|
|
@ -44,6 +46,8 @@ public class UIManager {
|
|||
// private Dictionary<(int, int), UIElement> doorElements = new();
|
||||
private static Dictionary<int, UIElement> enemyElements = new();
|
||||
private static TimerUIElement timerElement;
|
||||
private static UIElement cameraView;
|
||||
private static Dictionary<int, UIElement> lightIndicators = new();
|
||||
|
||||
private static InputListenerHook monitorSwitchHook;
|
||||
|
||||
|
|
@ -52,6 +56,7 @@ public class UIManager {
|
|||
OfficeAtlas = TextureAtlas.FromFile(Core.content, "images/office-definition.xml");
|
||||
MonitorAtlas = TextureAtlas.FromFile(Core.content, "images/monitor-definition.xml");
|
||||
EnemyAtlas = TextureAtlas.FromFile(Core.content, "images/enemies-definition.xml");
|
||||
RoomAtlas = TextureAtlas.FromFile(Core.content, "images/rooms-definition.xml");
|
||||
PixelMonoFont = Core.content.Load<SpriteFont>("ponderosa");
|
||||
}
|
||||
|
||||
|
|
@ -62,21 +67,28 @@ public class UIManager {
|
|||
// Screen.SetScreen(ScreenTypes.OFFICE);
|
||||
// Screen.SetOverlayScreen(ScreenTypes.OVERLAY);
|
||||
|
||||
officeScreen.AddElement("office_left", new UIElement([OfficeAtlas[3], OfficeAtlas[0]], Point.Zero));
|
||||
officeScreen.AddElement("office_centre", new UIElement([OfficeAtlas[4], OfficeAtlas[1]], new Point(200, 0)));
|
||||
officeScreen.AddElement("office_right", new UIElement([OfficeAtlas[5], OfficeAtlas[2]], new Point(440, 0)));
|
||||
officeScreen.AddElement("office_left", new UIElement([OfficeAtlas["left-open"], OfficeAtlas["left-closed"]], Point.Zero));
|
||||
officeScreen.AddElement("office_centre", new UIElement([OfficeAtlas["centre-open"], OfficeAtlas["centre-closed"]], new Point(200, 0)));
|
||||
officeScreen.AddElement("office_right", new UIElement([OfficeAtlas["right-open"], OfficeAtlas["right-closed"]], new Point(440, 0)));
|
||||
|
||||
// officeScreen.AddElement("test",
|
||||
// new UIElement(testAtlas[0], Point.Zero)
|
||||
// {Pressable = true, OnMousePress = () => Console.WriteLine("Pressed!")}
|
||||
// );
|
||||
|
||||
monitorScreen.AddElement("screen", new UIElement(MonitorAtlas[0], Point.Zero));
|
||||
monitorScreen.AddElement("view-frame", new UIElement(MonitorAtlas[1], new Point(62, 55)));
|
||||
monitorScreen.AddElement("map-frame", new UIElement(MonitorAtlas[2], new Point(334, 135)));
|
||||
monitorScreen.AddElement("map", new UIElement(MonitorAtlas[3], new Point(334, 135)));
|
||||
|
||||
monitorScreen.AddElement("screen", new UIElement(MonitorAtlas["screen"], Point.Zero));
|
||||
monitorScreen.AddElement("view-frame", new UIElement(MonitorAtlas["view-frame"], new Point(62, 55)));
|
||||
monitorScreen.AddElement("map-frame", new UIElement(MonitorAtlas["map-frame"], new Point(334, 135)));
|
||||
monitorScreen.AddElement("map", new UIElement(MonitorAtlas["map"], new Point(334, 135)));
|
||||
|
||||
List<TextureRegion> rooms = new();
|
||||
for (int i = 0; i < ClientMapManager.MAP_SIDE_LENGTH * ClientMapManager.MAP_SIDE_LENGTH; i++){
|
||||
rooms.Add(RoomAtlas["room" + i]);
|
||||
}
|
||||
cameraView = new UIElement(rooms.ToArray(), new(64, 64));
|
||||
monitorScreen.AddElement("camera-view", cameraView);
|
||||
|
||||
// main menu
|
||||
timerElement = new(new(0, 0), PixelMonoFont);
|
||||
overlayScreen.AddElement("timer", timerElement);
|
||||
officeScreen.AddElement("power-p1-office", new PowerIndicator(new(timerElement.Bounds.Item1.X, timerElement.Bounds.Item2.Y + 5), PixelMonoFont, Client.Player, "POWER: "));
|
||||
|
|
@ -126,22 +138,23 @@ public class UIManager {
|
|||
|
||||
CommandManager.AllowGameControls(true);
|
||||
UpdateCameras([Client.Player.state.camera]); // in case there is an enemy on the default camera
|
||||
|
||||
cameraView.SetTexture(Client.Player.state.camera);
|
||||
}
|
||||
public static void StartTimer() {
|
||||
timerElement.Start();
|
||||
}
|
||||
|
||||
public static void SpawnMapElements(TileConnectorProjection[] doors) {
|
||||
|
||||
for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server
|
||||
for (int j = 0; j < 5; j++){
|
||||
int i1 = i;
|
||||
int j1 = j;
|
||||
int id = ClientMapManager.CoordsToId(i, 4 - j);
|
||||
if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
|
||||
Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
|
||||
Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
|
||||
monitorScreen.AddElement($"room{ClientMapManager.CoordsToId(i, 4 - j)}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(ClientMapManager.Get((i1, 4 - j1)).Id))});
|
||||
monitorScreen.AddElement($"room{id}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(id))});
|
||||
lightIndicators.Add(id, monitorScreen.AddElement($"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1){Visible = false}));
|
||||
|
||||
//
|
||||
// if (doorPositions.ContainsKey((i, j))){
|
||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
|
|
@ -149,8 +162,8 @@ public class UIManager {
|
|||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas[24], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1));
|
||||
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas[23], MonitorAtlas[22]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1));
|
||||
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1));
|
||||
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1));
|
||||
|
||||
foreach (var door in doors){
|
||||
if(door.Type != ConnectorType.DOOR_REMOTE) continue;
|
||||
|
|
@ -161,16 +174,16 @@ public class UIManager {
|
|||
int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id;
|
||||
UIElement tile = monitorScreen["room"+targetId];
|
||||
|
||||
monitorScreen.AddElement("door"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas[5], MonitorAtlas[6]], tile.Bounds.Item1));
|
||||
monitorScreen.AddElement("door"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas["door-remote-open"], MonitorAtlas["door-remote-closed"]], tile.Bounds.Item1));
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas[7], MonitorAtlas[8]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas[9], MonitorAtlas[10]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas[11], MonitorAtlas[12]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas[13], MonitorAtlas[14]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas[15], MonitorAtlas[16]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas[17], MonitorAtlas[18]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas["door-office-p1-left-open"], MonitorAtlas["door-office-p1-left-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas["door-office-p1-centre-open"], MonitorAtlas["door-office-p1-centre-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas["door-office-p1-right-open"], MonitorAtlas["door-office-p1-right-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas["door-office-p2-right-open"], MonitorAtlas["door-office-p2-right-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -235,17 +248,28 @@ public class UIManager {
|
|||
|
||||
public static void ChangeCamera(int id) {
|
||||
monitorScreen["eye-player"].SetPosition(monitorScreen["room"+id].Bounds.Item1);
|
||||
cameraView.SetTexture(id);
|
||||
UpdateCameras([id]);
|
||||
}
|
||||
|
||||
public static void UpdateCameras(int[] camIds) {
|
||||
foreach (var id in camIds){
|
||||
MapTileProjection tile = ClientMapManager.Get(id);
|
||||
if(tile.Owner == null) continue;
|
||||
lightIndicators[id].Visible = tile.Lit;
|
||||
}
|
||||
|
||||
if (camIds.Contains(Client.Player.state.camera)){
|
||||
bool lit = ClientMapManager.Get(Client.Player.state.camera).Lit;
|
||||
cameraView.Visible = lit;
|
||||
enemyElements.Values.Where(e => e.Visible).ToList().ForEach(e => e.Visible = false);
|
||||
ClientEnemy[] enemies = ClientEnemyManager.GetByLocation(ClientMapManager.Get(Client.Player.state.camera));;
|
||||
ClientEnemy[] enemies = ClientEnemyManager.GetByLocation(ClientMapManager.Get(Client.Player.state.camera));
|
||||
foreach (var enemy in enemies){
|
||||
enemyElements.TryGetValue(enemy.Id, out var element);
|
||||
if (element == null) continue;
|
||||
element.Visible = true;
|
||||
EnemyUIElement enemyElement = (EnemyUIElement)element;
|
||||
enemyElement.Visible = true;
|
||||
enemyElement.SetTexture(lit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -269,15 +293,16 @@ public class UIManager {
|
|||
Screen.SetScreen(ScreenTypes.WIN);
|
||||
Screen.DisableOverlay();
|
||||
CommandManager.AllowGameControls(false);
|
||||
InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
|
||||
}
|
||||
|
||||
public static void ShowDeathScreen() {
|
||||
Screen.SetScreen(ScreenTypes.LOSE);
|
||||
Screen.DisableOverlay();
|
||||
CommandManager.AllowGameControls(false);
|
||||
InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
|
||||
}
|
||||
|
||||
|
||||
// private static Point GetRoomUIPos((int x, int y) pos) {
|
||||
// return new Point(336 + (32 * pos.x), 144 + (32 * pos.y));
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue