public GameVariablePicker(int GroupID, int VariableID) : base() { this.GroupID = GroupID; this.VariableID = VariableID; MinimumSize = MaximumSize = new Size(361, 409); SetTitle("Choose Game Variable"); SetSize(MaximumSize); Center(); CategoryLabel = new Label(this); CategoryLabel.SetPosition(10, 28); CategoryLabel.SetText("Categories"); CategoryLabel.SetFont(Font.Get("Fonts/Ubuntu-B", 14)); VariableLabel = new Label(this); VariableLabel.SetPosition(194, 28); VariableLabel.SetText("Variables"); VariableLabel.SetFont(Font.Get("Fonts/Ubuntu-B", 14)); GroupBox = new ListBox(this); GroupBox.SetPosition(6, 48); GroupBox.SetSize(167, 254); RedrawGroupBox(); GroupBox.OnSelectionChanged += delegate(BaseEventArgs e) { GroupNameBox.SetInitialText(Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Name ?? ""); RedrawVariableBox(); VariableBox.SetSelectedIndex(0, true); VariableBox.MainContainer.VScrollBar.SetValue(0); }; VariableBox = new ListBox(this); VariableBox.SetPosition(185, 48); VariableBox.SetSize(167, 254); VariableBox.OnSelectionChanged += delegate(BaseEventArgs e) { VariableNameBox.SetInitialText(Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Variables[VariableBox.SelectedIndex].Name ?? ""); }; VariableBox.OnDoubleClicked += delegate(BaseEventArgs e) { this.VariableID = VariableBox.SelectedIndex + 1; OK(new BaseEventArgs()); }; GroupNameLabel = new Label(this); GroupNameLabel.SetPosition(9, 311); GroupNameLabel.SetText("Name:"); GroupNameLabel.SetFont(Font.Get("Fonts/ProductSans-M", 12)); GroupNameBox = new TextBox(this); GroupNameBox.SetPosition(56, 307); GroupNameBox.SetSize(117, 27); GroupNameBox.OnTextChanged += delegate(BaseEventArgs e) { Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Name = GroupNameBox.Text; GroupBox.Redraw(); }; VariableNameLabel = new Label(this); VariableNameLabel.SetPosition(193, 311); VariableNameLabel.SetText("Name:"); VariableNameLabel.SetFont(Font.Get("Fonts/ProductSans-M", 12)); VariableNameBox = new TextBox(this); VariableNameBox.SetPosition(235, 307); VariableNameBox.SetSize(117, 27); VariableNameBox.OnTextChanged += delegate(BaseEventArgs e) { Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Variables[VariableBox.SelectedIndex].Name = VariableNameBox.Text; VariableBox.Redraw(); }; ChangeMaxGroups = new Button(this); ChangeMaxGroups.SetPosition(9, 340); ChangeMaxGroups.SetSize(163, 29); ChangeMaxGroups.SetText("Change Maximum"); ChangeMaxGroups.OnClicked += delegate(BaseEventArgs e) { PopupWindow win = new PopupWindow(); win.SetSize(270, 125); win.SetTitle("Set Variable Group capacity"); Label label = new Label(win); label.SetText("Set the maximum available number of groups."); label.SetPosition(5, 35); Label label2 = new Label(win); label2.SetText("Capacity:"); label2.SetPosition(75, 60); NumericBox num = new NumericBox(win); num.SetSize(66, 27); num.SetPosition(130, 55); num.SetValue(Editor.ProjectSettings.VariableGroupCapacity); num.MinValue = 1; win.CreateButton("Cancel", delegate(BaseEventArgs e) { win.Close(); }); win.CreateButton("OK", delegate(BaseEventArgs e) { int NewValue = num.Value; if (NewValue == Editor.ProjectSettings.VariableGroupCapacity) { win.Close(); return; } else if (NewValue > Editor.ProjectSettings.VariableGroupCapacity) { int Extra = NewValue - Editor.ProjectSettings.VariableGroupCapacity; for (int i = 0; i < Extra; i++) { Editor.ProjectSettings.Variables.Add(new GameVariableGroup() { ID = Editor.ProjectSettings.Variables.Count + 1 }); } Editor.ProjectSettings.VariableGroupCapacity = NewValue; RedrawGroupBox(); win.Close(); } else { int Lost = Editor.ProjectSettings.VariableGroupCapacity - NewValue; MessageBox box = new MessageBox("Warning", $"By resizing the Variable Group capacity from {Editor.ProjectSettings.VariableGroupCapacity} to {NewValue}, {Lost} entries will be removed.\n" + "This may cause unforeseen problems if Game Variables from these groups are still in use.\n" + "Would you like to proceed and delete these Variable Groups?", ButtonType.YesNoCancel, IconType.Warning); box.OnButtonPressed += delegate(BaseEventArgs e) { if (box.Result == 0) // Yes -> resize Switch Group capacity and delete Switch Groups { for (int i = Editor.ProjectSettings.Variables.Count - 1; i >= 0; i--) { if (i == NewValue) { break; } Editor.ProjectSettings.Variables[i] = null; } Editor.ProjectSettings.Variables.RemoveRange(NewValue, Lost); Editor.ProjectSettings.VariableGroupCapacity = NewValue; RedrawGroupBox(); win.Close(); } else // No, cancel -> do nothing { win.Close(); } }; } }); win.Center(); }; ChangeMaxVariables = new Button(this); ChangeMaxVariables.SetPosition(188, 340); ChangeMaxVariables.SetSize(163, 29); ChangeMaxVariables.SetText("Change Maximum"); ChangeMaxVariables.OnClicked += delegate(BaseEventArgs e) { PopupWindow win = new PopupWindow(); win.SetSize(270, 125); win.SetTitle("Set Variable capacity"); Label label = new Label(win); label.SetText("Set the maximum available number of variables."); label.SetPosition(5, 35); Label label2 = new Label(win); label2.SetText("Capacity:"); label2.SetPosition(75, 60); NumericBox num = new NumericBox(win); num.SetSize(66, 27); num.SetPosition(130, 55); num.SetValue(Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity); num.MinValue = 1; win.CreateButton("Cancel", delegate(BaseEventArgs e) { win.Close(); }); win.CreateButton("OK", delegate(BaseEventArgs e) { int NewValue = num.Value; if (NewValue == Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity) { win.Close(); return; } else if (NewValue > Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity) { int Extra = NewValue - Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity; for (int i = 0; i < Extra; i++) { Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Variables.Add(new GameVariable() { ID = Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Variables.Count + 1 }); } Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity = NewValue; RedrawVariableBox(); win.Close(); } else { int Lost = Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity - NewValue; MessageBox box = new MessageBox("Warning", $"By resizing the Variable capacity from {Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity} to {NewValue}, {Lost} entries will be removed.\n" + "This may cause unforeseen problems if any of these Variables are still in use.\n" + "Would you like to proceed and delete these Variables?", ButtonType.YesNoCancel, IconType.Warning); box.OnButtonPressed += delegate(BaseEventArgs e) { if (box.Result == 0) // Yes -> resize Switch Group capacity and delete Switch Groups { for (int i = Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Variables.Count - 1; i >= 0; i--) { if (i == NewValue) { break; } Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Variables[i] = null; } Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].Variables.RemoveRange(NewValue, Lost); Editor.ProjectSettings.Variables[GroupBox.SelectedIndex].VariableCapacity = NewValue; RedrawVariableBox(); win.Close(); } else // No, cancel -> do nothing { win.Close(); } }; } }); win.Center(); }; GroupBox.SetSelectedIndex(this.GroupID - 1); VariableBox.SetSelectedIndex(this.VariableID - 1); CreateButton("Cancel", Cancel); CreateButton("OK", OK); }
public void EditWindow(BaseEvent CallBack = null) { if (this.Command == null || !this.CommandType.IsEditable) { return; } PopupWindow = new PopupWindow(); OldParameters = new Dictionary <string, object>(Command.Parameters); WindowUtility = GenerateUtility(); dynamic basewidgets = this.CommandType.CallCreateWindow(WindowUtility); 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 DynamicWindowWidgets.Keys) { if (parentwidgetid == widget.Parent.UniqueID) { parent = DynamicWindowWidgets[parentwidgetid]; break; } } } if (parent == null) { parent = PopupWindow; } Widget w = ProcessWidgetType(widget, type, parent); ProcessWidget(w, widget, true, true); DynamicWindowWidgets.Add(widget.UniqueID, w); DynamicWindowWidgetObjects.Add(widget.UniqueID, widget); } int width = CommandType.WindowWidth; int height = CommandType.WindowHeight; PopupWindow.SetTitle(CommandType.Name); PopupWindow.MinimumSize = PopupWindow.MaximumSize = new Size(width, height); PopupWindow.SetSize(PopupWindow.MaximumSize); PopupWindow.CreateButton("Cancel", delegate(BaseEventArgs e) { CloseWindow(); }); PopupWindow.CreateButton("OK", delegate(BaseEventArgs e) { SaveWindow(WindowUtility); if (!WindowUtility.AwaitCloseFlag) { CloseWindow(); } }); PopupWindow.Center(); PopupWindow.OnClosed += delegate(BaseEventArgs e) { Reload(); CallBack?.Invoke(e); }; }
public DatabaseDataList(IContainer Parent) : base(Parent) { Sprites["listbox"] = new Sprite(this.Viewport); Sprites["header"] = new Sprite(this.Viewport); Sprites["header"].X = 10; Sprites["header"].Y = 10; ListContainer = new Container(this); ListContainer.SetPosition(3, 44); ListContainer.VAutoScroll = true; VScrollBar vslist = new VScrollBar(this); vslist.SetPosition(187, 41); ListContainer.SetVScrollBar(vslist); DataList = new ListDrawer(ListContainer); List <ListItem> Tilesets = new List <ListItem>(); for (int i = 1; i < Game.Data.Tilesets.Count; i++) { Game.Tileset t = Game.Data.Tilesets[i]; Tilesets.Add(new ListItem($"{Utilities.Digits(i, 3)}: {t?.Name}", t)); } DataList.SetItems(Tilesets); DataList.OnSelectionChanged += delegate(BaseEventArgs e) { TilesetEditor.SetTileset(DataList.SelectedItem.Object as Game.Tileset, DataList.SelectedIndex + 1); }; ChangeAmountButton = new Button(this); ChangeAmountButton.SetSize(154, 37); ChangeAmountButton.SetText("Change Amount..."); ChangeAmountButton.OnClicked += delegate(BaseEventArgs e) { PopupWindow win = new PopupWindow(); win.SetSize(270, 125); win.SetTitle("Set tileset capacity"); Label label = new Label(win); label.SetText("Set the maximum available number of tilesets."); label.SetPosition(5, 35); Label label2 = new Label(win); label2.SetText("Capacity:"); label2.SetPosition(75, 60); NumericBox num = new NumericBox(win); num.SetSize(66, 27); num.SetPosition(130, 55); num.SetValue(Editor.ProjectSettings.TilesetCapacity); num.MinValue = 1; Button CancelButton = new Button(win); CancelButton.SetText("Cancel"); CancelButton.SetPosition(win.Size.Width - CancelButton.Size.Width - 5, win.Size.Height - CancelButton.Size.Height - 5); CancelButton.OnClicked += delegate(BaseEventArgs e) { win.Close(); }; Button OKButton = new Button(win); OKButton.SetText("OK"); OKButton.SetPosition(CancelButton.Position.X - OKButton.Size.Width, CancelButton.Position.Y); OKButton.OnClicked += delegate(BaseEventArgs e) { int NewValue = num.Value; if (NewValue == Editor.ProjectSettings.TilesetCapacity) { win.Close(); return; } else if (NewValue > Editor.ProjectSettings.TilesetCapacity) { int Extra = NewValue - Editor.ProjectSettings.TilesetCapacity; for (int i = 0; i < Extra; i++) { Game.Data.Tilesets.Add(null); } Editor.ProjectSettings.TilesetCapacity = NewValue; RefreshList(); win.Close(); } else { int Lost = Editor.ProjectSettings.TilesetCapacity - NewValue; int DefinedCount = 0; for (int i = Game.Data.Tilesets.Count - 1; i >= 0; i--) { if (i == NewValue) { break; } if (Game.Data.Tilesets[i] != null) { DefinedCount++; } } if (DefinedCount > 0) { MessageBox box = new MessageBox("Warning", $"By resizing the tileset capacity from {Editor.ProjectSettings.TilesetCapacity} to {NewValue}, {Lost} entries will be removed, " + $"of which {DefinedCount} {(DefinedCount == 1 ? "is a" : "are")} defined tileset{(DefinedCount == 1 ? "" : "s")}.\n" + "Would you like to proceed and delete these tilesets?", ButtonType.YesNoCancel, IconType.Warning); box.OnButtonPressed += delegate(BaseEventArgs e) { if (box.Result == 0) // Yes -> resize tileset capacity and delete tilesets { for (int i = Game.Data.Tilesets.Count - 1; i >= 0; i--) { if (i == NewValue) { break; } foreach (KeyValuePair <int, Game.Map> kvp in Game.Data.Maps) { if (kvp.Value.TilesetIDs.Contains(i)) { kvp.Value.RemoveTileset(i); } } if (Game.Data.Tilesets[i] != null) { Game.Data.Tilesets[i].TilesetBitmap.Dispose(); Game.Data.Tilesets[i].TilesetListBitmap.Dispose(); } Game.Data.Tilesets[i] = null; } Game.Data.Tilesets.RemoveRange(NewValue + 1, Lost); Editor.ProjectSettings.TilesetCapacity = NewValue; RefreshList(); win.Close(); } else // No, cancel -> do nothing { win.Close(); } }; } else { Game.Data.Tilesets.RemoveRange(NewValue + 1, Lost); Editor.ProjectSettings.TilesetCapacity = NewValue; RefreshList(); win.Close(); } } }; win.Center(); }; }