Exemplo n.º 1
0
    void OnMappingChanged(Dictionary <string, DulibaWaitor.Command> newMap)
    {
        // If this happens twice per frame, the second occurance is the new black.
        leftButtons.ClearNewButtons();
        rightButtons.ClearNewButtons();

        foreach (var kvp in newMap)
        {
            string commandKey = kvp.Key;
            DulibaWaitor.Command newCommand = kvp.Value;

            Change      change          = Change.Create;
            ButtonGroup buttonsToChange = rightButtons;

            if (currentMap.ContainsKey(commandKey))
            {
                DulibaWaitor.Command oldCommand = currentMap[commandKey];

                if (oldCommand.disabled.HasValue != newCommand.disabled.HasValue)
                {
                    change = Change.Nothing;
                }
                if (oldCommand.callback != newCommand.callback)
                {
                    change = Change.Create;
                }
            }

            if (newCommand.leftHand)
            {
                buttonsToChange = leftButtons;
            }

            string quantity = "";

            if (dulibaWaitor.workArea is Shelf import)
            {
                foreach (var action in dulibaWaitor.actions)
                {
                    if (action.command == commandKey.ToLower())
                    {
                        if (!import.items[action.pickupIndex].infinite)
                        {
                            quantity = import.items[action.pickupIndex].itemCount.ToString();
                        }
                        break;
                    }
                }
            }

            /*
             * switch (change)
             * {
             *
             *      case Change.Nothing:
             *              buttonsToChange.UpdateButton(new ButtonInfo() { name = newCommand.name, button = commandKey, enabled = !newCommand.disabled.HasValue, image = newCommand.image });
             *              break;
             *      case Change.Create:*/
            buttonsToChange.CreateButton(new ButtonInfo()
            {
                quantity = quantity, name = newCommand.name, button = commandKey, enabled = !newCommand.disabled.HasValue, image = newCommand.image
            });

            /*break;
             *          }
             */
            //buttonsToChange.DisplayButton(new ButtonInfo() { name = command.name, button = commandKey, enabled = !command.disabled.HasValue, image = command.image });
        }

        /*
         * foreach (var kvp in currentMap)
         * {
         *      string commandKey = kvp.Key;
         *      DulibaWaitor.Command command = kvp.Value;
         *      ButtonGroup buttonsToChange = rightButtons;
         *
         *      if (command.leftHand)
         *              buttonsToChange = leftButtons;
         *
         *      if (!newMap.ContainsKey(kvp.Key))
         *              buttonsToChange.DestroyButton(kvp.Key);
         * }*/

        currentMap = newMap;
    }
Exemplo n.º 2
0
    void KeyAction(string button, DulibaInputKeys.KeyPress phase)
    {
        WorkArea currentWorkArea = waitor.workArea;

        foreach (var kvp in map)
        {
            string key = kvp.Key;
            DulibaWaitor.Command command = kvp.Value;

            if (button == key)
            {
                switch (phase)
                {
                case DulibaInputKeys.KeyPress.Down:
                    if (command.disabled == null)
                    {
                        waitor.actionMap.Add(new DulibaWaitor.ActionMap(key, Time.time, Time.time + command.workTime * (1 / waitor.characterData.workTimeMultiplier), command));
                        var   action = waitor.actionMap.GetByCommandString(key);
                        float perc   = Mathf.InverseLerp(action.startAction, action.endAction, Time.time);
                        switch (command.leftHand)
                        {
                        case true:
                            waitor.leftHand.radialImg.gameObject.SetActive(true);
                            waitor.leftHand.radialImg.fillAmount = 0;
                            break;

                        default:
                            waitor.rightHand.radialImg.gameObject.SetActive(true);
                            waitor.rightHand.radialImg.fillAmount = 0;
                            break;
                        }
                    }
                    break;

                case DulibaInputKeys.KeyPress.Pressed:
                    if (waitor.actionMap.Contains(key))
                    {
                        if (Time.time > waitor.actionMap.GetByCommandString(key).endAction)
                        {
                            command.callback?.Invoke();
                            command.lateCallback?.Invoke();
                            waitor.actionMap.Remove(key);
                            switch (command.leftHand)
                            {
                            case true:
                                waitor.leftHand.radialImg.gameObject.SetActive(false);
                                break;

                            default:
                                waitor.rightHand.radialImg.gameObject.SetActive(false);
                                break;
                            }
                        }
                        else
                        {
                            var   action = waitor.actionMap.GetByCommandString(key);
                            float perc   = Mathf.InverseLerp(action.startAction, action.endAction, Time.time);
                            switch (command.leftHand)
                            {
                            case true:
                                waitor.leftHand.radialImg.fillAmount = perc;
                                break;

                            default:
                                waitor.rightHand.radialImg.fillAmount = perc;
                                break;
                            }
                        }
                    }
                    break;

                case DulibaInputKeys.KeyPress.Up:
                    if (waitor.actionMap.Contains(key))
                    {
                        waitor.actionMap.Remove(key);
                        switch (command.leftHand)
                        {
                        case true:
                            waitor.leftHand.radialImg.gameObject.SetActive(false);
                            break;

                        default:
                            waitor.rightHand.radialImg.gameObject.SetActive(false);
                            break;
                        }
                    }
                    break;
                }
            }
        }
    }