public Widget LoadWidget(WidgetArgs args, Widget parent, MiniYamlNode node) { var widget = NewWidget(node.Key, args); if (parent != null) parent.AddChild( widget ); if (node.Key.Contains("@")) FieldLoader.LoadField(widget, "Id", node.Key.Split('@')[1]); foreach (var child in node.Value.Nodes) if (child.Key != "Children") FieldLoader.LoadField(widget, child.Key, child.Value.Value); if (!args.ContainsKey("modRules")) args = new WidgetArgs(args) { { "modRules", modData.DefaultRules } }; widget.Initialize(args); foreach (var child in node.Value.Nodes) if (child.Key == "Children") foreach (var c in child.Value.Nodes) LoadWidget( args, widget, c); widget.PostInit(args); return widget; }
public Widget LoadWidget(WidgetArgs args, Widget parent, MiniYamlNode node) { if (!args.ContainsKey("modData")) args = new WidgetArgs(args) { { "modData", modData } }; var widget = NewWidget(node.Key, args); if (parent != null) parent.AddChild(widget); if (node.Key.Contains("@")) FieldLoader.LoadField(widget, "Id", node.Key.Split('@')[1]); foreach (var child in node.Value.Nodes) if (child.Key != "Children") FieldLoader.LoadField(widget, child.Key, child.Value.Value); widget.Initialize(args); foreach (var child in node.Value.Nodes) if (child.Key == "Children") foreach (var c in child.Value.Nodes) LoadWidget(args, widget, c); var logicNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Logic"); var logic = logicNode == null ? null : logicNode.Value.ToDictionary(); args.Add("logicArgs", logic); widget.PostInit(args); args.Remove("logicArgs"); return widget; }
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 void CloseWindow() { if (WindowList.Count > 0) { Root.RemoveChild(WindowList.Pop()); } if (WindowList.Count > 0) { Root.AddChild(WindowList.Peek()); } }
public Widget LoadWidget( Dictionary<string, object> args, Widget parent, MiniYamlNode node) { var widget = NewWidget(node.Key, args); parent.AddChild( widget ); foreach (var child in node.Value.Nodes) if (child.Key != "Children") FieldLoader.LoadField(widget, child.Key, child.Value.Value); widget.Initialize(); foreach (var child in node.Value.Nodes) if (child.Key == "Children") foreach (var c in child.Value.Nodes) LoadWidget( args, widget, c); widget.PostInit( args ); return widget; }
public Widget LoadWidget( WidgetArgs args, Widget parent, MiniYamlNode node) { var widget = NewWidget(node.Key, args); if (parent != null) parent.AddChild( widget ); foreach (var child in node.Value.Nodes) if (child.Key != "Children") FieldLoader.LoadField(widget, child.Key, child.Value.Value); widget.Initialize(args); foreach (var child in node.Value.Nodes) if (child.Key == "Children") foreach (var c in child.Value.Nodes) LoadWidget( args, widget, c); widget.PostInit( args ); return widget; }
public SimpleTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Func<string> getText) { var label = widget.Get<LabelWidget>("LABEL"); var spacing = widget.Get("LINE_HEIGHT"); widget.RemoveChildren(); var font = Game.Renderer.Fonts[label.Font]; var horizontalPadding = label.Bounds.Width - widget.Bounds.Width; if (horizontalPadding <= 0) horizontalPadding = 2 * label.Bounds.X; var cachedText = ""; tooltipContainer.BeforeRender = () => { var text = getText(); if (text == cachedText) return; var lines = text.Split('\n'); var textWidth = font.Measure(text).X; // Set up label widgets widget.RemoveChildren(); var bottom = 0; for (var i = 0; i < lines.Length; i++) { var line = (LabelWidget)label.Clone(); var lineText = lines[i]; line.Bounds.Y += spacing.Bounds.Y + i * spacing.Bounds.Height; line.Bounds.Width = textWidth; line.GetText = () => lineText; widget.AddChild(line); bottom = line.Bounds.Y + line.Bounds.Height; } widget.Bounds.Width = horizontalPadding + textWidth; widget.Bounds.Height = bottom + spacing.Bounds.Y; cachedText = text; }; }
// 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; } }
static void BindHotkeyPref(KeyValuePair<string, string> kv, KeySettings ks, Widget template, Widget parent) { var key = template.Clone() as Widget; key.Id = kv.Key; key.IsVisible = () => true; var field = ks.GetType().GetField(kv.Key); if (field == null) throw new InvalidOperationException("Game.Settings.Keys does not contain {1}".F(kv.Key)); key.Get<LabelWidget>("FUNCTION").GetText = () => kv.Value + ":"; var textBox = key.Get<HotkeyEntryWidget>("HOTKEY"); textBox.Key = (Hotkey)field.GetValue(ks); textBox.OnLoseFocus = () => field.SetValue(ks, textBox.Key); parent.AddChild(key); }
void BuildMusicTable(Widget list) { music = Rules.Music.Where(a => a.Value.Exists).Select(a => a.Value).ToArray(); random = music.Shuffle(Game.CosmeticRandom).ToArray(); list.RemoveChildren(); foreach (var s in music) { var song = s; if (currentSong == null) currentSong = song; var item = ScrollItemWidget.Setup(itemTemplate, () => currentSong == song, () => { currentSong = song; Play(); }); item.Get<LabelWidget>("TITLE").GetText = () => song.Title; item.Get<LabelWidget>("LENGTH").GetText = () => SongLengthLabel(song); list.AddChild(item); } }
void LayoutDialog(Widget bg) { bg.Children.RemoveAll(w => controls.Contains(w)); controls.Clear(); var y = 50; var margin = 20; var labelWidth = (bg.Bounds.Width - 3 * margin) / 3; var ts = new LabelWidget { Bold = true, Bounds = new Rectangle(margin + labelWidth + 10, y, labelWidth, 25), Text = "Their Stance", Align = LabelWidget.TextAlign.Left, }; bg.AddChild(ts); controls.Add(ts); var ms = new LabelWidget { Bold = true, Bounds = new Rectangle(margin + 2 * labelWidth + 20, y, labelWidth, 25), Text = "My Stance", Align = LabelWidget.TextAlign.Left, }; bg.AddChild(ms); controls.Add(ms); y += 35; foreach (var p in world.players.Values.Where(a => a != world.LocalPlayer && !a.NonCombatant)) { var pp = p; var label = new LabelWidget { Bounds = new Rectangle(margin, y, labelWidth, 25), Id = "DIPLOMACY_PLAYER_LABEL_{0}".F(p.Index), Text = p.PlayerName, Align = LabelWidget.TextAlign.Left, Bold = true, }; bg.AddChild(label); controls.Add(label); var theirStance = new LabelWidget { Bounds = new Rectangle( margin + labelWidth + 10, y, labelWidth, 25), Id = "DIPLOMACY_PLAYER_LABEL_THEIR_{0}".F(p.Index), Text = p.PlayerName, Align = LabelWidget.TextAlign.Left, Bold = false, 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), Id = "DIPLOMACY_PLAYER_LABEL_MY_{0}".F(p.Index), GetText = () => world.LocalPlayer.Stances[ pp ].ToString(), }; myStance.OnMouseDown = mi => { ShowDropDown(pp, myStance); return true; }; bg.AddChild(myStance); controls.Add(myStance); y += 35; } }