Timer Widget
Added a new Timer Widget Made one to display the ingame time elapsed Hooked up to reset on Game Start Added a setting for it in Settings Menu (default true)
This commit is contained in:
@@ -29,6 +29,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
||||
|
||||
Game.OnGameStart += () => r.OpenWindow("INGAME_ROOT");
|
||||
Game.OnGameStart += () => gameRoot.GetWidget<TimerWidget>("GAME_TIMER").Stopwatch.Reset();
|
||||
|
||||
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
||||
optionsBG.Visible = !optionsBG.Visible;
|
||||
|
||||
@@ -149,6 +149,14 @@ namespace OpenRA.Widgets.Delegates
|
||||
return true;
|
||||
};
|
||||
|
||||
var timedebug = debug.GetWidget<CheckboxWidget>("GAMETIME_CHECKBOX");
|
||||
timedebug.Checked = () => {return Game.Settings.ShowGameTimer;};
|
||||
timedebug.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.ShowGameTimer ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_CLOSE").OnMouseUp = mi => {
|
||||
Game.Settings.Save();
|
||||
Chrome.rootWidget.CloseWindow();
|
||||
|
||||
27
OpenRA.Game/Widgets/TimerWidget.cs
Normal file
27
OpenRA.Game/Widgets/TimerWidget.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class TimerWidget : Widget
|
||||
{
|
||||
public Stopwatch Stopwatch;
|
||||
|
||||
public TimerWidget ()
|
||||
{
|
||||
Stopwatch = new Stopwatch();
|
||||
IsVisible = () => Game.Settings.ShowGameTimer;
|
||||
}
|
||||
|
||||
public override void DrawInner (World world)
|
||||
{
|
||||
var s = WorldUtils.FormatTime((int) Stopwatch.ElapsedTime() * 25);
|
||||
var size = Game.chrome.renderer.RegularFont.Measure(s);
|
||||
var padding = 5;
|
||||
WidgetUtils.DrawPanel("dialog4",new Rectangle(RenderBounds.Top - padding, RenderBounds.Left - padding, size.X + 2*padding, size.Y + 2*padding));
|
||||
Game.chrome.renderer.RegularFont.DrawText(s, new float2(RenderBounds.Top, RenderBounds.Left), Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user