Přidány sprity pro kancelář a monitor. Graficky viditelné zavírání a otevírání dveří, zapínání a vypínání monitoru. Podpora pouze pro specifická rozlišení.
This commit is contained in:
parent
952aae10de
commit
2cd215cc33
13 changed files with 202 additions and 41 deletions
7
FNAF_Clone/GUI/PointExtensions.cs
Normal file
7
FNAF_Clone/GUI/PointExtensions.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace FNAF_Clone.GUI;
|
||||
|
||||
public static class PointExtensions {
|
||||
public static Point MultiplyByScalar(this Point point, int scalar) => new(point.X * scalar, point.Y * scalar);
|
||||
}
|
||||
|
|
@ -11,9 +11,9 @@ public class Screen {
|
|||
public static Dictionary<string, Screen> 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 AddScreens(Screen[] screens) {
|
||||
foreach (var screen in screens){
|
||||
Screens.Add(screen.Label, screen);
|
||||
}
|
||||
}
|
||||
public static void AddScreen(string id, Screen screen, bool activate = false) {
|
||||
|
|
@ -29,28 +29,24 @@ public class Screen {
|
|||
public static void RemoveScreen(string id) {
|
||||
Screens.Remove(id);
|
||||
}
|
||||
|
||||
public enum ScreenType {
|
||||
MAIN_MENU,
|
||||
OFFICE,
|
||||
CAMERAS
|
||||
}
|
||||
|
||||
|
||||
public ScreenType Type{ get; private set; }
|
||||
|
||||
|
||||
public string Label;
|
||||
private Dictionary<string, UIElement> elements = new();
|
||||
public bool Active { get; private set; } = false;
|
||||
private InputListenerHook mouseInputHook = new(true);
|
||||
|
||||
public Screen(ScreenType type) {
|
||||
Type = type;
|
||||
public Screen(string label) {
|
||||
Label = label;
|
||||
InputManager.AddListener(InputManager.MouseButton.LEFT, () => ProcessMouseInput(InputManager.MouseState), InputTiming.PRESS, mouseInputHook);
|
||||
}
|
||||
|
||||
public Screen(ScreenType type, Dictionary<string, UIElement> elements) {
|
||||
public Screen(string label, Dictionary<string, UIElement> elements) {
|
||||
this.elements = elements;
|
||||
Type = type;
|
||||
Label = label;
|
||||
}
|
||||
|
||||
public UIElement this[string id] => elements[id];
|
||||
|
||||
public void AddElement(string id, UIElement element) {
|
||||
elements.Add(id, element);
|
||||
|
|
|
|||
|
|
@ -1,21 +1,56 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MonoGameLibrary;
|
||||
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;
|
||||
private List<TextureRegion> textures = new();
|
||||
private int currentTextureId = 0;
|
||||
|
||||
private float _scaleMultiplier = 1;
|
||||
public float ScaleMultiplier{
|
||||
get{
|
||||
return _scaleMultiplier;
|
||||
}
|
||||
set{
|
||||
_scaleMultiplier = value;
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
}
|
||||
private float pixelScaleMultiplier = 1;
|
||||
private void LoadPixelScaleMultiplier() {
|
||||
pixelScaleMultiplier = UIManager.GlobalPixelMultiplier * _scaleMultiplier;
|
||||
}
|
||||
|
||||
public UIElement(TextureRegion texture, Point position) {
|
||||
this.texture = texture;
|
||||
textures.Add(texture);
|
||||
bounds = (position, position + new Point(texture.Width, texture.Height));
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
public UIElement(TextureRegion[] textures, Point position) {
|
||||
this.textures.AddRange(textures);
|
||||
bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
|
||||
public void SetTexture(int textureId) {
|
||||
if (textureId >= textures.Count){
|
||||
Console.WriteLine($"WARNING: TEXTURE {textureId} OUT OF BOUNDS");
|
||||
return;
|
||||
}
|
||||
|
||||
currentTextureId = textureId;
|
||||
}
|
||||
public void Update() {
|
||||
|
||||
|
|
@ -35,6 +70,7 @@ public class UIElement {
|
|||
public virtual void OnMouseHold() { }
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch) {
|
||||
texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
||||
textures[currentTextureId].Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
|
||||
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
||||
}
|
||||
}
|
||||
64
FNAF_Clone/GUI/UIManager.cs
Normal file
64
FNAF_Clone/GUI/UIManager.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using MonoGameLibrary;
|
||||
using MonoGameLibrary.Graphics;
|
||||
|
||||
namespace FNAF_Clone.GUI;
|
||||
|
||||
public class UIManager {
|
||||
|
||||
public static class ScreenTypes {
|
||||
public const string OFFICE = "office";
|
||||
public const string CAMERAS = "monitor";
|
||||
}
|
||||
|
||||
private static Screen officeScreen = new(ScreenTypes.OFFICE);
|
||||
private static Screen monitorScreen = new(ScreenTypes.CAMERAS);
|
||||
|
||||
private static TextureAtlas testAtlas;
|
||||
private static TextureAtlas officeAtlas;
|
||||
private static TextureAtlas monitorAtlas;
|
||||
public static int GlobalPixelMultiplier{ get; private set; }
|
||||
|
||||
public static void InitUI() {
|
||||
GlobalPixelMultiplier = Core.graphicsDevice.Viewport.Height / 360;
|
||||
|
||||
testAtlas = TextureAtlas.FromFile(Core.content, "images/testBlocks-definition.xml");
|
||||
officeAtlas = TextureAtlas.FromFile(Core.content, "images/office-definition.xml");
|
||||
monitorAtlas = TextureAtlas.FromFile(Core.content, "images/monitor-definition.xml");
|
||||
|
||||
Screen.AddScreens([officeScreen, monitorScreen]);
|
||||
Screen.SetScreen(ScreenTypes.OFFICE);
|
||||
|
||||
// officeScreen.AddElement("test",
|
||||
// new UIElement(testAtlas[0], Point.Zero)
|
||||
// {Pressable = true, OnMousePress = () => Console.WriteLine("Pressed!")}
|
||||
// );
|
||||
|
||||
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).MultiplyByScalar(GlobalPixelMultiplier)));
|
||||
officeScreen.AddElement("office_right", new UIElement([officeAtlas[5], officeAtlas[2]], new Point(440, 0).MultiplyByScalar(GlobalPixelMultiplier)));
|
||||
|
||||
monitorScreen.AddElement("screen", new UIElement(monitorAtlas[0], Point.Zero));
|
||||
monitorScreen.AddElement("view-frame", new UIElement(monitorAtlas[1], new Point(62, 55).MultiplyByScalar(GlobalPixelMultiplier)));
|
||||
monitorScreen.AddElement("map-frame", new UIElement(monitorAtlas[2], new Point(334, 135).MultiplyByScalar(GlobalPixelMultiplier)));
|
||||
monitorScreen.AddElement("map", new UIElement(monitorAtlas[3], new Point(334, 135).MultiplyByScalar(GlobalPixelMultiplier)));
|
||||
}
|
||||
|
||||
public static void ChangeDoorState(int id, bool state) {
|
||||
switch (id){
|
||||
case 0:
|
||||
officeScreen["office_left"].SetTexture(state ? 1 : 0);
|
||||
break;
|
||||
case 1:
|
||||
officeScreen["office_centre"].SetTexture(state ? 1 : 0);
|
||||
break;
|
||||
case 2:
|
||||
officeScreen["office_right"].SetTexture(state ? 1 : 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ChangeMonitorState(bool state) {
|
||||
Screen.SetScreen(state ? ScreenTypes.CAMERAS : ScreenTypes.OFFICE);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue