3D buttons (still needs a little work)

This commit is contained in:
Paul Chote
2010-03-17 20:37:58 +13:00
parent 79bcb3c739
commit a2b2ad0af5
8 changed files with 69 additions and 36 deletions

View File

@@ -136,6 +136,8 @@ namespace OpenRA
}
public Widget rootWidget;
public Widget selectedWidget;
List<string> visibleTabs = new List<string>();
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()));
}

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#endregion
namespace OpenRA.Traits
{
class SpawnDefaultUnitsInfo : StatelessTraitInfo<SpawnDefaultUnits> { }
class SpawnDefaultUnits : IOnGameStart
{
public void GameStarted(Player p, int2 sp)
{
p.World.CreateActor("mcv", sp, p);
}
}
}

BIN
artsrc/cnc/dialog3.xcf Normal file

Binary file not shown.

View File

@@ -142,6 +142,17 @@
<image name="corner-tr" x="82" y="0" width="1" height="1" />
<image name="corner-bl" x="0" y="82" width="1" height="1" />
<image name="corner-br" x="82" y="82" width="1" height="1" />
</collection>
<collection name="dialog3" src="dialog3.png">
<image name="background" x="1" y="1" width="126" height="126" />
<image name="border-r" x="127" y="1" width="1" height="126" />
<image name="border-l" x="0" y="1" width="1" height="126" />
<image name="border-b" x="1" y="127" width="126" height="1" />
<image name="border-t" x="1" y="0" width="126" height="1" />
<image name="corner-tl" x="0" y="0" width="1" height="1" />
<image name="corner-tr" x="82" y="0" width="1" height="1" />
<image name="corner-bl" x="0" y="82" width="1" height="1" />
<image name="corner-br" x="82" y="82" width="1" height="1" />
</collection>
<collection name="spawnpoints" src="spawnpoints.png">
<image name="unowned" x="16" y="0" width="16" height="16" />

BIN
mods/cnc/dialog3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@@ -132,6 +132,17 @@
<image name="corner-br" x="252" y="252" width="4" height="4" />
<image name="background" x="4" y="4" width="248" height="248" />
</collection>
<collection name="dialog3" src="widget-panel.png">
<image name="border-t" x="4" y="0" width="248" height="4" />
<image name="border-b" x="4" y="252" width="248" height="4" />
<image name="border-l" x="0" y="4" width="4" height="248" />
<image name="border-r" x="252" y="4" width="4" height="248" />
<image name="corner-tl" x="0" y="0" width="4" height="4" />
<image name="corner-tr" x="252" y="0" width="4" height="4" />
<image name="corner-bl" x="0" y="252" width="4" height="4" />
<image name="corner-br" x="252" y="252" width="4" height="4" />
<image name="background" x="4" y="4" width="248" height="248" />
</collection>
<collection name="dialog" src="dialog.png">
<image name="background" x="0" y="0" width="624" height="384" />
<image name="border-r" x="624" y="0" width="14" height="200" />