From 3c1840dece8cd20c47fe2796cadf73ab05a2dc7b Mon Sep 17 00:00:00 2001 From: Dennis Ostermann Date: Mon, 28 Oct 2024 09:39:59 +0100 Subject: [PATCH] Added gamespeed buttons like in the history collection --- Freeserf.Core/Game.cs | 5 +++++ Freeserf.Core/UI/PanelBar.cs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Freeserf.Core/Game.cs b/Freeserf.Core/Game.cs index 3c4c80ca..4f1f7c5d 100644 --- a/Freeserf.Core/Game.cs +++ b/Freeserf.Core/Game.cs @@ -499,6 +499,11 @@ public void DecreaseSpeed() } } + public void SetSpeed(uint speed) + { + state.GameSpeed = Convert.ToUInt16(speed); + } + public void ResetSpeed() { state.GameSpeed = GameState.DEFAULT_GAME_SPEED; diff --git a/Freeserf.Core/UI/PanelBar.cs b/Freeserf.Core/UI/PanelBar.cs index 6c79e5d1..6ccf6da6 100644 --- a/Freeserf.Core/UI/PanelBar.cs +++ b/Freeserf.Core/UI/PanelBar.cs @@ -100,6 +100,8 @@ enum ButtonId readonly Interface interf = null; readonly Button messageIcon = null; readonly Button returnIcon = null; + + readonly Button[] gameSpeedButtons = new Button[5]; readonly Button[] panelButtons = new Button[5]; readonly ButtonId[] panelButtonIds = new ButtonId[5]; readonly Render.ILayerSprite[] background = new Render.ILayerSprite[20]; @@ -122,6 +124,25 @@ public PanelBar(Interface interf) returnIcon.Clicked += ReturnIcon_Clicked; AddChild(returnIcon, 40, 28, true); + gameSpeedButtons[0] = new Button(interf, 7, 7, Data.Resource.FrameBottom, 4u, layerOffset); + gameSpeedButtons[1] = new Button(interf, 7, 7, Data.Resource.FrameBottom, 4u, layerOffset); + gameSpeedButtons[2] = new Button(interf, 7, 7, Data.Resource.FrameBottom, 4u, layerOffset); + gameSpeedButtons[3] = new Button(interf, 7, 7, Data.Resource.FrameBottom, 4u, layerOffset); + gameSpeedButtons[4] = new Button(interf, 7, 7, Data.Resource.FrameBottom, 4u, layerOffset); + + int gameSpeedButtonsOffSet = 0; + foreach (Button button in gameSpeedButtons) + { + AddChild(button, 295, gameSpeedButtonsOffSet, true); + gameSpeedButtonsOffSet += 7; + } + + gameSpeedButtons[0].Clicked += (sender, e) => SetGameSpeed(0); + gameSpeedButtons[1].Clicked += (sender, e) => SetGameSpeed(GameState.DEFAULT_GAME_SPEED); + gameSpeedButtons[2].Clicked += (sender, e) => SetGameSpeed(GameState.DEFAULT_GAME_SPEED * 7); + gameSpeedButtons[3].Clicked += (sender, e) => SetGameSpeed(GameState.DEFAULT_GAME_SPEED * 14); + gameSpeedButtons[4].Clicked += (sender, e) => SetGameSpeed(Global.MAX_GAME_SPEED); + panelButtons[0] = new Button(interf, 32, 32, Data.Resource.PanelButton, (uint)ButtonId.BuildInactive, layerOffset); panelButtons[1] = new Button(interf, 32, 32, Data.Resource.PanelButton, (uint)ButtonId.DestroyInactive, layerOffset); panelButtons[2] = new Button(interf, 32, 32, Data.Resource.PanelButton, (uint)ButtonId.Map, layerOffset); @@ -167,6 +188,14 @@ public PanelBar(Interface interf) blinkTimer.Start(); } + private void SetGameSpeed(uint v) + { + if (interf.Player.Game.GameSpeed != v) + { + interf.Player.Game.SetSpeed(v); + } + } + private void GotoCastle(object sender, Button.ClickEventArgs args) { interf.GotoCastle(); @@ -233,6 +262,9 @@ public override bool Displayed messageIcon.Displayed = true; returnIcon.Displayed = true; + + foreach (var speedButton in gameSpeedButtons) + speedButton.Displayed = true; } } }