コード例 #1
0
ファイル: Toolbar.cs プロジェクト: kevin-ye/ksp_toolbar
        internal void update()
        {
            visibleButtons.reset();

            if (draggable != null) {
                draggable.update();
            }
            if (resizable != null) {
                resizable.update();
            }

            if (Enabled && rectLocked && buttonOrderLocked && (displayMode == DisplayMode.VISIBLE)) {
                foreach (Button button in buttons) {
                    IDrawable drawable = button.command.Drawable;
                    if (drawable != null) {
                        drawable.Update();
                    }
                }
            }

            if (dropdownMenu != null) {
                // auto-close drop-down menu when clicking outside
                if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2)) && !dropdownMenu.contains(Utils.getMousePosition())) {
                    dropdownMenu.destroy();
                    dropdownMenu = null;
                }

                // auto-close drop-down menu when pause menu is opened
                if (Utils.isPauseMenuOpen()) {
                    dropdownMenu.destroy();
                    dropdownMenu = null;
                }
            }

            if (buttonOrderDraggables.Count() > 0) {
                foreach (Draggable d in new List<Draggable>(buttonOrderDraggables.Keys)) {
                    d.update();
                }
            }
        }
コード例 #2
0
ファイル: Toolbar.cs プロジェクト: kevin-ye/ksp_toolbar
        private void toggleDropdownMenu()
        {
            if (dropdownMenu == null) {
                dropdownMenu = new PopupMenu(new Vector2(rect.x + PADDING + getPosition(dropdownMenuButton).x, rect.y + rect.height + BUTTON_SPACING));

                bool regularEntriesEnabled = rectLocked && buttonOrderLocked;

                Button visibleButtonsButton = Button.createMenuOption("Configure Visible Buttons...");
                visibleButtonsButton.command.Enabled = regularEntriesEnabled && (visibleButtonsSelector == null);
                visibleButtonsButton.OnClick += (e) => {
                    toggleVisibleButtonsSelector();
                };
                dropdownMenu += visibleButtonsButton;

                dropdownMenu += Separator.Instance;

                Button toggleRectLockButton = Button.createMenuOption(rectLocked ? "Unlock Position and Size" : "Lock Position and Size");
                toggleRectLockButton.OnClick += (e) => {
                    rectLocked = !rectLocked;
                    draggable.Enabled = !rectLocked;
                    resizable.Enabled = !rectLocked;

                    if (rectLocked) {
                        fireChange();
                    } else {
                        autoHide = false;
                        foreach (Toolbar folder in folders.Values) {
                            folder.Visible = false;
                        }
                        if (visibleButtonsSelector != null) {
                            visibleButtonsSelector.destroy();
                        }
                    }
                };
                toggleRectLockButton.command.Enabled = buttonOrderLocked;
                dropdownMenu += toggleRectLockButton;

                Button toggleButtonOrderLockButton = Button.createMenuOption(buttonOrderLocked ? "Unlock Button Order" : "Lock Button Order");
                toggleButtonOrderLockButton.OnClick += (e) => {
                    buttonOrderLocked = !buttonOrderLocked;

                    hookButtonOrderDraggables(!buttonOrderLocked);

                    if (buttonOrderLocked) {
                        fireChange();
                    } else {
                        autoHide = false;
                    }
                    foreach (Toolbar folder in folders.Values) {
                        folder.Enabled = buttonOrderLocked;
                    }
                    if (visibleButtonsSelector != null) {
                        visibleButtonsSelector.destroy();
                    }
                };
                toggleButtonOrderLockButton.command.Enabled = rectLocked;
                dropdownMenu += toggleButtonOrderLockButton;

                Button toggleAutoHideButton = Button.createMenuOption(autoHide ? "Deactivate Auto-Hide at Screen Edge" : "Activate Auto-Hide at Screen Edge");
                toggleAutoHideButton.OnClick += (e) => {
                    autoHide = !autoHide;
                    fireChange();
                };
                toggleAutoHideButton.command.Enabled = regularEntriesEnabled && (autoHide || AtScreenEdge);
                dropdownMenu += toggleAutoHideButton;

                Button toggleDrawBorderButton = Button.createMenuOption(showBorder ? "Hide Border" : "Show Border");
                toggleDrawBorderButton.OnClick += (e) => {
                    showBorder = !showBorder;
                    foreach (Toolbar folder in folders.Values) {
                        folder.showBorder = showBorder;
                    }
                    fireChange();
                };
                toggleDrawBorderButton.command.Enabled = regularEntriesEnabled;
                dropdownMenu += toggleDrawBorderButton;

                Button toggleKSPSkinButton = Button.createMenuOption(UseKSPSkin ? "Use Unity 'Smoke' Skin" : "Use KSP Skin");
                toggleKSPSkinButton.OnClick += (e) => {
                    UseKSPSkin = !UseKSPSkin;
                    foreach (Toolbar folder in folders.Values) {
                        folder.UseKSPSkin = UseKSPSkin;
                    }
                    fireChange();
                };
                toggleKSPSkinButton.command.Enabled = regularEntriesEnabled;
                dropdownMenu += toggleKSPSkinButton;

                dropdownMenu += Separator.Instance;

                Button createFolderButton = Button.createMenuOption("Create New Folder...");
                createFolderButton.OnClick += (e) => createFolder();
                createFolderButton.command.Enabled = regularEntriesEnabled;
                dropdownMenu += createFolderButton;

                dropdownMenu += Separator.Instance;

                Button createToolbarButton = Button.createMenuOption("Create New Toolbar");
                createToolbarButton.OnClick += (e) => createToolbar();
                createToolbarButton.command.Enabled = regularEntriesEnabled;
                dropdownMenu += createToolbarButton;

                Button deleteToolbarButton = Button.createMenuOption("Delete Toolbar...");
                deleteToolbarButton.OnClick += (e) => deleteToolbar();
                deleteToolbarButton.command.Enabled = regularEntriesEnabled && (ToolbarManager.InternalInstance.ToolbarsCount > 1);
                dropdownMenu += deleteToolbarButton;

                dropdownMenu += Separator.Instance;

                Button aboutButton = Button.createMenuOption("About the Toolbar Plugin...");
                aboutButton.OnClick += (e) => Application.OpenURL(ToolbarManager.FORUM_THREAD_URL);
                dropdownMenu += aboutButton;

                dropdownMenu.OnAnyOptionClicked += () => {
                    dropdownMenu.destroy();
                    dropdownMenu = null;
                };
            } else {
                dropdownMenu.destroy();
                dropdownMenu = null;
            }
        }
コード例 #3
0
ファイル: Toolbar.cs プロジェクト: KaiSforza/ksp_toolbar
        internal void update()
        {
            if (draggable != null) {
                draggable.update();
            }
            if (resizable != null) {
                resizable.update();
            }

            if (dropdownMenu != null) {
                // auto-close drop-down menu when clicking outside
                if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2)) && !dropdownMenu.contains(Utils.getMousePosition())) {
                    dropdownMenu.destroy();
                    dropdownMenu = null;
                }

                // auto-close drop-down menu when pause menu is opened
                if (isPauseMenuOpen()) {
                    dropdownMenu.destroy();
                    dropdownMenu = null;
                }
            }

            if (buttonOrderDraggables.Count() > 0) {
                foreach (Draggable d in new List<Draggable>(buttonOrderDraggables.Keys)) {
                    d.update();
                }
            }
        }
コード例 #4
0
ファイル: Toolbar.cs プロジェクト: kevin-ye/ksp_toolbar
        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;
            };
        }
コード例 #5
0
ファイル: Toolbar.cs プロジェクト: KaiSforza/ksp_toolbar
        internal void loadSettings(ConfigNode parentNode, GameScenes scene)
        {
            // hide these
            WindowList.Instance.destroyDialogs();
            dropdownMenu = null;
            // deactivate these
            rectLocked = true;
            buttonOrderLocked = true;
            draggable.Enabled = false;
            resizable.Enabled = false;
            // pretend we're not auto-hidden right now
            displayMode = DisplayMode.VISIBLE;
            // enable ourselves
            Enabled = true;
            // hide folders
            foreach (Toolbar folder in folders.Values) {
                folder.Visible = false;
            }
            // pretend that nothing was visible until now
            visibleButtonIds.Clear();

            if (parentNode.HasNode("toolbar")) {
                foreach (Toolbar folder in new List<Toolbar>(folders.Values)) {
                    removeFolder(folder);
                }
                savedFolderSettings.Clear();

                ConfigNode toolbarNode = parentNode.GetNode("toolbar");
                ConfigNode settingsNode = toolbarNode.HasNode(scene.ToString()) ? toolbarNode.GetNode(scene.ToString()) : toolbarNode;
                rect.x = settingsNode.get("x", DEFAULT_X);
                rect.y = settingsNode.get("y", DEFAULT_Y);
                rect.width = settingsNode.get("width", DEFAULT_WIDTH);
                rect.height = settingsNode.get("height", 0f);
                autoHide = settingsNode.get("autoHide", false);
                showBorder = settingsNode.get("drawBorder", true);
                UseKSPSkin = settingsNode.get("useKSPSkin", false);
                savedButtonOrder = settingsNode.get("buttonOrder", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                savedVisibleButtons = new HashSet<string>(settingsNode.get("visibleButtons", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));

                if (settingsNode.HasNode("folders")) {
                    foreach (ConfigNode folderNode in settingsNode.GetNode("folders").nodes) {
                        string folderId = folderNode.name;
                        string toolTip = folderNode.get("toolTip", "");
                        HashSet<string> buttonIds = new HashSet<string>(folderNode.get("buttons", "").Split(new char[] { ',' }));

                        Toolbar folder = createFolder(folderId, toolTip, false);

                        savedFolderSettings[folderId].buttons = buttonIds;
                    }
                }

                // show/hide buttons according to saved settings
                foreach (Button button in buttons.Where(b => (b.ns != Button.NAMESPACE_INTERNAL) && !b.Equals(dropdownMenuButton))) {
                    button.UserVisible = savedVisibleButtons.Contains(button.ns + "." + button.id);
                }

                // move existing buttons according to saved folder contents
                foreach (Button button in new List<Button>(buttons)) {
                    string buttonId = button.ns + "." + button.id;
                    string folderId = savedFolderSettings.SingleOrDefault(kv => kv.Value.buttons.Contains(buttonId)).Key;
                    if (folderId != null) {
                        moveButtonToFolder(button, folders[folderId]);
                    }
                }
            }

            savedMaxWidth = rect.width;

            sortButtons(buttons, compareButtonsUserOrder);
        }