Přidán build script, předělaná struktura, funkční spouštění serveru z clienta. Client je schopen fungovat po více her bez restartu. Bugfixy
This commit is contained in:
parent
c942d23a87
commit
1a27dd6fab
22 changed files with 269 additions and 136 deletions
|
|
@ -73,6 +73,8 @@ public class Screen {
|
|||
public bool Active { get; private set; } = false;
|
||||
private InputListenerHook mouseInputHook = new(true);
|
||||
private bool temporary = false;
|
||||
|
||||
private List<string> temporaryElements = new();
|
||||
|
||||
public Screen(string label) {
|
||||
Label = label;
|
||||
|
|
@ -87,7 +89,7 @@ public class Screen {
|
|||
public UIElement this[string id] => elements[id];
|
||||
public UIElement TryGetElement(string id) => elements.TryGetValue(id, out var val) ? val : null;
|
||||
|
||||
public UIElement AddElement(string id, UIElement element) {
|
||||
public UIElement AddElement(string id, UIElement element, bool temporary = false) {
|
||||
elements.Add(id, element);
|
||||
|
||||
int insertIndex = elementsInDrawOrder.FindLastIndex(e => e.DrawPriority == element.DrawPriority);
|
||||
|
|
@ -97,10 +99,25 @@ public class Screen {
|
|||
else{
|
||||
elementsInDrawOrder.Insert(insertIndex + 1, element);
|
||||
}
|
||||
|
||||
if (temporary){
|
||||
temporaryElements.Add(id);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public void RemoveElement(string id) {
|
||||
if (!elements.ContainsKey(id)) return;
|
||||
elements.Remove(id, out var element);
|
||||
elementsInDrawOrder.RemoveAll(e => e == element);
|
||||
}
|
||||
|
||||
public void RemoveTemporary() {
|
||||
temporaryElements.ForEach(RemoveElement);
|
||||
temporaryElements.Clear();
|
||||
}
|
||||
|
||||
public void SetActive(bool active) {
|
||||
Active = active;
|
||||
if (Active == active) return;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class TimerUIElement : TextUIElement{
|
|||
}
|
||||
|
||||
public void Start() {
|
||||
stopwatch.Start();
|
||||
stopwatch.Restart();
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,14 @@ public class UIManager {
|
|||
cameraView = new UIElement(rooms.ToArray(), new(64, 64));
|
||||
monitorScreen.AddElement("camera-view", cameraView);
|
||||
|
||||
monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas["door-office-p1-left-open"], MonitorAtlas["door-office-p1-left-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas["door-office-p1-centre-open"], MonitorAtlas["door-office-p1-centre-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas["door-office-p1-right-open"], MonitorAtlas["door-office-p1-right-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas["door-office-p2-right-open"], MonitorAtlas["door-office-p2-right-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
|
||||
|
||||
|
||||
// main menu
|
||||
timerElement = new(new(0, 0), PixelMonoFont);
|
||||
overlayScreen.AddElement("timer", timerElement);
|
||||
|
|
@ -119,20 +127,70 @@ public class UIManager {
|
|||
}
|
||||
});
|
||||
menuScreen.AddElement("host-button",
|
||||
new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST"});
|
||||
new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST", Pressable = true,
|
||||
OnMousePress = () => {
|
||||
Client.StartServer();
|
||||
Client.Player.username = usernameField.Text;
|
||||
Client.Connect("127.0.0.1", 9012);
|
||||
Screen.SetScreen(ScreenTypes.LOADING);
|
||||
|
||||
}});
|
||||
|
||||
loadingScreen.AddElement("loading-text", new LoadingUIElement(new(320, 180), PixelMonoFont, field.Text));
|
||||
|
||||
}
|
||||
|
||||
public static void DisplayMainMenu() {
|
||||
ResetUI();
|
||||
Screen.SetScreen(ScreenTypes.MENU);
|
||||
CommandManager.AllowGameControls(false);
|
||||
// if(Client.Player.username != null)
|
||||
// ((MenuInputField)menuScreen["username-field"]).Text = Client.Player.username;
|
||||
}
|
||||
|
||||
public static void SpawnMapElements(TileConnectorProjection[] doors) {
|
||||
|
||||
|
||||
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++){
|
||||
int id = ClientMapManager.CoordsToId(i, 4 - j);
|
||||
if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
|
||||
Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
|
||||
Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
|
||||
monitorScreen.AddElement(
|
||||
$"room{id}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(id))},
|
||||
true);
|
||||
lightIndicators.Add(id,
|
||||
monitorScreen.AddElement(
|
||||
$"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1)
|
||||
{Visible = false},
|
||||
true));
|
||||
|
||||
//
|
||||
// if (doorPositions.ContainsKey((i, j))){
|
||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1), true);
|
||||
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1), true);
|
||||
|
||||
|
||||
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"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas["door-remote-open"], MonitorAtlas["door-remote-closed"]], tile.Bounds.Item1), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DisplayGameUI() {
|
||||
Screen.SetScreen(ScreenTypes.OFFICE);
|
||||
Screen.SetOverlayScreen(ScreenTypes.OVERLAY);
|
||||
|
|
@ -145,53 +203,10 @@ public class UIManager {
|
|||
timerElement.Start();
|
||||
}
|
||||
|
||||
public static void SpawnMapElements(TileConnectorProjection[] doors) {
|
||||
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++){
|
||||
int id = ClientMapManager.CoordsToId(i, 4 - j);
|
||||
if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
|
||||
Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
|
||||
Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
|
||||
monitorScreen.AddElement($"room{id}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(id))});
|
||||
lightIndicators.Add(id, monitorScreen.AddElement($"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1){Visible = false}));
|
||||
|
||||
//
|
||||
// if (doorPositions.ContainsKey((i, j))){
|
||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1));
|
||||
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1));
|
||||
|
||||
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"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas["door-remote-open"], MonitorAtlas["door-remote-closed"]], tile.Bounds.Item1));
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas["door-office-p1-left-open"], MonitorAtlas["door-office-p1-left-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas["door-office-p1-centre-open"], MonitorAtlas["door-office-p1-centre-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas["door-office-p1-right-open"], MonitorAtlas["door-office-p1-right-closed"]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas["door-office-p2-right-open"], MonitorAtlas["door-office-p2-right-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
|
||||
|
||||
}
|
||||
|
||||
public static void AddEnemySprite(int id, UIElement sprite, UIElement jumpscareSprite = null) {
|
||||
monitorScreen.AddElement($"enemy{id}", sprite);
|
||||
monitorScreen.AddElement($"enemy{id}", sprite, true);
|
||||
if (jumpscareSprite != null){
|
||||
officeScreen.AddElement($"enemy{id}-jumpscare", jumpscareSprite);
|
||||
officeScreen.AddElement($"enemy{id}-jumpscare", jumpscareSprite, true);
|
||||
jumpscareSprite.Active = false;
|
||||
jumpscareSprite.Visible = false;
|
||||
}
|
||||
|
|
@ -314,6 +329,16 @@ public class UIManager {
|
|||
SoundManager.StopAmbience();
|
||||
InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
|
||||
}
|
||||
|
||||
public static void ResetUI() {
|
||||
foreach (Screen screen in Screen.Screens.Values){
|
||||
screen.RemoveTemporary();
|
||||
}
|
||||
lightIndicators.Clear();
|
||||
enemyElements.Clear();
|
||||
|
||||
timerElement.Stop();
|
||||
}
|
||||
|
||||
// private static Point GetRoomUIPos((int x, int y) pos) {
|
||||
// return new Point(336 + (32 * pos.x), 144 + (32 * pos.y));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue