Esempio n. 1
0
        public override TranslatorResult Translate(Section.SectionProperty INIProperty)
        {
            foreach ( OptionInterface item in _Options.Options )
            {
                if ( item.SaveKey.ToLower() != INIProperty.Name )
                {
                    continue;
                }
                if ( item is Option<KeyboardControl> )
                {
                    int unlessIndex = Convert.ToInt32(INIProperty.Value.ToLower().IndexOf("unless"));
                    string[] keysText = null;
                    string[] unlessKeysText = null;
                    if ( unlessIndex < 0 )
                    {
                        keysText = INIProperty.Value.Split(',');
                        unlessKeysText = new string[0];
                    }
                    else
                    {
                        keysText = INIProperty.Value.Substring(0, unlessIndex - 1).Split(',');
                        unlessKeysText = INIProperty.Value.Substring(unlessIndex + 6, INIProperty.Value.Length - (unlessIndex + 6)).Split(',');
                    }

                    Keys[] keys = new Keys[keysText.GetUpperBound(0) + 1];

                    bool valid = true;
                    for ( int j = 0; j <= keysText.GetUpperBound(0); j++ )
                    {
                        int number = 0;
                        if ( IOUtil.InvariantParse(keysText[j], ref number) )
                        {
                            keys[j] = (Keys)number;
                        }
                        else
                        {
                            valid = false;
                        }
                    }
                    Keys[] unlessKeys = new Keys[unlessKeysText.GetUpperBound(0) + 1];
                    for ( int j = 0; j <= unlessKeysText.GetUpperBound(0); j++ )
                    {
                        int number = 0;
                        if ( IOUtil.InvariantParse(unlessKeysText[j], ref number) )
                        {
                            unlessKeys[j] = (Keys)number;
                        }
                        else
                        {
                            valid = false;
                        }
                    }
                    if ( !valid )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    KeyboardControl control = new KeyboardControl(keys, unlessKeys);
                    if ( !item.IsValueValid(control) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<KeyboardControl>(control));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<SimpleList<string>> )
                {
                    SimpleList<string> list = default(SimpleList<string>);
                    if ( get_Changes(item) == null )
                    {
                        list = new SimpleList<string>();
                        set_Changes(item, new Change<SimpleList<string>>(list));
                    }
                    else
                    {
                        list = (SimpleList<string>)(get_Changes(item).ValueObject);
                    }
                    list.Add(INIProperty.Value);
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<FontFamily> )
                {
                    FontFamily fontFamily = default(FontFamily);
                    try
                    {
                        fontFamily = new FontFamily(Convert.ToString(INIProperty.Value));
                    }
                    catch
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(fontFamily) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<FontFamily>(fontFamily));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<clsRGB_sng> )
                {
                    clsRGB_sng value = new clsRGB_sng(0.0F, 0.0F, 0.0F);
                    if ( !value.ReadINIText(new SplitCommaText(Convert.ToString(INIProperty.Value))) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<clsRGB_sng>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<clsRGBA_sng> )
                {
                    clsRGBA_sng value = new clsRGBA_sng(0.0F, 0.0F, 0.0F, 0.0F);
                    if ( !value.ReadINIText(new SplitCommaText(Convert.ToString(INIProperty.Value))) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<clsRGBA_sng>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<bool> )
                {
                    bool value = default(bool);
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<bool>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<byte> )
                {
                    byte value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<byte>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<short> )
                {
                    short value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<short>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<int> )
                {
                    int value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<int>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<UInt32> )
                {
                    UInt32 value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<UInt32>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<Single> )
                {
                    float value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<Single>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<double> )
                {
                    double value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<double>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<string> )
                {
                    string value = Convert.ToString(INIProperty.Value);
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<string>(value));
                    return TranslatorResult.Translated;
                }
                else
                {
                    return TranslatorResult.ValueInvalid;
                }
            }

            return TranslatorResult.ValueInvalid;
        }
Esempio n. 2
0
        public void btnKeyControlChange_Click(Object sender, EventArgs e)
        {
            if ( lstKeyboardControls.SelectedIndex < 0 )
            {
                return;
            }

            frmKeyboardControl capture = new frmKeyboardControl();
            if ( capture.ShowDialog() != DialogResult.OK )
            {
                return;
            }
            if ( capture.Results.Count == 0 )
            {
                return;
            }
            Option<KeyboardControl> keyOption = lstKeyboardControls_Items[lstKeyboardControls.SelectedIndex];
            KeyboardControl previous = (KeyboardControl)(ChangedKeyControls.get_Value(keyOption));

            Keys[] keys = new Keys[capture.Results.Count];
            for ( int i = 0; i <= capture.Results.Count - 1; i++ )
            {
                keys[i] = capture.Results[i].Item;
            }
            KeyboardControl copy = new KeyboardControl(keys, previous.UnlessKeys);
            ChangedKeyControls.set_Changes(keyOption, new Change<KeyboardControl>(copy));
            UpdateKeyboardControl(keyOption.GroupLink.ArrayPosition);
        }
Esempio n. 3
0
 public static Option<KeyboardControl> KeyboardControlOptionCreate(string saveKey, KeyboardControl defaultValue)
 {
     var result = new Option<KeyboardControl>(saveKey, defaultValue);
     OptionsKeyboardControls.Options.Add(result.GroupLink);
     return result;
 }