diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 1c7aa1d6aa..ee41bd1705 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -136,6 +136,8 @@ namespace OpenRA } public Widget rootWidget; + public Widget selectedWidget; + List visibleTabs = new List(); public void Tick(World world) @@ -1045,6 +1047,12 @@ namespace OpenRA int2 lastMousePos; public bool HandleInput(World world, MouseInput mi) { + if (selectedWidget != null) + { + selectedWidget.HandleInput(mi); + return true; + } + if (rootWidget.HandleInput(mi)) return true; @@ -1065,6 +1073,9 @@ namespace OpenRA public bool HitTest(int2 mousePos) { + if (selectedWidget != null) + return true; + return rootWidget.GetEventBounds().Contains(mousePos.X, mousePos.Y) || buttons.Any(a => a.First.Contains(mousePos.ToPoint())); } diff --git a/OpenRA.Game/Chrome/ButtonWidget.cs b/OpenRA.Game/Chrome/ButtonWidget.cs index 7306e4b024..b77edc9c75 100644 --- a/OpenRA.Game/Chrome/ButtonWidget.cs +++ b/OpenRA.Game/Chrome/ButtonWidget.cs @@ -7,6 +7,37 @@ namespace OpenRA.Widgets class ButtonWidget : Widget { public readonly string Text = ""; + public bool Depressed = false; + public int VisualHeight = 1; + public override bool HandleInput(MouseInput mi) + { + if (Game.chrome.selectedWidget == this) + Depressed = (GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) ? true : false; + + // Relinquish focus + if (Game.chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up) + { + Game.chrome.selectedWidget = null; + Depressed = false; + } + + // Are we able to handle this event? + if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) + return base.HandleInput(mi); + + // Give button focus only while the mouse is down + // This is a bit of a hack: it will become cleaner soonish + // It will also steal events from any potential children + // We also want to play a click sound + if (mi.Event == MouseInputEvent.Down) + { + Game.chrome.selectedWidget = this; + Depressed = true; + return true; + } + + return base.HandleInput(mi); + } public override void Draw() { @@ -16,7 +47,8 @@ namespace OpenRA.Widgets return; } - string collection = "dialog2"; + string collection = (Depressed) ? "dialog3" : "dialog2"; + int2 stateOffset = (Depressed) ? new int2(VisualHeight,VisualHeight) : new int2(0,0); Game.chrome.renderer.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height); string[] images = { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" }; @@ -45,7 +77,7 @@ namespace OpenRA.Widgets Game.chrome.rgbaRenderer.DrawSprite(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y), "chrome"); Game.chrome.rgbaRenderer.Flush(); - Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(Game.chrome.renderer.BoldFont.Measure(Text).X / 2, Game.chrome.renderer.BoldFont.Measure(Text).Y/2), Color.White); + Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(Game.chrome.renderer.BoldFont.Measure(Text).X / 2, Game.chrome.renderer.BoldFont.Measure(Text).Y/2) + stateOffset, Color.White); Game.chrome.renderer.Device.DisableScissor(); diff --git a/OpenRA.Game/Chrome/Widget.cs b/OpenRA.Game/Chrome/Widget.cs index d77c56d8c6..23e9c63080 100644 --- a/OpenRA.Game/Chrome/Widget.cs +++ b/OpenRA.Game/Chrome/Widget.cs @@ -87,9 +87,9 @@ namespace OpenRA.Widgets // Mousedown // todo: route the other events too! - if (InputHandler.Value != null && mi.Event == MouseInputEvent.Down) + if (InputHandler.Value != null && mi.Event == MouseInputEvent.Up) return InputHandler.Value.OnClick(this, mi); - + return false; } diff --git a/OpenRA.Game/Traits/Player/SpawnDefaultUnits.cs b/OpenRA.Game/Traits/Player/SpawnDefaultUnits.cs deleted file mode 100644 index 49fc746da3..0000000000 --- a/OpenRA.Game/Traits/Player/SpawnDefaultUnits.cs +++ /dev/null @@ -1,32 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. - * This file is part of OpenRA. - * - * OpenRA is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * OpenRA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OpenRA. If not, see . - */ -#endregion - -namespace OpenRA.Traits -{ - class SpawnDefaultUnitsInfo : StatelessTraitInfo { } - - class SpawnDefaultUnits : IOnGameStart - { - public void GameStarted(Player p, int2 sp) - { - p.World.CreateActor("mcv", sp, p); - } - } -} diff --git a/artsrc/cnc/dialog3.xcf b/artsrc/cnc/dialog3.xcf new file mode 100644 index 0000000000..5218c267ff Binary files /dev/null and b/artsrc/cnc/dialog3.xcf differ diff --git a/mods/cnc/chrome.xml b/mods/cnc/chrome.xml index 30876e8a4c..0526f427df 100644 --- a/mods/cnc/chrome.xml +++ b/mods/cnc/chrome.xml @@ -142,6 +142,17 @@ + + + + + + + + + + + diff --git a/mods/cnc/dialog3.png b/mods/cnc/dialog3.png new file mode 100644 index 0000000000..67da64ad3f Binary files /dev/null and b/mods/cnc/dialog3.png differ diff --git a/mods/ra/chrome.xml b/mods/ra/chrome.xml index fcd6ef18cb..5273e1d757 100644 --- a/mods/ra/chrome.xml +++ b/mods/ra/chrome.xml @@ -132,6 +132,17 @@ + + + + + + + + + + +