split Widget static bits into Ui static class

This commit is contained in:
Chris Forbes
2011-12-13 23:38:59 +13:00
parent 83055f0a17
commit ed429a3b30
60 changed files with 173 additions and 168 deletions

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Cnc
void TestAndContinue()
{
Widget.ResetAll();
Ui.ResetAll();
if (!FileSystem.Exists(Info["TestFile"]))
{
var args = new WidgetArgs()
@@ -131,8 +131,8 @@ namespace OpenRA.Mods.Cnc
{ "continueLoading", () => TestAndContinue() },
{ "installData", Info }
};
Widget.LoadWidget(Info["InstallerBackgroundWidget"], Widget.RootWidget, args);
Widget.OpenWindow(Info["InstallerMenuWidget"], args);
Ui.LoadWidget(Info["InstallerBackgroundWidget"], Ui.RootWidget, args);
Ui.OpenWindow(Info["InstallerMenuWidget"], args);
}
else
Game.LoadShellMap();

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Cnc
{
Sound.StopMusic();
Game.Disconnect();
Widget.ResetAll();
Ui.ResetAll();
Game.LoadShellMap();
};
Game.RunAfterDelay(5000, () => Scripting.Media.PlayFMVFullscreen(w, "consyard.vqa", afterFMV));
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Cnc
{
Sound.StopMusic();
Game.Disconnect();
Widget.ResetAll();
Ui.ResetAll();
Game.LoadShellMap();
};
Game.RunAfterDelay(5000, () => Scripting.Media.PlayFMVFullscreen(w, "gameover.vqa", afterFMV));

View File

@@ -33,15 +33,16 @@ namespace OpenRA.Mods.Cnc.Widgets
this.world = world;
tabsWidget = Lazy.New(() =>
Widget.RootWidget.GetWidget<ProductionTabsWidget>(info.ProductionTabsWidget));
Ui.RootWidget.GetWidget<ProductionTabsWidget>(info.ProductionTabsWidget));
}
public void SelectionChanged()
{
// Find an actor with a queue
var producer = world.Selection.Actors.FirstOrDefault(a => a.IsInWorld
&& a.World.LocalPlayer == a.Owner
&& a.HasTrait<ProductionQueue>());
&& a.World.LocalPlayer == a.Owner
&& a.HasTrait<ProductionQueue>());
if (producer != null)
tabsWidget.Value.CurrentQueue = producer.TraitsImplementing<ProductionQueue>().First();
}

View File

@@ -19,19 +19,19 @@ namespace OpenRA.Mods.Cnc.Widgets
{
public static void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel)
{
var prompt = Widget.OpenWindow("CONFIRM_PROMPT");
var prompt = Ui.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();
Ui.CloseWindow();
onConfirm();
};
prompt.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
{
Widget.CloseWindow();
Ui.CloseWindow();
onCancel();
};
}

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Cnc.Widgets
: base(world, worldRenderer)
{
tooltipContainer = Lazy.New(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
Ui.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
}
public override void MouseEntered()
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public override void Tick()
{
Edge = ScrollDirection.None;
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus && Widget.MouseOverWidget == this)
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus && Ui.MouseOverWidget == this)
{
// Check for edge-scroll
if (Viewport.LastMousePos.X < EdgeScrollThreshold)

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
panel.GetWidget<ButtonWidget>("GIVE_EXPLORATION_BUTTON").OnClick = () =>
world.IssueOrder(new Order("DevGiveExploration", world.LocalPlayer.PlayerActor, false));
panel.GetWidget<ButtonWidget>("CLOSE_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
panel.GetWidget<ButtonWidget>("CLOSE_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
}
public void Order(World world, string order)

View File

@@ -86,12 +86,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{
if (menu != MenuType.None)
{
Widget.CloseWindow();
Ui.CloseWindow();
menu = MenuType.None;
}
ingameRoot.IsVisible = () => false;
Game.LoadWidget(world, "INGAME_MENU", Widget.RootWidget, new WidgetArgs()
Game.LoadWidget(world, "INGAME_MENU", Ui.RootWidget, new WidgetArgs()
{
{ "onExit", () => ingameRoot.IsVisible = () => true }
});
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
cheatsButton.OnClick = () =>
{
if (menu != MenuType.None)
Widget.CloseWindow();
Ui.CloseWindow();
menu = MenuType.Cheats;
Game.OpenWindow("CHEATS_PANEL", new WidgetArgs() {{"onExit", () => menu = MenuType.None }});

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Game.RunAfterDelay(1200 + 40 * mpe.Info.FadeLength, () =>
{
Game.Disconnect();
Widget.ResetAll();
Ui.ResetAll();
Game.LoadShellMap();
});
};
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
menu.GetWidget<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
hideButtons = true;
Widget.OpenWindow("MUSIC_PANEL", new WidgetArgs()
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
{
{ "onExit", () => hideButtons = false },
});
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
menu.GetWidget<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
{
hideButtons = true;
Widget.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "world", world },
{ "onExit", () => hideButtons = false },
@@ -80,8 +80,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
resumeButton.IsDisabled = () => resumeDisabled;
resumeButton.OnClick = () =>
{
Widget.CloseWindow();
Widget.RootWidget.RemoveChild(menu);
Ui.CloseWindow();
Ui.RootWidget.RemoveChild(menu);
world.WorldActor.Trait<CncMenuPaletteEffect>().Fade(CncMenuPaletteEffect.EffectType.None);
onExit();
};

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL");
backButton = panel.GetWidget<ButtonWidget>("BACK_BUTTON");
backButton.OnClick = Widget.CloseWindow;
backButton.OnClick = Ui.CloseWindow;
retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON");
retryButton.OnClick = CheckForDisk;
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Game.RunAfterTick(() =>
{
Widget.CloseWindow();
Ui.CloseWindow();
afterInstall();
});
}

View File

@@ -22,15 +22,15 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var panel = widget.GetWidget("INSTALL_PANEL");
var args = new WidgetArgs()
{
{ "afterInstall", () => { Widget.CloseWindow(); continueLoading(); } },
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
{ "installData", installData }
};
panel.GetWidget<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
Widget.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
panel.GetWidget<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
Widget.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs(args)
Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs(args)
{
{ "filesToCopy", new[] { "CONQUER.MIX", "DESERT.MIX", "SCORES.MIX",
"SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX" } },
@@ -41,11 +41,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
panel.GetWidget<ButtonWidget>("MODS_BUTTON").OnClick = () =>
{
Widget.OpenWindow("MODS_PANEL", new WidgetArgs()
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => {} },
// Close this panel
{ "onSwitch", Widget.CloseWindow },
{ "onSwitch", Ui.CloseWindow },
});
};
}

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
mainMenu.GetWidget<ButtonWidget>("MODS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("MODS_PANEL", new WidgetArgs()
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main },
{ "onSwitch", RemoveShellmapUI }
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
settingsMenu.GetWidget<ButtonWidget>("REPLAYS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs()
Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Settings },
{ "onStart", RemoveShellmapUI }
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
settingsMenu.GetWidget<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("MUSIC_PANEL", new WidgetArgs()
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Settings },
});
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
settingsMenu.GetWidget<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "world", world },
{ "onExit", () => Menu = MenuType.Settings },
@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
void OpenGamePanel(string id)
{
Menu = MenuType.None;
Widget.OpenWindow(id, new WidgetArgs()
Ui.OpenWindow(id, new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer, false) }

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
installed = Rules.Music.Where(m => m.Value.Exists).Any();
Func<bool> noMusic = () => !installed;
panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
Action afterInstall = () =>
{
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var installButton = panel.GetWidget<ButtonWidget>("INSTALL_BUTTON");
installButton.OnClick = () =>
Widget.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() {
Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() {
{ "afterInstall", afterInstall },
{ "filesToCopy", new [] { "SCORES.MIX" } },
{ "filesToExtract", new [] { "transit.mix" } },

View File

@@ -140,7 +140,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
int.TryParse(windowHeight.Text, out y);
graphicsSettings.WindowedSize = new int2(x,y);
Game.Settings.Save();
Widget.CloseWindow();
Ui.CloseWindow();
onExit();
};
}

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
pm = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
tooltipContainer = Lazy.New(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
Ui.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
}
public override void MouseEntered()

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Cnc.Widgets
this.world = world;
this.worldRenderer = worldRenderer;
tooltipContainer = Lazy.New(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
Ui.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
cantBuild = new Animation("clock");
cantBuild.PlayFetchIndex("idle", () => 0);

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Cnc.Widgets
// Only visible if the production palette has icons to display
IsVisible = () => queueGroup != null && Groups[queueGroup].Tabs.Count > 0;
paletteWidget = Lazy.New(() => Widget.RootWidget.GetWidget<ProductionPaletteWidget>(PaletteWidget));
paletteWidget = Lazy.New(() => Ui.RootWidget.GetWidget<ProductionPaletteWidget>(PaletteWidget));
}
public void SelectNextTab(bool reverse)
@@ -135,9 +135,9 @@ namespace OpenRA.Mods.Cnc.Widgets
rightButtonRect = new Rectangle(rb.Right - ArrowWidth, rb.Y, ArrowWidth, rb.Height);
var leftDisabled = ListOffset >= 0;
var leftHover = Widget.MouseOverWidget == this && leftButtonRect.Contains(Viewport.LastMousePos);
var leftHover = Ui.MouseOverWidget == this && leftButtonRect.Contains(Viewport.LastMousePos);
var rightDisabled = ListOffset <= Bounds.Width - rightButtonRect.Width - leftButtonRect.Width - ContentWidth;
var rightHover = Widget.MouseOverWidget == this && rightButtonRect.Contains(Viewport.LastMousePos);
var rightHover = Ui.MouseOverWidget == this && rightButtonRect.Contains(Viewport.LastMousePos);
WidgetUtils.DrawPanel("panel-black", rb);
ButtonWidget.DrawBackground("button", leftButtonRect, leftDisabled, leftPressed, leftHover);
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Cnc.Widgets
foreach (var tab in Groups[queueGroup].Tabs)
{
var rect = new Rectangle(origin.X + ContentWidth, origin.Y, TabWidth, rb.Height);
var hover = !leftHover && !rightHover && Widget.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
var hover = !leftHover && !rightHover && Ui.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
var baseName = tab.Queue == CurrentQueue ? "button-toggled" : "button";
ButtonWidget.DrawBackground(baseName, rect, false, false, hover);
ContentWidth += TabWidth - 1;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
pr = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
tooltipContainer = Lazy.New(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
Ui.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
}
public override void MouseEntered()

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Cnc.Widgets
this.worldRenderer = worldRenderer;
spm = world.LocalPlayer.PlayerActor.Trait<SupportPowerManager>();
tooltipContainer = Lazy.New(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
Ui.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
iconSprites = Rules.Info.Values.SelectMany( u => u.Traits.WithInterface<SupportPowerInfo>() )
.Select(u => u.Image).Distinct()

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Cnc.Widgets
: base()
{
tooltipContainer = Lazy.New(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
Ui.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
}
protected ToggleButtonWidget(ToggleButtonWidget other)
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Cnc.Widgets
TooltipText = other.TooltipText;
TooltipContainer = other.TooltipContainer;
tooltipContainer = Lazy.New(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
Ui.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
}
public override void MouseEntered()

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public void SetTooltip(string id, WidgetArgs args)
{
RemoveTooltip();
tooltip = Widget.LoadWidget(id, this, new WidgetArgs(args) {{ "tooltipContainer", this }});
tooltip = Ui.LoadWidget(id, this, new WidgetArgs(args) {{ "tooltipContainer", this }});
}
public void RemoveTooltip()
@@ -45,7 +45,9 @@ namespace OpenRA.Mods.Cnc.Widgets
}
public override void Draw() { BeforeRender(); }
public override Rectangle GetEventBounds() { return Rectangle.Empty; }
public override int2 ChildOrigin
{
get
@@ -62,6 +64,7 @@ namespace OpenRA.Mods.Cnc.Widgets
}
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { throw new NotImplementedException(); }
}
}