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
|
|
@ -72,7 +72,7 @@ public class Client {
|
|||
client.PollEvents();
|
||||
}
|
||||
|
||||
public static void OnPlayerUpdate(UpdatePlayerPacket packet) {
|
||||
public static void OnPlayerUpdate(UpdatePlayerPacket packet) { // TODO: move this to a separate class
|
||||
//Player.state = Player.state.pid == 0 ? packet.stateP1 : packet.stateP2;
|
||||
|
||||
foreach (var e in packet.events){
|
||||
|
|
@ -87,7 +87,7 @@ public class Client {
|
|||
if (Player.state.pid == e.Args[0]){
|
||||
Player.state.camera = e.Args[1];
|
||||
}
|
||||
Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}");
|
||||
Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}-{e.Args[2]}");
|
||||
break;
|
||||
case 3: // toggle cam
|
||||
Player.state.monitorUp = e.Args[1] == 1;
|
||||
|
|
|
|||
|
|
@ -37,4 +37,8 @@ public class CommandManager {
|
|||
}
|
||||
Client.SendCommands([PlayerCommand.TOGGLE_DOOR_OFFICE(id)]);
|
||||
}
|
||||
|
||||
public static void SendChangeCamera(int idx, int idy) {
|
||||
Client.SendCommands([PlayerCommand.SWITCH_CAM(idx, idy)]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
@ -43,6 +46,12 @@ public class UIElement {
|
|||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
public UIElement(Point corner1, Point corner2) {
|
||||
bounds = (corner1, corner2);
|
||||
Visible = false;
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
|
||||
|
||||
public void SetTexture(int textureId) {
|
||||
if (textureId >= textures.Count){
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -9,8 +9,8 @@ public class CommandProcessor {
|
|||
foreach (var playerCommand in commands){
|
||||
switch (playerCommand.ID){
|
||||
case 0:
|
||||
Console.WriteLine($"C: Player {pid} switched to camera {playerCommand.Args[0]}");
|
||||
Server.SendUpdateToAll([GameEvent.SWITCH_CAM(pid, playerCommand.Args[0])]);
|
||||
Console.WriteLine($"C: Player {pid} switched to camera {playerCommand.Args[0]}-{playerCommand.Args[1]}");
|
||||
Server.SendUpdateToAll([GameEvent.SWITCH_CAM(pid, playerCommand.Args[0], playerCommand.Args[1])]);
|
||||
break;
|
||||
case 1:
|
||||
bool monitorState = !currentPlayer.state.monitorUp;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace PacketLib;
|
|||
public struct GameEvent : INetSerializable{
|
||||
public static GameEvent PLAYER_JOIN(int pid) => new(){ID = 0, Args = [pid] };
|
||||
public static GameEvent PLAYER_LEAVE(int pid) => new(){ID = 1, Args = [pid] };
|
||||
public static GameEvent SWITCH_CAM(int pid, int camId) => new(){ID = 2, Args = [pid, camId] };
|
||||
public static GameEvent SWITCH_CAM(int pid, int idx, int idy) => new(){ID = 2, Args = [pid, idx, idy] };
|
||||
public static GameEvent TOGGLE_MONITOR(int pid, bool state) => new(){ID = 3, Args = [pid, state ? 1 : 0]};
|
||||
public static GameEvent TOGGLE_DOOR_OFFICE(int pid, int doorId, bool state) => new(){ID = 4, Args = [pid, doorId, state ? 1 : 0]};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using LiteNetLib.Utils;
|
|||
namespace PacketLib;
|
||||
|
||||
public struct PlayerCommand : INetSerializable {
|
||||
public static PlayerCommand SWITCH_CAM(int camId) => new(){ID = 0, Args = [camId] };
|
||||
public static PlayerCommand SWITCH_CAM(int idx, int idy) => new(){ID = 0, Args = [idx, idy] };
|
||||
public static PlayerCommand TOGGLE_MONITOR() => new(){ID = 1, Args = []};
|
||||
public static PlayerCommand TOGGLE_DOOR_OFFICE(int doorId) => new(){ID = 2, Args = [doorId]};
|
||||
public int ID{ get; set; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue