Split some useful bits from CncIngameMenuLogic into CncWidgetUtils for use elsewhere

This commit is contained in:
Paul Chote
2011-07-26 21:59:16 +12:00
parent 648979c8ae
commit 304601b5ca
7 changed files with 94 additions and 80 deletions

View File

@@ -107,6 +107,7 @@
<Compile Include="Widgets\Logic\CncColorPickerLogic.cs" />
<Compile Include="Widgets\LogicTickerWidget.cs" />
<Compile Include="RenderBuildingRefinery.cs" />
<Compile Include="Widgets\CncWidgetUtils.cs" />
</ItemGroup>
<ItemGroup>
<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.FileFormats;
using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets
{
public static class CncWidgetUtils
{
public static string ActiveModVersion()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Version;
}
public static void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel)
{
var prompt = Widget.OpenWindow("CONFIRM_PROMPT");
prompt.GetWidget<LabelWidget>("PROMPT_TITLE").GetText = () => title;
prompt.GetWidget<LabelWidget>("PROMPT_TEXT").GetText = () => text;
prompt.GetWidget<ButtonWidget>("CONFIRM_BUTTON").OnClick = () =>
{
Widget.CloseWindow();
onConfirm();
};
prompt.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
{
Widget.CloseWindow();
onCancel();
};
}
}
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var mpe = world.WorldActor.Trait<CncMenuPaletteEffect>();
mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
menu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = ActiveModVersion;
menu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion;
bool hideButtons = false;
menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons;
@@ -53,13 +53,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Action doNothing = () => {};
menu.GetWidget<ButtonWidget>("QUIT_BUTTON").OnClick = () =>
PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing);
CncWidgetUtils.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing);
Action onSurrender = () => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
var surrenderButton = menu.GetWidget<ButtonWidget>("SURRENDER_BUTTON");
surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined);
surrenderButton.OnClick = () =>
PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, doNothing);
CncWidgetUtils.PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, doNothing);
menu.GetWidget<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
@@ -95,30 +95,5 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
if (iop != null && iop.ObjectivesPanel != null)
Game.OpenWindow(world, iop.ObjectivesPanel);
}
static string ActiveModVersion()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Version;
}
public void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel)
{
var prompt = Widget.OpenWindow("CONFIRM_PROMPT");
prompt.GetWidget<LabelWidget>("PROMPT_TITLE").GetText = () => title;
prompt.GetWidget<LabelWidget>("PROMPT_TEXT").GetText = () => text;
prompt.GetWidget<ButtonWidget>("CONFIRM_BUTTON").OnClick = () =>
{
Widget.CloseWindow();
onConfirm();
};
prompt.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
{
Widget.CloseWindow();
onCancel();
};
}
}
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
rootMenu = widget.GetWidget("MENU_BACKGROUND");
rootMenu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = ActiveModVersion;
rootMenu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion;
// Menu buttons
var mainMenu = widget.GetWidget("MAIN_MENU");
@@ -129,12 +129,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
rootMenu.GetWidget<ImageWidget>("RECBLOCK").IsVisible = () => world.FrameNumber / 25 % 2 == 0;
}
static string ActiveModVersion()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Version;
}
void RemoveShellmapUI()
{
rootMenu.Parent.RemoveChild(rootMenu);

View File

@@ -137,3 +137,45 @@ ScrollPanel@TEAM_DROPDOWN_TEMPLATE:
Width:PARENT_RIGHT
Height:25
Align:Center
Container@CONFIRM_PROMPT:
Id:CONFIRM_PROMPT
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 90)/2
Width:370
Height:125
Children:
Label@PROMPT_TITLE:
Id:PROMPT_TITLE
Width:PARENT_RIGHT
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Background@bg:
Width:370
Height:90
Background:panel-black
Children:
Label@PROMPT_TEXT:
Id:PROMPT_TEXT
Y:(PARENT_BOTTOM-HEIGHT)/2
Width:PARENT_RIGHT
Height:25
Font:Bold
Align:Center
Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON
Key:escape
Y:89
Width:140
Height:35
Text:Cancel
Button@CONFIRM_BUTTON:
Id:CONFIRM_BUTTON
Key:return
X:230
Y:89
Width:140
Height:35
Text:Confirm

View File

@@ -65,45 +65,3 @@ Container@INGAME_MENU:
Width:140
Height:35
Text:Resume
Container@CONFIRM_PROMPT:
Id:CONFIRM_PROMPT
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 90)/2
Width:370
Height:125
Children:
Label@PROMPT_TITLE:
Id:PROMPT_TITLE
Width:PARENT_RIGHT
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Background@bg:
Width:370
Height:90
Background:panel-black
Children:
Label@PROMPT_TEXT:
Id:PROMPT_TEXT
Y:(PARENT_BOTTOM-HEIGHT)/2
Width:PARENT_RIGHT
Height:25
Font:Bold
Align:Center
Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON
Key:escape
Y:89
Width:140
Height:35
Text:Cancel
Button@CONFIRM_BUTTON:
Id:CONFIRM_BUTTON
Key:return
X:230
Y:89
Width:140
Height:35
Text:Confirm

View File

@@ -76,7 +76,7 @@ ChromeLayout:
mods/cnc/chrome/modchooser.yaml
mods/cnc/chrome/preferences.yaml
mods/cnc/chrome/cheats.yaml
mods/cnc/chrome/dropdowns.yaml
mods/cnc/chrome/dialogs.yaml
mods/cnc/chrome/objectives.yaml
mods/cnc/chrome/tooltips.yaml