public void SetCommand(EventPage PageData, BasicCommand Command, int Indent = -1) { this.PageData = PageData; this.Command = Command; if (Indent == -1 && Command != null) { Indent = Command.Indent; } this.Indent = Indent; this.Sprites["bullet"].X = Indent * CommandBox.Indent + 6; this.Sprites["bullet"].Y = 9; HeaderLabel.SetPosition(19 + Indent * CommandBox.Indent, HeaderLabel.Position.Y); if (this.Command == null) { SetHeight(20); return; } this.CommandType = CommandPlugins.CommandTypes.Find(t => t.Identifier == Command.Identifier.Substring(1)).EmptyClone(); if (this.Command != null && this.CommandType.IsSubBranch) { this.Sprites["bullet"].Visible = false; WidgetContainer.SetPosition(30 + Indent * CommandBox.Indent, WidgetContainer.Position.Y); } else { WidgetContainer.SetPosition(19 + Indent * CommandBox.Indent, WidgetContainer.Position.Y); } HeaderLabel.SetText(this.CommandType.Name); HeaderLabel.SetVisible(this.CommandType.ShowHeader); dynamic basewidgets = this.CommandType.CallCreateReadOnly(); HeaderLabel.SetTextColor(this.CommandType.HeaderColor); for (int i = 0; i < basewidgets.Count; i++) { dynamic widget = basewidgets[i]; string type = widget.GetType().Name; Widget parent = null; if (widget.Parent != null) { foreach (string parentwidgetid in DynamicReadOnlyWidgets.Keys) { if (parentwidgetid == widget.parent.UniqueID) { parent = DynamicReadOnlyWidgets[parentwidgetid]; break; } } } if (parent == null) { parent = WidgetContainer; } Widget w = ProcessWidgetType(widget, type, parent); ProcessWidget(w, widget, false, true); DynamicReadOnlyWidgets.Add(widget.UniqueID, w); } Reload(); }
public CommandPicker() { SetTitle("Pick Command"); MainTabView = new TabView(this); MainTabView.SetPosition(1, 25); MainTabView.SetHeaderColor(new Color(59, 91, 124)); MainTabView.SetXOffset(16); for (int i = 0; i < CommandPlugins.CommandTypes.Count; i++) { DynamicCommandType t = CommandPlugins.CommandTypes[i]; if (string.IsNullOrEmpty(t.Name)) { continue; } string name = t.PickerTabName; int tabidx = MainTabView.Names.IndexOf(name); TabContainer tc = null; if (tabidx == -1) { tc = MainTabView.CreateTab(name); Container ButtonContainer = new Container(tc); } else { tc = MainTabView.Tabs[tabidx]; } int idx = tc.Widgets[0].Widgets.Count; Button b = new Button(tc.Widgets[0]); b.SetText(t.Name); b.SetPosition(9 + 153 * (idx % 2), 7 + 38 * (int)Math.Floor(idx / 2d)); b.SetSize(153, 38); b.OnClicked += delegate(BaseEventArgs e) { CreateCommand(t); }; } int count = 0; foreach (TabContainer tc in MainTabView.Tabs) { if (tc.Widgets[0].Widgets.Count > count) { count = tc.Widgets[0].Widgets.Count; } } MinimumSize = MaximumSize = new Size(count > 1 ? 326 : 173, 69 + 45 + 38 * count / 2); SetSize(MaximumSize); Center(); CreateButton("Cancel", Cancel); }
public CommandUtility GetBranchParent() { BasicCommand main = Commands[CommandIndex]; DynamicCommandType maintype = CommandBox.GetCommandType(main); string identifier = this.Commands[this.CommandIndex].Identifier; for (int i = this.CommandIndex - 1; i >= 0; i--) { BasicCommand cmd = this.Commands[i]; DynamicCommandType cmdtype = CommandBox.GetCommandType(cmd); if (maintype.IsSubBranch && cmdtype.HasBranches && cmd.Indent == main.Indent || !maintype.IsSubBranch && cmd.Indent < main.Indent) { return(new CommandUtility(this.CommandBox, this.Commands, i, this.Commands[i].Parameters)); } } throw new Exception($"Failed to find a branch parent."); }
public void RemoveBranch(BasicCommand main) { int StartIndex = -1; for (int i = this.CommandIndex; i < Commands.Count; i++) { BasicCommand cmd = this.Commands[i]; DynamicCommandType cmdtype = CommandBox.GetCommandType(cmd); if (cmd == main) { StartIndex = i; } else if (StartIndex != -1) { if (cmd.Indent <= main.Indent) { this.Commands.RemoveRange(StartIndex, i - StartIndex); break; } } } }
public void CreateCommand(DynamicCommandType Type) { this.ChosenCommand = Type; this.Close(); }