New menu buttons that support hover and a disabled state
This commit is contained in:
@@ -72,6 +72,7 @@
|
||||
<Compile Include="SpawnViceroid.cs" />
|
||||
<Compile Include="Widgets\CncMenuLogic.cs" />
|
||||
<Compile Include="Widgets\CncServerBrowserLogic.cs" />
|
||||
<Compile Include="Widgets\CncMenuButton.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
44
OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs
Normal file
44
OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public class CncMenuLogic : IWidgetDelegate
|
||||
{
|
||||
@@ -47,7 +47,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
var multiplayerMenu = widget.GetWidget("MULTIPLAYER_MENU");
|
||||
multiplayerMenu.IsVisible = () => Menu == MenuType.Multiplayer;
|
||||
|
||||
|
||||
multiplayerMenu.GetWidget("BACK_BUTTON").OnMouseUp = mi => { Menu = MenuType.Main; return true; };
|
||||
multiplayerMenu.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
|
||||
@@ -61,14 +61,15 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
searchStatus = SearchStatus.Fetching;
|
||||
sl.RemoveChildren();
|
||||
currentServer = null;
|
||||
|
||||
MasterServerQuery.Refresh(Game.Settings.Server.MasterServer);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
var join = panel.GetWidget("JOIN_BUTTON");
|
||||
join.IsVisible = () => currentServer != null && ServerBrowserDelegate.CanJoin(currentServer);
|
||||
var join = panel.GetWidget<CncMenuButtonWidget>("JOIN_BUTTON");
|
||||
join.IsDisabled = () => currentServer == null || !ServerBrowserDelegate.CanJoin(currentServer);
|
||||
join.OnMouseUp = mi =>
|
||||
{
|
||||
if (currentServer == null)
|
||||
|
||||
Reference in New Issue
Block a user