New menu buttons that support hover and a disabled state

This commit is contained in:
Paul Chote
2011-05-06 18:19:59 +12:00
parent 845b32281d
commit 28cf48459b
9 changed files with 241 additions and 137 deletions

View File

@@ -72,6 +72,7 @@
<Compile Include="SpawnViceroid.cs" /> <Compile Include="SpawnViceroid.cs" />
<Compile Include="Widgets\CncMenuLogic.cs" /> <Compile Include="Widgets\CncMenuLogic.cs" />
<Compile Include="Widgets\CncServerBrowserLogic.cs" /> <Compile Include="Widgets\CncServerBrowserLogic.cs" />
<Compile Include="Widgets\CncMenuButton.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,44 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Widgets;
using OpenRA.Graphics;
using System.Drawing;
namespace OpenRA.Mods.Cnc.Widgets
{
public class CncMenuButtonWidget : ButtonWidget
{
public CncMenuButtonWidget() : base() { }
protected CncMenuButtonWidget(CncMenuButtonWidget widget) : base(widget) { }
public Func<bool> IsDisabled = () => false;
public override int2 ChildOrigin { get { return RenderOrigin; } }
public override void DrawInner()
{
var font = Game.Renderer.BoldFont;
var state = IsDisabled() ? "button-disabled" :
Depressed ? "button-pressed" :
RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" :
"button";
WidgetUtils.DrawPanel(state, RenderBounds);
var text = GetText();
font.DrawText(text,
new int2(RenderOrigin.X + UsableWidth / 2, RenderOrigin.Y + Bounds.Height / 2)
- new int2(font.Measure(text).X / 2,
font.Measure(text).Y / 2), IsDisabled() ? Color.Gray : Color.White);
}
}
}

View File

@@ -18,7 +18,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.GameRules; using OpenRA.GameRules;
namespace OpenRA.Mods.RA.Widgets.Delegates namespace OpenRA.Mods.Cnc.Widgets
{ {
public class CncMenuLogic : IWidgetDelegate public class CncMenuLogic : IWidgetDelegate
{ {
@@ -47,7 +47,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var multiplayerMenu = widget.GetWidget("MULTIPLAYER_MENU"); var multiplayerMenu = widget.GetWidget("MULTIPLAYER_MENU");
multiplayerMenu.IsVisible = () => Menu == MenuType.Multiplayer; multiplayerMenu.IsVisible = () => Menu == MenuType.Multiplayer;
multiplayerMenu.GetWidget("BACK_BUTTON").OnMouseUp = mi => { Menu = MenuType.Main; return true; }; multiplayerMenu.GetWidget("BACK_BUTTON").OnMouseUp = mi => { Menu = MenuType.Main; return true; };
multiplayerMenu.GetWidget("JOIN_BUTTON").OnMouseUp = mi => multiplayerMenu.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
{ {

View File

@@ -61,14 +61,15 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
searchStatus = SearchStatus.Fetching; searchStatus = SearchStatus.Fetching;
sl.RemoveChildren(); sl.RemoveChildren();
currentServer = null;
MasterServerQuery.Refresh(Game.Settings.Server.MasterServer); MasterServerQuery.Refresh(Game.Settings.Server.MasterServer);
return true; return true;
}; };
var join = panel.GetWidget("JOIN_BUTTON"); var join = panel.GetWidget<CncMenuButtonWidget>("JOIN_BUTTON");
join.IsVisible = () => currentServer != null && ServerBrowserDelegate.CanJoin(currentServer); join.IsDisabled = () => currentServer == null || !ServerBrowserDelegate.CanJoin(currentServer);
join.OnMouseUp = mi => join.OnMouseUp = mi =>
{ {
if (currentServer == null) if (currentServer == null)

View File

@@ -28,13 +28,13 @@
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="4" inkscape:zoom="4"
inkscape:cx="30.297739" inkscape:cx="26.047739"
inkscape:cy="49.497475" inkscape:cy="49.497475"
inkscape:document-units="px" inkscape:document-units="px"
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
showgrid="false" showgrid="false"
inkscape:window-width="1626" inkscape:window-width="1440"
inkscape:window-height="1006" inkscape:window-height="856"
inkscape:window-x="54" inkscape:window-x="54"
inkscape:window-y="22" inkscape:window-y="22"
inkscape:window-maximized="0" /> inkscape:window-maximized="0" />
@@ -84,6 +84,16 @@
height="63" height="63"
width="63" width="63"
id="rect2984" id="rect2984"
style="fill:#000000;fill-opacity:0.75111109;stroke:#800000;stroke-width:1;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none" /> style="fill:#2b2b2b;fill-opacity:0.87843137999999998;stroke:#800000;stroke-width:1;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
inkscape:export-ydpi="90"
inkscape:export-xdpi="90"
inkscape:export-filename="/Users/paul/src/OpenRA/mods/cnc/uibits/rect3776.png"
y="988.86218"
x="64.5"
height="63"
width="63"
id="rect3753"
style="fill:#0f0000;fill-opacity:0.87843137999999998;stroke:#c00000;stroke-width:1;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -141,7 +141,50 @@ dialog: uibuttons.png
corner-bl: 0,62,2,2 corner-bl: 0,62,2,2
corner-br: 62,62,2,2 corner-br: 62,62,2,2
# Pressed button button-hover: uibuttons.png
background: 2,2,60,60
border-r: 62,2,2,60
border-l: 0,2,2,60
border-b: 2,62,60,2
border-t: 2,0,60,2
corner-tl: 0,0,2,2
corner-tr: 62,0,2,2
corner-bl: 0,62,2,2
corner-br: 62,62,2,2
button-disabled: uibuttons.png
background: 66,2,60,60
border-r: 126,2,2,60
border-l: 64,2,2,60
border-b: 66,62,60,2
border-t: 66,0,60,2
corner-tl: 64,0,2,2
corner-tr: 126,0,2,2
corner-bl: 64,62,2,2
corner-br: 126,62,2,2
button-pressed: uibuttons.png
background: 66,66,60,60
border-r: 126,66,2,60
border-l: 64,66,2,60
border-b: 66,126,60,2
border-t: 66,64,60,2
corner-tl: 64,64,2,2
corner-tr: 126,64,2,2
corner-bl: 64,126,2,2
corner-br: 126,126,2,2
button: uibuttons.png
background: 2,66,60,60
border-r: 62,66,2,60
border-l: 0,66,2,60
border-b: 2,126,60,2
border-t: 2,64,60,2
corner-tl: 0,64,2,2
corner-tr: 62,64,2,2
corner-bl: 0,126,2,2
corner-br: 62,126,2,2
dialog3: uibuttons.png dialog3: uibuttons.png
background: 2,2,60,60 background: 2,2,60,60
border-r: 62,2,2,60 border-r: 62,2,2,60
@@ -153,7 +196,6 @@ dialog3: uibuttons.png
corner-bl: 0,62,2,2 corner-bl: 0,62,2,2
corner-br: 62,62,2,2 corner-br: 62,62,2,2
# Normal buttton
dialog2: uibuttons.png dialog2: uibuttons.png
background: 2,66,60,60 background: 2,66,60,60
border-r: 62,66,2,60 border-r: 62,66,2,60
@@ -165,8 +207,7 @@ dialog2: uibuttons.png
corner-bl: 0,126,2,2 corner-bl: 0,126,2,2
corner-br: 62,126,2,2 corner-br: 62,126,2,2
# Panel background panel-black: panel.png
panel: uibuttons.png
background: 66,2,60,60 background: 66,2,60,60
border-r: 126,2,2,60 border-r: 126,2,2,60
border-l: 64,2,2,60 border-l: 64,2,2,60
@@ -177,6 +218,18 @@ panel: uibuttons.png
corner-bl: 64,62,2,2 corner-bl: 64,62,2,2
corner-br: 126,62,2,2 corner-br: 126,62,2,2
panel-darkred: panel.png
background: 2,66,60,60
border-r: 62,66,2,60
border-l: 0,66,2,60
border-b: 2,126,60,2
border-t: 2,64,60,2
corner-tl: 0,64,2,2
corner-tr: 62,64,2,2
corner-bl: 0,126,2,2
corner-br: 62,126,2,2
dialog4: dialog4.png dialog4: dialog4.png
border-t: 5,0,52,6 border-t: 5,0,52,6
border-b: 5,58,52,6 border-b: 5,58,52,6

View File

@@ -36,48 +36,43 @@ Container@MENU_BACKGROUND:
Height:20 Height:20
Text:Main Menu Text:Main Menu
Align:Center Align:Center
Bold:True Font:Bold
Contrast:True Contrast:True
Button@SOLO_BUTTON: CncMenuButton@SOLO_BUTTON:
Id:SOLO_BUTTON Id:SOLO_BUTTON
X:0 X:0
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Skirmish Text:Skirmish
Bold:True CncMenuButton@MULTIPLAYER_BUTTON:
Button@MULTIPLAYER_BUTTON:
Id:MULTIPLAYER_BUTTON Id:MULTIPLAYER_BUTTON
X:150 X:150
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Multiplayer Text:Multiplayer
Bold:True CncMenuButton@SETTINGS_BUTTON:
Button@SETTINGS_BUTTON:
Id:SETTINGS_BUTTON Id:SETTINGS_BUTTON
X:300 X:300
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Settings Text:Settings
Bold:True CncMenuButton@REPLAY_BUTTON:
Button@REPLAY_BUTTON:
Id:REPLAY_BUTTON Id:REPLAY_BUTTON
X:450 X:450
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text: Replays Text: Replays
Bold: True CncMenuButton@QUIT_BUTTON:
Button@QUIT_BUTTON:
Id:QUIT_BUTTON Id:QUIT_BUTTON
X:600 X:600
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Quit Text:Quit
Bold:True
Container@MULTIPLAYER_MENU: Container@MULTIPLAYER_MENU:
Id:MULTIPLAYER_MENU Id:MULTIPLAYER_MENU
Width:PARENT_RIGHT Width:PARENT_RIGHT
@@ -90,40 +85,36 @@ Container@MENU_BACKGROUND:
Height:20 Height:20
Text:Multiplayer Text:Multiplayer
Align:Center Align:Center
Bold:True Font:Bold
Contrast:True Contrast:True
Button@CREATE_BUTTON: CncMenuButton@CREATE_BUTTON:
Id:CREATE_BUTTON Id:CREATE_BUTTON
X:0 X:0
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Create Server Text:Create Server
Bold:True CncMenuButton@JOIN_BUTTON:
Button@JOIN_BUTTON:
Id:JOIN_BUTTON Id:JOIN_BUTTON
X:150 X:150
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Find Server Text:Find Server
Bold:True CncMenuButton@DIRECTCONNECT_BUTTON:
Button@DIRECTCONNECT_BUTTON:
Id:DIRECTCONNECT_BUTTON Id:DIRECTCONNECT_BUTTON
X:300 X:300
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Direct Connect Text:Direct Connect
Bold:True CncMenuButton@BACK_BUTTON:
Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
X:600 X:600
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Back Text:Back
Bold:True
Container@SETTINGS_MENU: Container@SETTINGS_MENU:
Id:SETTINGS_MENU Id:SETTINGS_MENU
Width:PARENT_RIGHT Width:PARENT_RIGHT
@@ -136,40 +127,36 @@ Container@MENU_BACKGROUND:
Height:20 Height:20
Text:Settings Text:Settings
Align:Center Align:Center
Bold:True Font:Bold
Contrast:True Contrast:True
Button@MODS_BUTTON: CncMenuButton@MODS_BUTTON:
Id:MODS_BUTTON Id:MODS_BUTTON
X:0 X:0
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Mods Text:Mods
Bold:True CncMenuButton@MUSIC_BUTTON:
Button@MUSIC_BUTTON:
Id:MUSIC_BUTTON Id:MUSIC_BUTTON
X:150 X:150
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Music Text:Music
Bold:True CncMenuButton@PREFERENCES_BUTTON:
Button@PREFERENCES_BUTTON:
Id:PREFERENCES_BUTTON Id:PREFERENCES_BUTTON
X:300 X:300
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Preferences Text:Preferences
Bold:True CncMenuButton@BACK_BUTTON:
Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
X:600 X:600
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Back Text:Back
Bold:True
Background@QUICKMODSWITCHER: Background@QUICKMODSWITCHER:
Id:QUICKMODSWITCHER Id:QUICKMODSWITCHER
Background: dialog4 Background: dialog4
@@ -186,7 +173,7 @@ Background@QUICKMODSWITCHER:
Height:25 Height:25
Text:Mod: Text:Mod:
Align:Left Align:Left
Bold:True Font:Bold
DropDownButton@SWITCHER: DropDownButton@SWITCHER:
Id:SWITCHER Id:SWITCHER
Text:Team Text:Team
@@ -201,7 +188,7 @@ Background@QUICKMODSWITCHER:
Width:150 Width:150
Height:25 Height:25
Align:Center Align:Center
Bold:True Font:Bold
Background@PERF_BG: Background@PERF_BG:
Id:PERF_BG Id:PERF_BG
Background:dialog4 Background:dialog4
@@ -240,7 +227,7 @@ Background@MUSIC_MENU:
Height:25 Height:25
Text:Music Text:Music
Align:Center Align:Center
Bold:True Font:Bold
Button@BUTTON_INSTALL: Button@BUTTON_INSTALL:
Id:BUTTON_INSTALL Id:BUTTON_INSTALL
X:20 X:20
@@ -248,7 +235,7 @@ Background@MUSIC_MENU:
Width:160 Width:160
Height:25 Height:25
Text:Install Music Text:Install Music
Bold:True Font:Bold
Button@BUTTON_CLOSE: Button@BUTTON_CLOSE:
Id:BUTTON_CLOSE Id:BUTTON_CLOSE
X:PARENT_RIGHT - 180 X:PARENT_RIGHT - 180
@@ -256,7 +243,7 @@ Background@MUSIC_MENU:
Width:160 Width:160
Height:25 Height:25
Text:Close Text:Close
Bold:True Font:Bold
Container@BUTTONS: Container@BUTTONS:
X:PARENT_RIGHT - 150 X:PARENT_RIGHT - 150
Y:50 Y:50

View File

@@ -6,10 +6,17 @@ Container@SERVERBROWSER_PANEL:
Width:740 Width:740
Height:535 Height:535
Children: Children:
Label@TITLE:
Text:Find Server
Width:740
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Background@bg: Background@bg:
Width:740 Width:740
Height:500 Height:500
Background:panel Background:panel-black
Children: Children:
ScrollPanel@SERVER_LIST: ScrollPanel@SERVER_LIST:
Id:SERVER_LIST Id:SERVER_LIST
@@ -62,7 +69,7 @@ Container@SERVERBROWSER_PANEL:
Y:0 Y:0
Text:Title Text:Title
Align:Center Align:Center
Bold:True Font:Bold
Label@MAP: Label@MAP:
Id:MAP Id:MAP
X:PARENT_RIGHT-450 X:PARENT_RIGHT-450
@@ -70,7 +77,7 @@ Container@SERVERBROWSER_PANEL:
Width:250 Width:250
Height:25 Height:25
Text:Map Text:Map
Bold:true Font:Bold
Label@PLAYERS: Label@PLAYERS:
Id:PLAYERS Id:PLAYERS
X:PARENT_RIGHT-200 X:PARENT_RIGHT-200
@@ -78,7 +85,7 @@ Container@SERVERBROWSER_PANEL:
Width:50 Width:50
Height:25 Height:25
Text:Players Text:Players
Bold:true Font:Bold
Label@IP: Label@IP:
Id:IP Id:IP
Width:140 Width:140
@@ -86,23 +93,29 @@ Container@SERVERBROWSER_PANEL:
Align:Center Align:Center
Height:25 Height:25
Text:Address Text:Address
Bold:true Font:Bold
Label@PROGRESS_LABEL: Label@PROGRESS_LABEL:
Id:PROGRESS_LABEL Id:PROGRESS_LABEL
X:22 X:22
Y:150 Y:165
Width:710 Width:710
Height:25 Height:25
Font:Bold
Align:Center Align:Center
Visible:false Visible:false
Container@SERVER_INFO: Background@INFO_BG:
Id:SERVER_INFO
X:15 X:15
Y:345 Y:345
Width:710 Width:710
Height:140 Height:140
Visible:false
Background:dialog2 Background:dialog2
Children:
Container@SERVER_INFO:
Id:SERVER_INFO
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Visible:false
Background:panel-darkred
Children: Children:
MapPreview@MAP_PREVIEW: MapPreview@MAP_PREVIEW:
Id:MAP_PREVIEW Id:MAP_PREVIEW
@@ -110,7 +123,7 @@ Container@SERVERBROWSER_PANEL:
Y:10 Y:10
Width:128 Width:128
Height:128 Height:128
Container@STATS_BIN Container@STATS_BIN:
X:200 X:200
Y:30 Y:30
Width:150 Width:150
@@ -123,7 +136,7 @@ Container@SERVERBROWSER_PANEL:
Width:70 Width:70
Height:20 Height:20
Text:Server: Text:Server:
Bold:True Font:Bold
Label@SERVER_IP: Label@SERVER_IP:
Id:SERVER_IP Id:SERVER_IP
X:70 X:70
@@ -139,7 +152,7 @@ Container@SERVERBROWSER_PANEL:
Width:70 Width:70
Height:20 Height:20
Text:Players: Text:Players:
Bold:True Font:Bold
Label@MAP_PLAYERS: Label@MAP_PLAYERS:
Id:MAP_PLAYERS Id:MAP_PLAYERS
X:70 X:70
@@ -155,7 +168,7 @@ Container@SERVERBROWSER_PANEL:
Width:70 Width:70
Height:20 Height:20
Text:Map: Text:Map:
Bold:True Font:Bold
Label@MAP_TITLE: Label@MAP_TITLE:
Id:MAP_TITLE Id:MAP_TITLE
X:70 X:70
@@ -171,7 +184,7 @@ Container@SERVERBROWSER_PANEL:
Width:70 Width:70
Height:20 Height:20
Text:Mods: Text:Mods:
Bold:True Font:Bold
Label@SERVER_MODS: Label@SERVER_MODS:
Id:SERVER_MODS Id:SERVER_MODS
X:70 X:70
@@ -180,28 +193,24 @@ Container@SERVERBROWSER_PANEL:
VAlign:Top VAlign:Top
Width:70 Width:70
Height:20 Height:20
Button@JOIN_BUTTON: CncMenuButton@JOIN_BUTTON:
Id:JOIN_BUTTON Id:JOIN_BUTTON
X:0 X:0
Y:499 Y:499
Width:140 Width:140
Height:35 Height:35
Visible: false
Text:Join Text:Join
Bold:True CncMenuButton@REFRESH_BUTTON:
Button@REFRESH_BUTTON:
Id:REFRESH_BUTTON Id:REFRESH_BUTTON
X:450 X:450
Y:499 Y:499
Width:140 Width:140
Height:35 Height:35
Text:Refresh Text:Refresh
Bold:True CncMenuButton@BACK_BUTTON:
Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
X:600 X:600
Y:499 Y:499
Width:140 Width:140
Height:35 Height:35
Text:Back Text:Back
Bold:True

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 B

After

Width:  |  Height:  |  Size: 549 B