Opravena chyba se špatně převedenými hitboxy UI elementů. Opravena chyba s měněním screenu, kdy stará zůstala aktivní. Přidány elementy pro překlikávání kamer.
This commit is contained in:
parent
2cd215cc33
commit
8a3267cc4b
8 changed files with 56 additions and 19 deletions
|
|
@ -22,6 +22,9 @@ public class Screen {
|
|||
}
|
||||
|
||||
public static void SetScreen(string id) {
|
||||
if (CurrentScreen != null){
|
||||
CurrentScreen.Active = false;
|
||||
}
|
||||
CurrentScreen = Screens[id];
|
||||
CurrentScreen.Active = true;
|
||||
}
|
||||
|
|
@ -62,6 +65,9 @@ public class Screen {
|
|||
}
|
||||
|
||||
private void ProcessMouseInput(MouseState mouseState) {
|
||||
if (!Active){
|
||||
return;
|
||||
}
|
||||
foreach (var element in elements.Values){
|
||||
if (!element.Pressable) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ public class UIElement {
|
|||
|
||||
public bool Active { get; set; } = false;
|
||||
public bool Pressable { get; set; } = false;
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes
|
||||
private (Point, Point) screenSpaceBounds;
|
||||
private List<TextureRegion> textures = new();
|
||||
private int currentTextureId = 0;
|
||||
|
||||
|
|
@ -27,9 +29,10 @@ public class UIElement {
|
|||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
}
|
||||
private float pixelScaleMultiplier = 1;
|
||||
private int pixelScaleMultiplier = 1;
|
||||
private void LoadPixelScaleMultiplier() {
|
||||
pixelScaleMultiplier = UIManager.GlobalPixelMultiplier * _scaleMultiplier;
|
||||
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
|
||||
screenSpaceBounds = (bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||
}
|
||||
|
||||
public UIElement(TextureRegion texture, Point position) {
|
||||
|
|
@ -42,6 +45,12 @@ public class UIElement {
|
|||
bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
public UIElement(Point corner1, Point corner2) {
|
||||
bounds = (corner1, corner2);
|
||||
Visible = false;
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
|
||||
public void SetTexture(int textureId) {
|
||||
|
|
@ -57,8 +66,8 @@ public class UIElement {
|
|||
}
|
||||
|
||||
public bool IsWithinBounds(Point pos) {
|
||||
return pos.X >= Math.Min(bounds.Item1.X, bounds.Item2.X) && pos.X <= Math.Max(bounds.Item1.X, bounds.Item2.X) &&
|
||||
pos.Y >= Math.Min(bounds.Item1.Y, bounds.Item2.Y) && pos.Y <= Math.Max(bounds.Item1.Y, bounds.Item2.Y);
|
||||
return pos.X >= Math.Min(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) && pos.X <= Math.Max(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) &&
|
||||
pos.Y >= Math.Min(screenSpaceBounds.Item1.Y, screenSpaceBounds.Item2.Y) && pos.Y <= Math.Max(screenSpaceBounds.Item1.Y, screenSpaceBounds.Item2.Y);
|
||||
}
|
||||
|
||||
public Action OnMousePress{ get; set; }
|
||||
|
|
@ -70,7 +79,10 @@ public class UIElement {
|
|||
public virtual void OnMouseHold() { }
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch) {
|
||||
textures[currentTextureId].Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
|
||||
if (!Visible){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MonoGameLibrary;
|
||||
using MonoGameLibrary.Graphics;
|
||||
|
|
@ -29,19 +30,31 @@ public class UIManager {
|
|||
Screen.AddScreens([officeScreen, monitorScreen]);
|
||||
Screen.SetScreen(ScreenTypes.OFFICE);
|
||||
|
||||
|
||||
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("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)));
|
||||
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)));
|
||||
|
||||
for (int i = 0; i < 5; i++){
|
||||
for (int j = 0; j < 5; j++){
|
||||
int i1 = i;
|
||||
int j1 = j;
|
||||
monitorScreen.AddElement($"room{i}-{j}", new UIElement(new Point(336 + (32 * i), 144 + (32 * j)), new Point(367 + (32 * i), 175 + (32 * j)))
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(i1, j1))});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void ChangeDoorState(int id, bool state) {
|
||||
|
|
@ -61,4 +74,6 @@ public class UIManager {
|
|||
public static void ChangeMonitorState(bool state) {
|
||||
Screen.SetScreen(state ? ScreenTypes.CAMERAS : ScreenTypes.OFFICE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue