public static void CloseWindow() { if (WindowList.Count > 0) { Root.RemoveChild(WindowList.Pop()); } if (WindowList.Count > 0) { Root.AddChild(WindowList.Peek()); } }
public static void CloseWindow() { if (WindowList.Count > 0) { var hidden = WindowList.Pop(); Root.RemoveChild(hidden); if (hidden.LogicObjects != null) { foreach (var l in hidden.LogicObjects) { l.BecameHidden(); } } } if (WindowList.Count > 0) { var restore = WindowList.Peek(); Root.AddChild(restore); if (restore.LogicObjects != null) { foreach (var l in restore.LogicObjects) { l.BecameVisible(); } } } }
public static Widget OpenWindow(string id, WidgetArgs args) { var window = Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id); if (WindowList.Count > 0) { rootWidget.RemoveChild(WindowList.Peek()); } WindowList.Push(window); return(window); }
// This is shit void LayoutDialog(Widget bg) { foreach (var c in controls) bg.RemoveChild(c); controls.Clear(); var y = 50; var margin = 20; var labelWidth = (bg.Bounds.Width - 3 * margin) / 3; var ts = new LabelWidget { Font = "Bold", Bounds = new Rectangle(margin + labelWidth + 10, y, labelWidth, 25), Text = "Their Stance", Align = TextAlign.Left, }; bg.AddChild(ts); controls.Add(ts); var ms = new LabelWidget { Font = "Bold", Bounds = new Rectangle(margin + 2 * labelWidth + 20, y, labelWidth, 25), Text = "My Stance", Align = TextAlign.Left, }; bg.AddChild(ms); controls.Add(ms); y += 35; foreach (var p in world.Players.Where(a => a != world.LocalPlayer && !a.NonCombatant)) { var pp = p; var label = new LabelWidget { Bounds = new Rectangle(margin, y, labelWidth, 25), Text = p.PlayerName, Align = TextAlign.Left, Font = "Bold", Color = p.Color.RGB, }; bg.AddChild(label); controls.Add(label); var theirStance = new LabelWidget { Bounds = new Rectangle( margin + labelWidth + 10, y, labelWidth, 25), Text = p.PlayerName, Align = TextAlign.Left, GetText = () => pp.Stances[ world.LocalPlayer ].ToString(), }; bg.AddChild(theirStance); controls.Add(theirStance); var myStance = new DropDownButtonWidget { Bounds = new Rectangle( margin + 2 * labelWidth + 20, y, labelWidth, 25), GetText = () => world.LocalPlayer.Stances[ pp ].ToString(), }; if (!p.World.LobbyInfo.GlobalSettings.FragileAlliances) myStance.Disabled = true; myStance.OnMouseDown = mi => ShowDropDown(pp, myStance); bg.AddChild(myStance); controls.Add(myStance); y += 35; } }
internal MapChooserLogic(Widget widget, string initialMap, MapClassification initialTab, Action onExit, Action<string> onSelect, MapVisibility filter) { this.widget = widget; this.onSelect = onSelect; var approving = new Action(() => { Ui.CloseWindow(); onSelect(selectedUid); }); var canceling = new Action(() => { Ui.CloseWindow(); onExit(); }); var okButton = widget.Get<ButtonWidget>("BUTTON_OK"); okButton.Disabled = this.onSelect == null; okButton.OnClick = approving; widget.Get<ButtonWidget>("BUTTON_CANCEL").OnClick = canceling; gameModeDropdown = widget.GetOrNull<DropDownButtonWidget>("GAMEMODE_FILTER"); var itemTemplate = widget.Get<ScrollItemWidget>("MAP_TEMPLATE"); widget.RemoveChild(itemTemplate); var mapFilterInput = widget.GetOrNull<TextFieldWidget>("MAPFILTER_INPUT"); if (mapFilterInput != null) { mapFilterInput.TakeKeyboardFocus(); mapFilterInput.OnEscKey = () => { if (mapFilterInput.Text.Length == 0) canceling(); else { mapFilter = mapFilterInput.Text = null; EnumerateMaps(currentTab, itemTemplate); } return true; }; mapFilterInput.OnEnterKey = () => { approving(); return true; }; mapFilterInput.OnTextEdited = () => { mapFilter = mapFilterInput.Text; EnumerateMaps(currentTab, itemTemplate); }; } var randomMapButton = widget.GetOrNull<ButtonWidget>("RANDOMMAP_BUTTON"); if (randomMapButton != null) { randomMapButton.OnClick = () => { var uid = visibleMaps.Random(Game.CosmeticRandom); selectedUid = uid; scrollpanels[currentTab].ScrollToItem(uid, smooth: true); }; randomMapButton.IsDisabled = () => visibleMaps == null || visibleMaps.Length == 0; } var deleteMapButton = widget.Get<ButtonWidget>("DELETE_MAP_BUTTON"); deleteMapButton.IsDisabled = () => Game.ModData.MapCache[selectedUid].Class != MapClassification.User; deleteMapButton.IsVisible = () => currentTab == MapClassification.User; deleteMapButton.OnClick = () => { DeleteOneMap(selectedUid, (string newUid) => { RefreshMaps(currentTab, filter); EnumerateMaps(currentTab, itemTemplate); if (!tabMaps[currentTab].Any()) SwitchTab(Game.ModData.MapCache[newUid].Class, itemTemplate); }); }; var deleteAllMapsButton = widget.Get<ButtonWidget>("DELETE_ALL_MAPS_BUTTON"); deleteAllMapsButton.IsVisible = () => currentTab == MapClassification.User; deleteAllMapsButton.OnClick = () => { DeleteAllMaps(visibleMaps, (string newUid) => { RefreshMaps(currentTab, filter); EnumerateMaps(currentTab, itemTemplate); SwitchTab(Game.ModData.MapCache[newUid].Class, itemTemplate); }); }; SetupMapTab(MapClassification.User, filter, "USER_MAPS_TAB_BUTTON", "USER_MAPS_TAB", itemTemplate); SetupMapTab(MapClassification.System, filter, "SYSTEM_MAPS_TAB_BUTTON", "SYSTEM_MAPS_TAB", itemTemplate); if (initialMap == null && tabMaps.Keys.Contains(initialTab) && tabMaps[initialTab].Any()) { selectedUid = WidgetUtils.ChooseInitialMap(tabMaps[initialTab].Select(mp => mp.Uid).First()); currentTab = initialTab; } else { selectedUid = WidgetUtils.ChooseInitialMap(initialMap); currentTab = tabMaps.Keys.FirstOrDefault(k => tabMaps[k].Select(mp => mp.Uid).Contains(selectedUid)); } SwitchTab(currentTab, itemTemplate); }
public MenuButtonsChromeLogic(Widget widget, World world) { this.world = world; worldRoot = Ui.Root.Get("WORLD_ROOT"); menuRoot = Ui.Root.Get("MENU_ROOT"); Action removeCurrentWidget = () => menuRoot.RemoveChild(currentWidget); world.GameOver += removeCurrentWidget; // System buttons var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON"); if (options != null) { var blinking = false; var lp = world.LocalPlayer; options.IsDisabled = () => disableSystemButtons; options.OnClick = () => { blinking = false; OpenMenuPanel(options, new WidgetArgs() { { "activePanel", IngameInfoPanel.AutoSelect } }); }; options.IsHighlighted = () => blinking && Game.LocalTick % 50 < 25; if (lp != null) { Action<Player, bool> startBlinking = (player, inhibitAnnouncement) => { if (!inhibitAnnouncement && player == world.LocalPlayer) blinking = true; }; var mo = lp.PlayerActor.TraitOrDefault<MissionObjectives>(); if (mo != null) mo.ObjectiveAdded += startBlinking; } } var diplomacy = widget.GetOrNull<MenuButtonWidget>("DIPLOMACY_BUTTON"); if (diplomacy != null) { diplomacy.Visible = !world.Map.Visibility.HasFlag(MapVisibility.MissionSelector) && world.Players.Any(a => a != world.LocalPlayer && !a.NonCombatant); diplomacy.IsDisabled = () => disableSystemButtons; diplomacy.OnClick = () => OpenMenuPanel(diplomacy); } var debug = widget.GetOrNull<MenuButtonWidget>("DEBUG_BUTTON"); if (debug != null) { debug.IsVisible = () => world.LobbyInfo.GlobalSettings.AllowCheats; debug.IsDisabled = () => disableSystemButtons; debug.OnClick = () => OpenMenuPanel(debug, new WidgetArgs() { { "activePanel", IngameInfoPanel.Debug } }); } var stats = widget.GetOrNull<MenuButtonWidget>("OBSERVER_STATS_BUTTON"); if (stats != null) { stats.IsDisabled = () => disableSystemButtons; stats.OnClick = () => OpenMenuPanel(stats); } }