Exemplo n.º 1
0
        public string GetValue(bool strict)
        {
            string value = null;

            switch (Type)
            {
            case UIControlType.TextLabel:
                if (strict)
                {
                    value = Text;
                }
                break;

            case UIControlType.TextBox:
            {
                UIInfo_TextBox info = Info.Cast <UIInfo_TextBox>();
                value = info.Value;
            }
            break;

            case UIControlType.NumberBox:
            {
                UIInfo_NumberBox info = Info.Cast <UIInfo_NumberBox>();
                value = info.Value.ToString();
            }
            break;

            case UIControlType.CheckBox:
            {
                UIInfo_CheckBox info = Info.Cast <UIInfo_CheckBox>();
                value = info.Value ? "True" : "False";
            }
            break;

            case UIControlType.ComboBox:
                value = Text;
                break;

            case UIControlType.RadioButton:
            {
                UIInfo_RadioButton info = Info.Cast <UIInfo_RadioButton>();
                value = info.Selected ? "True" : "False";
            }
            break;

            case UIControlType.FileBox:
                value = Text;
                break;

            case UIControlType.RadioGroup:
            {
                UIInfo_RadioGroup info = Info.Cast <UIInfo_RadioGroup>();
                value = info.Selected.ToString();
            }
            break;
            }

            return(value);
        }
Exemplo n.º 2
0
        public static string GetUIControlTemplate(UIControlType type, string key)
        {
            switch (type)
            {
            case UIControlType.TextBox:
                return(UIInfo_TextBox.Template(key));

            case UIControlType.TextLabel:
                return(UIInfo_TextLabel.Template(key));

            case UIControlType.NumberBox:
                return(UIInfo_NumberBox.Template(key));

            case UIControlType.CheckBox:
                return(UIInfo_CheckBox.Template(key));

            case UIControlType.ComboBox:
                return(UIInfo_ComboBox.Template(key));

            case UIControlType.Image:
                return(UIInfo_Image.Template(key));

            case UIControlType.TextFile:
                return(UIInfo_TextFile.Template(key));

            case UIControlType.Button:
                return(UIInfo_Button.Template(key));

            case UIControlType.WebLabel:
                return(UIInfo_WebLabel.Template(key));

            case UIControlType.RadioButton:
                return(UIInfo_RadioButton.Template(key));

            case UIControlType.Bevel:
                return(UIInfo_Bevel.Template(key));

            case UIControlType.FileBox:
                return(UIInfo_FileBox.Template(key));

            case UIControlType.RadioGroup:
                return(UIInfo_RadioGroup.Template(key));

            default:
                throw new InvalidOperationException("Internal Logic Error at UIControl.GetUIControlTemplate");
            }
        }
Exemplo n.º 3
0
        public bool SetValue(string newValue, bool update, out List <LogInfo> logs)
        {
            logs = new List <LogInfo>(1);
            bool success = false;

            switch (Type)
            {
            case UIControlType.TextLabel:
                // Text
                Text = StringEscaper.Escape(newValue);

                logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [{newValue}]"));
                success = true;
                break;

            case UIControlType.TextBox:
            {         // Value
                UIInfo_TextBox uiInfo = Info.Cast <UIInfo_TextBox>();
                uiInfo.Value = StringEscaper.Escape(newValue);

                logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [{newValue}]"));
                success = true;
            }
            break;

            case UIControlType.NumberBox:
            {         // Value
                UIInfo_NumberBox uiInfo = Info.Cast <UIInfo_NumberBox>();

                // WB082 just write string value in case of error, but PEBakery will throw error
                if (!NumberHelper.ParseInt32(newValue, out int intVal))
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{newValue}] is not a valid integer"));
                    return(false);
                }

                if (uiInfo.Min <= intVal && intVal <= uiInfo.Max)
                {
                    uiInfo.Value = intVal;
                }
                else
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{newValue}] should be inside of [{uiInfo.Min}] ~ [{uiInfo.Max}]"));
                    return(false);
                }

                logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [{newValue}]"));
                success = true;
            }
            break;

            case UIControlType.CheckBox:
            {         // Value
                UIInfo_CheckBox uiInfo = Info.Cast <UIInfo_CheckBox>();

                if (newValue.Equals("True", StringComparison.OrdinalIgnoreCase))
                {
                    uiInfo.Value = true;

                    logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [True]"));
                    success = true;
                }
                else if (newValue.Equals("False", StringComparison.OrdinalIgnoreCase))
                {
                    uiInfo.Value = false;

                    logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [False]"));
                    success = true;
                }
                else
                {         // WB082 just write string value in case of error, but PEBakery will throw error
                    logs.Add(new LogInfo(LogState.Error, $"[{newValue}] is not a valid boolean value"));
                    return(false);
                }
            }
            break;

            case UIControlType.ComboBox:
            {         // Text
                UIInfo_ComboBox uiInfo = Info.Cast <UIInfo_ComboBox>();

                int idx = uiInfo.Items.FindIndex(x => newValue.Equals(StringEscaper.Unescape(x), StringComparison.OrdinalIgnoreCase));
                if (idx == -1)
                {         // Invalid index
                    logs.Add(new LogInfo(LogState.Error, $"[{newValue}] was not found in the item list"));
                    return(false);
                }

                uiInfo.Index = idx;
                Text         = uiInfo.Items[idx];

                logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [{Text}]"));
                success = true;
            }
            break;

            case UIControlType.RadioButton:
            {
                UIInfo_RadioButton uiInfo = Info.Cast <UIInfo_RadioButton>();

                if (newValue.Equals("True", StringComparison.OrdinalIgnoreCase))
                {
                    uiInfo.Selected = true;

                    logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [True]"));
                    success = true;
                }
                else if (newValue.Equals("False", StringComparison.OrdinalIgnoreCase))
                {
                    uiInfo.Selected = false;

                    logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [False]"));
                    success = true;
                }
                else
                {         // WB082 just write string value, but PEBakery will throw error
                    logs.Add(new LogInfo(LogState.Error, $"[{newValue}] is not a valid boolean value"));
                    return(false);
                }
            }
            break;

            case UIControlType.FileBox:
                Text = StringEscaper.Escape(newValue);

                logs.Add(new LogInfo(LogState.Success, $"Interface Control [{Key}] set to [{newValue}]"));
                success = true;
                break;

            case UIControlType.RadioGroup:
            {
                UIInfo_RadioGroup uiInfo = Info.Cast <UIInfo_RadioGroup>();

                if (!NumberHelper.ParseInt32(newValue, out int idx))
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{newValue}] is not a valid integer"));
                    return(false);
                }

                if (0 <= idx && idx < uiInfo.Items.Count)
                {
                    uiInfo.Selected = idx;
                }
                else
                {         // Invalid Index
                    logs.Add(new LogInfo(LogState.Error, $"Index [{newValue}] is invalid"));
                    return(false);
                }

                logs.Add(new LogInfo(LogState.Success, $"Interface control [{Key}] set to [{newValue}]"));
                success = true;
            }
            break;
            }

            if (success && update)
            {
                Update();
            }

            return(success);
        }
Exemplo n.º 4
0
        public string GetValue()
        {
            string value = null;

            switch (Type)
            {
            case UIType.TextBox:
            {
                Debug.Assert(Info.GetType() == typeof(UIInfo_TextBox));
                UIInfo_TextBox info = Info as UIInfo_TextBox;

                value = info.Value;
            }
            break;

            case UIType.NumberBox:
            {
                Debug.Assert(Info.GetType() == typeof(UIInfo_NumberBox));
                UIInfo_NumberBox info = Info as UIInfo_NumberBox;

                value = info.Value.ToString();
            }
            break;

            case UIType.CheckBox:
            {
                Debug.Assert(Info.GetType() == typeof(UIInfo_CheckBox));
                UIInfo_CheckBox info = Info as UIInfo_CheckBox;

                value = info.Value ? "True" : "False";
            }
            break;

            case UIType.ComboBox:
            {
                value = Text;
            }
            break;

            case UIType.RadioButton:
            {
                Debug.Assert(Info.GetType() == typeof(UIInfo_RadioButton));
                UIInfo_RadioButton info = Info as UIInfo_RadioButton;

                value = info.Selected ? "True" : "False";
            }
            break;

            case UIType.FileBox:
            {
                value = Text;
            }
            break;

            case UIType.RadioGroup:
            {
                Debug.Assert(Info.GetType() == typeof(UIInfo_RadioGroup));
                UIInfo_RadioGroup info = Info as UIInfo_RadioGroup;

                value = info.Selected.ToString();
            }
            break;
            }

            return(value);
        }