private void OnLevelWasLoaded(int level)
        {
            if (Game.AddPiece == null)
            {
                return;
            }
            timeSliderObject = GameObject.FindObjectOfType <TimeSliderObject>();
            timeScale        = timeSliderObject.timeSliderCode.delegateTimeScale / 2f;

            // load configuration
            speedUpKey   = tempSpeedUpKey = Configuration.GetString("key:speedup", "=");
            speedDownKey = tempSpeedDownKey = Configuration.GetString("key:speeddown", "-");

            string[] hotkeys = Configuration.GetString("boundKeys", "").Split(new char[] { ' ' },
                                                                              StringSplitOptions.RemoveEmptyEntries); // this shouldn't really be needed, but computers are weird sometimes
            foreach (var hotkey in hotkeys)
            {
                percentHotkeys[hotkey] = Configuration.GetFloat("boundKey:" + hotkey, -1);
            }

            // add commands
            Commands.RegisterCommand("addTimeHotkey", new CommandCallback(AddHotkey), ADD_TIME_HOTKEY_USAGE);
            Commands.RegisterCommand("removeTimeHotkey", new CommandCallback(RemoveHotkey), REMOVE_TIME_HOTKEY_USAGE);
            Commands.RegisterCommand("listTimeHotkeys", new CommandCallback(ListHotkeys), LIST_TIME_HOTKEYS_USAGE);
            Commands.RegisterHelpMessage("button-mapper-mod commands:\n" +
                                         ADD_TIME_HOTKEY_USAGE + "\n" +
                                         REMOVE_TIME_HOTKEY_USAGE + "\n" +
                                         LIST_TIME_HOTKEYS_USAGE
                                         );

            isLoaded = true;
        }
        private void OnLevelWasLoaded(int level)
        {
            if (Game.AddPiece == null) return;
            timeSliderObject = GameObject.FindObjectOfType<TimeSliderObject>();
            timeScale = timeSliderObject.timeSliderCode.delegateTimeScale / 2f;

            // load configuration
            speedUpKey = tempSpeedUpKey = Configuration.GetString("key:speedup", "=");
            speedDownKey = tempSpeedDownKey = Configuration.GetString("key:speeddown", "-");

            string[] hotkeys = Configuration.GetString("boundKeys", "").Split(new char[] {' '},
                StringSplitOptions.RemoveEmptyEntries); // this shouldn't really be needed, but computers are weird sometimes
            foreach (var hotkey in hotkeys)
            {
                percentHotkeys[hotkey] = Configuration.GetFloat("boundKey:" + hotkey, -1);
            }

            // add commands
            Commands.RegisterCommand("addTimeHotkey", new CommandCallback(AddHotkey), ADD_TIME_HOTKEY_USAGE);
            Commands.RegisterCommand("removeTimeHotkey", new CommandCallback(RemoveHotkey), REMOVE_TIME_HOTKEY_USAGE);
            Commands.RegisterCommand("listTimeHotkeys", new CommandCallback(ListHotkeys), LIST_TIME_HOTKEYS_USAGE);
            Commands.RegisterHelpMessage("button-mapper-mod commands:\n" +
                ADD_TIME_HOTKEY_USAGE + "\n" +
                REMOVE_TIME_HOTKEY_USAGE + "\n" +
                LIST_TIME_HOTKEYS_USAGE
            );

            isLoaded = true;
        }
Beispiel #3
0
        private void Update()
        {
            if (!Game.AddPiece)
            {
                return;
            }

            if (increaseTime.Pressed())
            {
                TimeSliderObject sliderObj = FindObjectOfType <TimeSliderObject>();
                TimeSlider       slider    = FindObjectOfType <TimeSlider>();
                sliderObj.SetPercentage(
                    Mathf.Clamp01((slider.delegateTimeScale + 0.1f) / 2f));
            }
            if (decreaseTime.Pressed())
            {
                TimeSliderObject sliderObj = FindObjectOfType <TimeSliderObject>();
                TimeSlider       slider    = FindObjectOfType <TimeSlider>();
                sliderObj.SetPercentage(
                    Mathf.Clamp01((slider.delegateTimeScale - 0.1f) / 2f));
            }
            if (timeTo100.Pressed())
            {
                FindObjectOfType <TimeSliderObject>().SetPercentage(0.5f);
            }
            if (timeTo0.Pressed())
            {
                FindObjectOfType <TimeSliderObject>().SetPercentage(0.0f);
            }

            if (Game.IsSimulating)
            {
                return;
            }

            //Debug code helpful for filling out blockIndices table
#if DEBUG
            if (Input.GetKeyDown(KeyCode.N))
            {
                var buttons = tabController.tabs[tabController.activeTab]
                              .GetComponent <BlockMenuControl>().buttons;
                for (int i = 0; i < buttons.Length; i++)
                {
                    Debug.Log("buttons[" + i + "] = " + buttons[i]);
                }
            }
#endif

            if (pipette.Pressed())
            {
                RaycastHit hit;
                var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    var myName = hit.transform.GetComponent <MyBlockInfo>().blockName;
                    for (int i = 0; i < PrefabMaster.BlockPrefabs.Count; i++)
                    {
                        var type = PrefabMaster.BlockPrefabs[i].gameObject;
                        if ((type.GetComponent <MyBlockInfo>() &&
                             type.GetComponent <MyBlockInfo>().blockName == myName) ||
                            (type.GetComponentInChildren <MyBlockInfo>() &&
                             type.GetComponentInChildren <MyBlockInfo>().blockName == myName))
                        {
                            StartCoroutine(ExecuteWithDisabledGhost(() => { Game.AddPiece.SetBlockType(i); }));
                            break;
                        }
                    }
                }
            }

            if (openSettings.Pressed())
            {
                RaycastHit hit;
                var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    var block = hit.transform.gameObject.GetComponent <BlockBehaviour>();
                    FindObjectOfType <KeyMapModeButton>().KeyMapOn();
                    BlockSelect(block);
                    BlockMapper.Open(block);
                }
            }

            if (nextTab.Pressed())
            {
                currentTab = InternalToOrderedTabIndex(tabController.activeTab);
                tabController.OpenTab(tabIndices[mod(++currentTab, tabIndices.Length)]);
            }
            if (previousTab.Pressed())
            {
                currentTab = InternalToOrderedTabIndex(tabController.activeTab);
                tabController.OpenTab(tabIndices[mod(--currentTab, tabIndices.Length)]);
            }

            // Don't react to block shortcuts when block settings are open to prevent
            // typing a slider value changing what block is selected
            if (BlockMapper.CurrentInstance == null)
            {
                for (int i = 0; i < 9; i++)
                {
                    if (blockKeys[i].Pressed())
                    {
                        var index = blockIndices[
                            InternalToOrderedTabIndex(tabController.activeTab)][i];
                        if (index != -1)
                        {
                            StartCoroutine(ExecuteWithDisabledGhost(() =>
                            {
                                tabController.tabs[tabController.activeTab]
                                .GetComponent <BlockMenuControl>()
                                .buttons[index].Set();
                            }));
                        }
                    }
                }
            }

            for (int i = 0; i < 7; i++)
            {
                if (tabKeys[i].Pressed())
                {
                    tabController.OpenTab(tabIndices[i]);
                }
            }
        }