internal Button(Command command, Toolbar toolbar = null) { this.command = command; this.toolbar = toolbar; OnMouseEnter += () => { showTooltip = true; command.mouseEnter(); }; OnMouseLeave += () => { showTooltip = false; command.mouseLeave(); }; command.OnChange += () => clearCaches(); command.OnDestroy += () => Destroy(); if (toolbar != null) { toolbar.OnSkinChange += clearCaches; } }
internal ToolbarManager() { Log.trace("ToolbarManager()"); if (Instance == null) { Instance = this; GameObject.DontDestroyOnLoad(this); loadSettings(GameScenes.MAINMENU); toolbar = new Toolbar(); toolbar.onChange += toolbarChanged; updateChecker = new UpdateChecker(); updateChecker.OnDone += () => updateChecker = null; GameEvents.onGameSceneLoadRequested.Add(gameSceneLoadRequested); } else { Log.warn("ToolbarManager already running, marking this instance as stale"); running = false; } }
internal Button(string ns, string id, Toolbar toolbar = null) { checkId(ns, "namespace"); checkId(id, "ID"); this.ns = ns; this.id = id; this.toolbar = toolbar; Enabled = true; if (ns == NAMESPACE_INTERNAL) { UserVisible = true; } OnMouseEnter += (e) => showTooltip = true; OnMouseLeave += (e) => showTooltip = false; if (toolbar != null) { // reset style when skin changes toolbar.onSkinChange += skinChanged; } }
private Toolbar addToolbar(string toolbarId) { Toolbar toolbar = new Toolbar(); toolbar.OnChange += toolbarChanged; toolbars.Add(toolbarId, toolbar); return toolbar; }
internal void destroyToolbar(Toolbar toolbar) { string toolbarId = toolbars.Single(kv => kv.Value.Equals(toolbar)).Key; toolbars.Remove(toolbarId); toolbar.destroy(); if (settings.HasNode("toolbars")) { ConfigNode toolbarsNode = settings.GetNode("toolbars"); string scene = gameScene.ToString(); if (toolbarsNode.HasNode(scene)) { ConfigNode sceneNode = toolbarsNode.GetNode(scene); if (sceneNode.HasNode(toolbarId)) { sceneNode.RemoveNode(toolbarId); saveSettings(); } } } }
internal Toolbar(Mode mode = Mode.TOOLBAR, Toolbar parentToolbar = null, RelativePosition preferredRelativePosition = RelativePosition.DEFAULT) { this.mode = mode; this.parentToolbar = parentToolbar; this.relativePosition = preferredRelativePosition; visibleButtons = new VisibleButtons(buttons, isEffectivelyUserVisible); autoHideUnimportantButtonAlpha.a = 0.4f; rect = new Rectangle(new Rect(DEFAULT_X, DEFAULT_Y, DEFAULT_WIDTH, float.MinValue)); if (mode == Mode.TOOLBAR) { dropdownMenuButton = Button.createToolbarDropdown(); dropdownMenuButton.OnClick += (e) => toggleDropdownMenu(); buttons.Add(dropdownMenuButton); draggable = new Draggable(rect, PADDING, (pos) => !dropdownMenuButtonContains(pos) && !resizable.HandleRect.Contains(pos)); resizable = new Resizable(rect, PADDING, (pos) => !dropdownMenuButtonContains(pos)); draggable.OnDrag += (e) => { resizable.Enabled = !draggable.Dragging; toolbarDrag(); }; resizable.OnDrag += (e) => { draggable.Enabled = !resizable.Dragging; toolbarResize(); }; CursorGrabbing.Instance.add(draggable); CursorGrabbing.Instance.add(resizable); CursorGrabbing.Instance.add(this); ToolbarManager.InternalInstance.OnCommandAdded += updateVisibleButtons; } else { showBorder = parentToolbar.showBorder; useKSPSkin_ = parentToolbar.UseKSPSkin; } }
private void deleteFolder(Toolbar folder) { ConfirmDialog.confirm("Delete Folder", "Delete this folder? Buttons inside the folder will be moved to the main toolbar.", () => removeFolder(folder)); }
private Toolbar createFolder(string id, string texturePath, string toolTip, bool visible) { if (visible) { // close all other folders first foreach (Toolbar folder in folders.Values) { folder.Visible = false; } } RelativePosition relativePosition = lastChildPosition.ContainsKey(id) ? lastChildPosition[id] : RelativePosition.DEFAULT; Toolbar newFolder = new Toolbar(Mode.FOLDER, this, relativePosition); newFolder.Visible = visible; folders.Add(id, newFolder); Command folderCommand = new Command(ToolbarManager.NAMESPACE_INTERNAL, id); folderCommand.TexturePath = texturePath; folderCommand.ToolTip = toolTip; Button folderButton = null; folderCommand.OnClick += (e) => { switch (e.MouseButton) { case 0: newFolder.Visible = !newFolder.Visible; if (newFolder.Visible) { foreach (Toolbar otherFolder in folders.Values.Where(f => !f.Equals(newFolder))) { otherFolder.Visible = false; } } break; case 1: openFolderButtonDropdownMenu(newFolder, getPosition(folderButton) + new Vector2(rect.x + PADDING, rect.y + PADDING + folderButton.Size.y + BUTTON_SPACING)); break; } }; folderButton = new Button(folderCommand, this); folderButtons.Add(folderButton, newFolder); add(folderButton); savedFolderSettings.Add(id, new FolderSettings() { buttons = new HashSet<string>(), texturePath = texturePath, toolTip = toolTip }); newFolder.OnVisibleChange += () => { if (!newFolder.Visible) { lastChildPosition.addOrUpdate(id, newFolder.relativePosition); } }; return newFolder; }
private void removeFolder(Toolbar folder) { string folderId = folders.Single(kv => kv.Value.Equals(folder)).Key; folders.Remove(folderId); savedFolderSettings.Remove(folderId); Button folderButton = folderButtons.Single(kv => kv.Value.Equals(folder)).Key; folderButton.Destroy(); foreach (Button b in new List<Button>(folder.buttons)) { folder.remove(b); add(b); } folder.destroy(); }
private void openFolderButtonDropdownMenu(Toolbar folder, Vector2 pos) { dropdownMenu = new PopupMenu(pos); Button editButton = Button.createMenuOption("Edit Folder Settings"); editButton.OnClick += (e) => editFolder(folder); dropdownMenu += editButton; Button deleteButton = Button.createMenuOption("Delete Folder"); deleteButton.OnClick += (e) => deleteFolder(folder); dropdownMenu += deleteButton; dropdownMenu.OnAnyOptionClicked += () => { dropdownMenu.destroy(); dropdownMenu = null; }; }
private void moveButtonToFolder(Button button, Toolbar folder) { remove(button); folder.add(button); }
private void editFolder(Toolbar folder) { string folderId = folders.Single(kv => kv.Value.Equals(folder)).Key; FolderSettings folderSettings = savedFolderSettings[folderId]; FolderSettingsDialog folderSettingsDialog = new FolderSettingsDialog(folderSettings.texturePath, folderSettings.toolTip); folderSettingsDialog.OnOkClicked += () => { folderSettings.texturePath = folderSettingsDialog.TexturePath; folderSettings.toolTip = folderSettingsDialog.ToolTip; Button folderButton = folderButtons.Single(kv => kv.Value.Equals(folder)).Key; folderButton.command.TexturePath = folderSettings.texturePath; folderButton.command.ToolTip = folderSettings.toolTip; fireChange(); }; }
internal Toolbar(Mode mode = Mode.TOOLBAR, Toolbar parentToolbar = null) { this.mode = mode; this.parentToolbar = parentToolbar; autoHideUnimportantButtonAlpha.a = 0.4f; rect = new Rectangle(new Rect(DEFAULT_X, DEFAULT_Y, DEFAULT_WIDTH, float.MinValue)); if (mode == Mode.TOOLBAR) { dropdownMenuButton = Button.createToolbarDropdown(); dropdownMenuButton.OnClick += (e) => toggleDropdownMenu(); buttons.Add(dropdownMenuButton); setupConfigureVisibleButtonsButton(); draggable = new Draggable(rect, PADDING, (pos) => !dropdownMenuButtonContains(pos) && !resizable.HandleRect.Contains(pos)); resizable = new Resizable(rect, PADDING, (pos) => !dropdownMenuButtonContains(pos)); draggable.OnDrag += (e) => { resizable.Enabled = !draggable.Dragging; toolbarDrag(); }; resizable.OnDrag += (e) => { draggable.Enabled = !resizable.Dragging; toolbarResize(); }; CursorGrabbing.Instance.add(draggable); CursorGrabbing.Instance.add(resizable); CursorGrabbing.Instance.add(this); } else { showBorder = parentToolbar.showBorder; useKSPSkin_ = parentToolbar.UseKSPSkin; } }
private void editFolder(Toolbar folder) { string folderId = folders.Single(kv => kv.Value.Equals(folder)).Key; string toolTip = savedFolderSettings[folderId].toolTip; FolderSettingsDialog folderSettingsDialog = new FolderSettingsDialog(toolTip); folderSettingsDialog.OnOkClicked += () => { toolTip = folderSettingsDialog.ToolTip; savedFolderSettings[folderId].toolTip = toolTip; Button folderButton = folderButtons.Single(kv => kv.Value.Equals(folder)).Key; folderButton.ToolTip = toolTip; fireChange(); }; }
private Toolbar createFolder(string id, string toolTip, bool visible) { if (visible) { // close all other folders first foreach (Toolbar folder in folders.Values) { folder.Visible = false; } } Toolbar newFolder = new Toolbar(Mode.FOLDER, this); newFolder.Visible = visible; folders.Add(id, newFolder); Button folderButton = new Button(Button.NAMESPACE_INTERNAL, id, this); folderButton.TexturePath = "000_Toolbar/folder"; folderButton.ToolTip = toolTip; folderButton.OnClick += (e) => { switch (e.MouseButton) { case 0: newFolder.Visible = !newFolder.Visible; if (newFolder.Visible) { foreach (Toolbar otherFolder in folders.Values.Where(f => !f.Equals(newFolder))) { otherFolder.Visible = false; } } break; case 1: openFolderButtonDropdownMenu(newFolder, getPosition(folderButton) + new Vector2(rect.x + PADDING, rect.y + PADDING + folderButton.Size.y + BUTTON_SPACING)); break; } }; folderButtons.Add(folderButton, newFolder); add(folderButton); savedFolderSettings.Add(id, new FolderSettings() { buttons = new HashSet<string>(), toolTip = toolTip }); return newFolder; }