Exemple #1
0
        public ColourControl(clsRGB_sng NewColour)
        {
            InitializeComponent();

            if ( NewColour == null )
            {
                Debugger.Break();
                Hide();
                return;
            }

            Colour = NewColour;
            int Red = (int)(MathUtil.Clamp_dbl(Colour.Red * 255.0D, 0.0D, 255.0D));
            int Green = (int)(MathUtil.Clamp_dbl(Colour.Green * 255.0D, 0.0D, 255.0D));
            int Blue = (int)(MathUtil.Clamp_dbl(Colour.Blue * 255.0D, 0.0D, 255.0D));
            ColourColor = ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue));

            if ( Colour is clsRGBA_sng )
            {
                nudAlpha.Value = (decimal)(((clsRGBA_sng)Colour).Alpha);
                nudAlpha.ValueChanged += nudAlpha_Changed;
                nudAlpha.Leave += nudAlpha_Changed;
            }
            else
            {
                nudAlpha.Hide();
            }

            ColourBoxGraphics = pnlColour.CreateGraphics();

            ColourBoxRedraw();
        }
Exemple #2
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;
        }