Skip to content

Commit

Permalink
Added gamespeed buttons like in the history collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Ostermann committed Oct 28, 2024
1 parent fc3a886 commit 3c1840d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Freeserf.Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions Freeserf.Core/UI/PanelBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -233,6 +262,9 @@ public override bool Displayed

messageIcon.Displayed = true;
returnIcon.Displayed = true;

foreach (var speedButton in gameSpeedButtons)
speedButton.Displayed = true;
}
}
}
Expand Down

0 comments on commit 3c1840d

Please sign in to comment.