Přidán indikátor právě aktivní kamery pro oba hráče. Indikátor protivníka se mění podle toho, jestli má zapnutý monitor.

This commit is contained in:
Perry 2026-02-26 16:24:55 +01:00
parent 3049417914
commit 4484b127c5
8 changed files with 60 additions and 9 deletions

View file

@ -60,6 +60,7 @@ public class CommandManager {
public static void SendChangeCamera(int id) {
Client.Player.state.camera = id;
UIManager.ChangeCamera(id);
Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]);
MapTileProjection tile = ClientMapManager.Get(id);
// add UIManager switch camera

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Before After
Before After

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas count="19">
<TextureAtlas count="25">
<Texture>images/SpriteSheet_monitor</Texture>
<Regions>
<Region id = "0" name="screen" x="0" y="0" width="640" height="360"/>
@ -25,6 +25,14 @@
<Region id = "17" name="door-office-p2-left-open" x="472" y="564" width="32" height="33"/>
<Region id = "18" name="door-office-p2-left-closed" x="504" y="564" width="32" height="33"/>
<Region id = "19" name="eye-opponent-open" x="572" y="360" width="32" height="14"/>
<Region id = "20" name="eye-opponent-open" x="604" y="360" width="32" height="14"/>
<Region id = "21" name="eye-player-open" x="572" y="374" width="32" height="14"/>
<Region id = "22" name="eye-small-opponent-open" x="572" y="402" width="32" height="9"/>
<Region id = "23" name="eye-small-opponent-closed" x="604" y="402" width="32" height="9"/>
<Region id = "24" name="eye-small-player" x="572" y="411" width="32" height="9"/>
</Regions>

View file

@ -19,16 +19,25 @@ public class EventProcessor {
break;
case 2: // switch cam
if (Client.Player.state.pid != e.Args[0]) return;
if (Client.Player.state.pid != e.Args[0]){
UIManager.ChangeCameraOpponent(e.Args[1]);
break;
}
if (Client.Player.state.camera != e.Args[1]) Console.WriteLine("!!! DESYNC: CAMERA STATE");
Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}");
break;
case 3: // toggle cam
if (e.Args[0] == Client.Player.state.pid && Client.Player.state.monitorUp != (e.Args[1] == 1)) Console.WriteLine("!!! DESYNC: MONITOR STATE");
Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}");
if (e.Args[0] != Client.Player.state.pid){
UIManager.ChangeMonitorStateOpponent(e.Args[1] == 1);
break;
}
if (Client.Player.state.monitorUp != (e.Args[1] == 1)) Console.WriteLine("!!! DESYNC: MONITOR STATE");
// UIManager.ChangeMonitorState(e.Args[1] == 1);
Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}");
break;
case 4: // toggle door

View file

@ -14,7 +14,11 @@ public class UIElement {
public bool Pressable { get; set; } = false;
public bool Visible { get; set; } = true;
public (Point, Point) Bounds{ get; private set; } // TODO: Change this to support non-rectangular hitboxes
public (Point, Point) Bounds{
get;
private set { field = value; UpdateBounds(); }
} // TODO: Change this to support non-rectangular hitboxes
private (Point, Point) screenSpaceBounds;
private List<TextureRegion> textures = new();
private int currentTextureId = 0;
@ -32,6 +36,10 @@ public class UIElement {
private int pixelScaleMultiplier = 1;
private void LoadPixelScaleMultiplier() {
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
UpdateBounds();
}
private void UpdateBounds() {
screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
}
@ -85,4 +93,8 @@ public class UIElement {
textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
}
public void SetPosition(Point position) {
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
}
}

View file

@ -63,6 +63,10 @@ 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));
}
public static void SpawnDoors(TileConnectorProjection[] doors) {
@ -131,5 +135,20 @@ public class UIManager {
Screen.SetScreen(state ? ScreenTypes.CAMERAS : ScreenTypes.OFFICE);
}
public static void ChangeMonitorStateOpponent(bool state) {
monitorScreen["eye-opponent"].SetTexture(state ? 1 : 0);
}
public static void ChangeCamera(int id) {
monitorScreen["eye-player"].SetPosition(monitorScreen["room"+id].Bounds.Item1);
}
public static void ChangeCameraOpponent(int id) {
monitorScreen["eye-opponent"].SetPosition(monitorScreen["room"+id].Bounds.Item1);
}
// private static Point GetRoomUIPos((int x, int y) pos) {
// return new Point(336 + (32 * pos.x), 144 + (32 * pos.y));
// }
}

View file

@ -6,6 +6,8 @@ namespace FNAF_Server;
public class GameLogic {
public const int START_CAMERA = 12;
public static void Init() {
// Create map
MapManager.InitMap();

View file

@ -102,7 +102,7 @@ public class Server {
peer = peer,
state = new PlayerState {
pid = peer.Id,
camera = 0,
camera = GameLogic.START_CAMERA,
doorStates = [false, false, false]
},
username = packet.username