Ejemplo n.º 1
0
        // Returning `true` means it ran a custom menu update. `false` means the menu needs to be updated manually.
        public virtual bool CycleParam(string paramKey, bool up = true)
        {
            ArrayList tileObj = WandData.wandTileData;

            // Verify that the parameter can exist.
            if (tileObj == null)
            {
                return(false);
            }

            if (tileObj.Count <= 2)
            {
                tileObj.Add(new Dictionary <string, short>());
            }

            // Retrieve Rule
            ParamGroup paramRule = this.GetParamRule(paramKey);

            // Get Tile Data
            Dictionary <string, short> paramList = (Dictionary <string, short>)tileObj[2];

            // Retrieve the parameter value (or the default value if it's not set)
            short paramVal = paramList.ContainsKey(paramKey) ? paramList[paramKey] : paramRule.defValue;

            // Cycle an Integer Param
            if (paramRule is IntParam)
            {
                IntParam intRule  = (IntParam)paramRule;
                short    newValue = this.CycleNumber((short)paramVal, intRule.min, intRule.max, intRule.increment, up);
                this.UpdateParamNum(paramList, paramKey, newValue, intRule.defValue);
            }

            // Cycle a Percent Param
            else if (paramRule is PercentParam)
            {
                PercentParam perRule  = (PercentParam)paramRule;
                short        newValue = this.CycleNumber((short)paramVal, perRule.min, perRule.max, perRule.increment, up);
                this.UpdateParamNum(paramList, paramKey, newValue, perRule.defValue);
            }

            // Cycle a Labeled Param
            else if (paramRule is LabeledParam)
            {
                LabeledParam labelRule = (LabeledParam)paramRule;
                short        newValue  = this.CycleNumber((short)paramVal, 0, (short)(labelRule.labels.Length - 1), 1, up);
                this.UpdateParamNum(paramList, paramKey, newValue, labelRule.defValue);
            }

            else
            {
                return(false);
            }

            // Run Custom Cycle Updates for Advanced Params
            return(this.RunCustomMenuUpdate());
        }
Ejemplo n.º 2
0
        // Retrieve Param Value from Param List (the JSON for the specific param key)
        public static short GetParamVal(Params paramSet, string paramKey)
        {
            Dictionary <string, short> paramList = WandData.GetAllParamsOnTile();

            // Get the default value if the tile data does not have one saved:
            if (paramList == null || !paramList.ContainsKey(paramKey))
            {
                ParamGroup rule = paramSet.GetParamRule(paramKey);
                return(rule.defValue);
            }

            return((short)paramList[paramKey]);
        }
Ejemplo n.º 3
0
        // Update Menu Options (run when menu changes)
        public void UpdateMenuOptions(byte numOptsToShow = 0, byte[] optRuleIds = null)
        {
            if (!this.visible)
            {
                return;
            }

            Dictionary <string, short> paramList = WandData.GetAllParamsOnTile();

            // Get Rules
            List <ParamGroup> rules = this.paramSet.rules;

            // Prepare Menu Options
            this.numberOptsToShow = (numOptsToShow == 0 ? (byte)rules.Count : numOptsToShow);

            // Determine the Rule IDs that appear in the Option List. The default is just to list each rule in order.
            // Some wand menus (such as Flight and Chest) will have different sequences that must be sent to this method.
            // The reason for this is because there are certain rules that will affect others. Such as Flight Type of Rotation making the rotating diameter value visible.
            for (byte i = 0; i < this.numberOptsToShow; i++)
            {
                this.menuOptRuleIds[i] = optRuleIds == null ? i : optRuleIds[i];
            }

            // Loop through each rule:
            for (byte i = 0; i < this.numberOptsToShow; i++)
            {
                byte       ruleId = this.menuOptRuleIds[i];
                ParamGroup rule   = rules[ruleId];

                this.menuOptLabels[i] = rule.name;

                // Determine the Text
                if (paramList != null && paramList.ContainsKey(rule.key))
                {
                    // Labeled Params
                    if (rule is LabeledParam)
                    {
                        byte paramVal = byte.Parse(paramList[rule.key].ToString());
                        if (((LabeledParam)rule).labels.Length > paramVal)
                        {
                            this.menuOptText[i] = ((LabeledParam)rule).labels[paramVal];
                        }
                    }

                    // Dictionary Params
                    else if (rule is DictParam)
                    {
                        DictParam dictRule    = (DictParam)(rule);
                        byte[]    contentKeys = dictRule.dict.Keys.ToArray <byte>();
                        byte      paramVal    = byte.Parse(paramList[rule.key].ToString());
                        this.menuOptText[i] = dictRule.dict[contentKeys[paramVal]];
                    }

                    // Frame Params (show them as milliseconds, rather than by frames)
                    else if (rule is FrameParam)
                    {
                        int newVal = short.Parse(paramList[rule.key].ToString()) * 1000 / 60;
                        this.menuOptText[i] = newVal.ToString() + " ms";
                    }

                    // Default Numeric Params
                    else
                    {
                        this.menuOptText[i] = paramList[rule.key].ToString() + rule.unitName;
                    }
                }

                // Display Default String
                else
                {
                    // Default Rule for Frame Params is still altered.
                    if (rule is FrameParam)
                    {
                        this.menuOptText[i] = (rule.defValue * 1000 / 60).ToString() + " ms";
                    }
                    else
                    {
                        this.menuOptText[i] = rule.defStr;
                    }
                }

                // Resize Menu after any update.
                this.ResizeMenu(false);
            }
        }