Split some useful bits from CncIngameMenuLogic into CncWidgetUtils for use elsewhere
This commit is contained in:
@@ -107,6 +107,7 @@
|
|||||||
<Compile Include="Widgets\Logic\CncColorPickerLogic.cs" />
|
<Compile Include="Widgets\Logic\CncColorPickerLogic.cs" />
|
||||||
<Compile Include="Widgets\LogicTickerWidget.cs" />
|
<Compile Include="Widgets\LogicTickerWidget.cs" />
|
||||||
<Compile Include="RenderBuildingRefinery.cs" />
|
<Compile Include="RenderBuildingRefinery.cs" />
|
||||||
|
<Compile Include="Widgets\CncWidgetUtils.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
44
OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs
Normal file
44
OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.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.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();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
var mpe = world.WorldActor.Trait<CncMenuPaletteEffect>();
|
var mpe = world.WorldActor.Trait<CncMenuPaletteEffect>();
|
||||||
mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
|
mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
|
||||||
|
|
||||||
menu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = ActiveModVersion;
|
menu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion;
|
||||||
|
|
||||||
bool hideButtons = false;
|
bool hideButtons = false;
|
||||||
menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons;
|
menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons;
|
||||||
@@ -53,13 +53,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
Action doNothing = () => {};
|
Action doNothing = () => {};
|
||||||
|
|
||||||
menu.GetWidget<ButtonWidget>("QUIT_BUTTON").OnClick = () =>
|
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));
|
Action onSurrender = () => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
|
||||||
var surrenderButton = menu.GetWidget<ButtonWidget>("SURRENDER_BUTTON");
|
var surrenderButton = menu.GetWidget<ButtonWidget>("SURRENDER_BUTTON");
|
||||||
surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined);
|
surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined);
|
||||||
surrenderButton.OnClick = () =>
|
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 = () =>
|
menu.GetWidget<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
|
||||||
{
|
{
|
||||||
@@ -95,30 +95,5 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
if (iop != null && iop.ObjectivesPanel != null)
|
if (iop != null && iop.ObjectivesPanel != null)
|
||||||
Game.OpenWindow(world, iop.ObjectivesPanel);
|
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();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
|
.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
|
||||||
|
|
||||||
rootMenu = widget.GetWidget("MENU_BACKGROUND");
|
rootMenu = widget.GetWidget("MENU_BACKGROUND");
|
||||||
rootMenu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = ActiveModVersion;
|
rootMenu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion;
|
||||||
|
|
||||||
// Menu buttons
|
// Menu buttons
|
||||||
var mainMenu = widget.GetWidget("MAIN_MENU");
|
var mainMenu = widget.GetWidget("MAIN_MENU");
|
||||||
@@ -128,13 +128,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
|
|
||||||
rootMenu.GetWidget<ImageWidget>("RECBLOCK").IsVisible = () => world.FrameNumber / 25 % 2 == 0;
|
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()
|
void RemoveShellmapUI()
|
||||||
{
|
{
|
||||||
rootMenu.Parent.RemoveChild(rootMenu);
|
rootMenu.Parent.RemoveChild(rootMenu);
|
||||||
|
|||||||
@@ -137,3 +137,45 @@ ScrollPanel@TEAM_DROPDOWN_TEMPLATE:
|
|||||||
Width:PARENT_RIGHT
|
Width:PARENT_RIGHT
|
||||||
Height:25
|
Height:25
|
||||||
Align:Center
|
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
|
||||||
@@ -64,46 +64,4 @@ Container@INGAME_MENU:
|
|||||||
Y:0
|
Y:0
|
||||||
Width:140
|
Width:140
|
||||||
Height:35
|
Height:35
|
||||||
Text:Resume
|
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
|
|
||||||
@@ -76,7 +76,7 @@ ChromeLayout:
|
|||||||
mods/cnc/chrome/modchooser.yaml
|
mods/cnc/chrome/modchooser.yaml
|
||||||
mods/cnc/chrome/preferences.yaml
|
mods/cnc/chrome/preferences.yaml
|
||||||
mods/cnc/chrome/cheats.yaml
|
mods/cnc/chrome/cheats.yaml
|
||||||
mods/cnc/chrome/dropdowns.yaml
|
mods/cnc/chrome/dialogs.yaml
|
||||||
mods/cnc/chrome/objectives.yaml
|
mods/cnc/chrome/objectives.yaml
|
||||||
mods/cnc/chrome/tooltips.yaml
|
mods/cnc/chrome/tooltips.yaml
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user