Remote dveře se renderují na mapě. Opravena chyba v GlobalMapTile.CoordsToId, která způsobovala desynchronizaci id místností
This commit is contained in:
parent
7e6b3d724b
commit
70b5debb22
7 changed files with 58 additions and 27 deletions
|
|
@ -14,7 +14,7 @@ public class UIElement {
|
|||
public bool Pressable { get; set; } = false;
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes
|
||||
public (Point, Point) Bounds{ get; private set; } // TODO: Change this to support non-rectangular hitboxes
|
||||
private (Point, Point) screenSpaceBounds;
|
||||
private List<TextureRegion> textures = new();
|
||||
private int currentTextureId = 0;
|
||||
|
|
@ -32,22 +32,22 @@ public class UIElement {
|
|||
private int pixelScaleMultiplier = 1;
|
||||
private void LoadPixelScaleMultiplier() {
|
||||
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
|
||||
screenSpaceBounds = (bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||
screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||
}
|
||||
|
||||
public UIElement(TextureRegion texture, Point position) {
|
||||
textures.Add(texture);
|
||||
bounds = (position, position + new Point(texture.Width, texture.Height));
|
||||
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));
|
||||
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
public UIElement(Point corner1, Point corner2) {
|
||||
bounds = (corner1, corner2);
|
||||
Bounds = (corner1, corner2);
|
||||
Visible = false;
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FNAF_Clone.Map;
|
||||
using GlobalClassLib;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MonoGameLibrary;
|
||||
|
|
@ -22,6 +23,7 @@ public class UIManager {
|
|||
private static TextureAtlas monitorAtlas;
|
||||
public static int GlobalPixelMultiplier{ get; private set; }
|
||||
|
||||
private Dictionary<(int, int), UIElement> doorElements = new();
|
||||
public static void InitUI() {
|
||||
GlobalPixelMultiplier = Core.graphicsDevice.Viewport.Height / 360;
|
||||
|
||||
|
|
@ -47,10 +49,10 @@ public class UIManager {
|
|||
monitorScreen.AddElement("map-frame", new UIElement(monitorAtlas[2], new Point(334, 135)));
|
||||
monitorScreen.AddElement("map", new UIElement(monitorAtlas[3], new Point(334, 135)));
|
||||
|
||||
Dictionary<(int,int),string> doorPositions = new(){
|
||||
{(0, 0),"2-5"},{ (1, 0), "2-4" }, { (1, 1), "2-3" }, { (3, 0), "2-2" }, { (3, 1), "2-1" }, { (4, 0), "2-0" }, // TODO: generate this dynamically from server map info
|
||||
{(0, 3),"1-0"},{ (1, 3), "1-1" }, { (1, 2), "1-2" }, { (3, 3), "1-3" }, { (3, 2), "1-4" }, { (4, 3), "1-5" }
|
||||
};
|
||||
// Dictionary<(int,int),string> doorPositions = new(){
|
||||
// {(0, 0),"2-5"},{ (1, 0), "2-4" }, { (1, 1), "2-3" }, { (3, 0), "2-2" }, { (3, 1), "2-1" }, { (4, 0), "2-0" }, // TODO: generate this dynamically from server map info
|
||||
// {(0, 3),"1-0"},{ (1, 3), "1-1" }, { (1, 2), "1-2" }, { (3, 3), "1-3" }, { (3, 2), "1-4" }, { (4, 3), "1-5" }
|
||||
// };
|
||||
|
||||
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++){
|
||||
|
|
@ -58,16 +60,28 @@ public class UIManager {
|
|||
int j1 = j;
|
||||
Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
|
||||
Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
|
||||
monitorScreen.AddElement($"room{i}-{4 - j}", new UIElement(point1, point2)
|
||||
monitorScreen.AddElement($"room{MapTileProjection.CoordsToId(i, 4 - j)}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(i1, 4 - j1))});
|
||||
if (doorPositions.ContainsKey((i, j))){
|
||||
monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
}
|
||||
//
|
||||
// if (doorPositions.ContainsKey((i, j))){
|
||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SpawnDoors(TileConnectorProjection[] doors) {
|
||||
foreach (var door in doors){
|
||||
if(door.Type != ConnectorType.DOOR_REMOTE) continue;
|
||||
|
||||
(int x, int y) dpos = (Math.Abs(door.Tiles.tile1.GridPosition.x - door.Tiles.tile2.GridPosition.x), Math.Abs(door.Tiles.tile1.GridPosition.y - door.Tiles.tile2.GridPosition.y));
|
||||
|
||||
if (dpos.y == 1){
|
||||
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"+targetId+"-"+(targetId == door.Tiles.tile1.Id ? door.Tiles.tile2.Id : door.Tiles.tile1.Id), new UIElement([monitorAtlas[5], monitorAtlas[6]], tile.Bounds.Item1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void ChangeDoorState(Direction dir, bool state) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue