Example #1
0
        /// <summary>
        /// Set up the default...defaults, for controls.
        /// </summary>
        public static void TagsSetDefaults(Control controls)
        {
            foreach (Control c in controls.Controls)
            {
                if (c.Tag is JsonFormTag)
                {
                    JsonFormTag tag = (JsonFormTag)c.Tag;

                    if (tag.def == null)
                    {
                        if (c is NumericUpDown)
                        {
                            tag.def = 0;
                        }
                        else if (c is CheckedListBox)
                        {
                            tag.def = new string[0];
                        }
                        else if (c is CheckBox)
                        {
                            tag.def = false;
                        }
                        else
                        {
                            tag.def = "";
                        }
                    }
                }
                if (c.Controls.Count > 0)
                {
                    TagsSetDefaults(c);
                }
            }
        }
Example #2
0
        public static void ListChanged(object sender, EventArgs e)
        {
            BindingList <GroupedData> list = (BindingList <GroupedData>)sender;
            JsonFormTag tag = listTags[list];

            if (!string.IsNullOrEmpty(tag.key))
            {
                ApplyList(tag.key, list, tag.mandatory);
            }
        }
Example #3
0
        private static void ControlSetValues(Control control, object item)
        {
            ControlsResetValues(control);

            Dictionary <string, object> itemValues = (Dictionary <string, object>)item;

            //TODO: displaymember?
            string id = "-null-";

            if (itemValues.ContainsKey("id"))
            {
                id = (string)itemValues["id"];
            }

            foreach (Control c in control.Controls)
            {
                if (c.Tag is JsonFormTag)
                {
                    JsonFormTag tag = (JsonFormTag)c.Tag;
                    if (!string.IsNullOrEmpty(tag.key))
                    {
                        if (c is NumericUpDown)
                        {
                            SetInt(itemValues, tag.key, (NumericUpDown)c, id, tag.mandatory);
                        }
                        else if (c is CheckedListBox)
                        {
                            SetChecks(itemValues, tag.key, (CheckedListBox)c, id, tag.mandatory);
                        }
                        else if (c is CheckBox)
                        {
                            SetCheckBox(itemValues, tag.key, (CheckBox)c, id, tag.mandatory);
                        }
                        else if (c is ListBox && tag.listBoxData != null)
                        {
                            SetList(itemValues, tag.key, (ListBox)c, tag.listBoxData.backingList, id, tag.mandatory);
                        }
                        else
                        {
                            SetString(itemValues, tag.key, c, id, tag.mandatory);
                        }
                    }
                }
                if (c.Controls.Count > 0)
                {
                    ControlSetValues(c, item);
                }
            }
        }
Example #4
0
 private static void ControlResetValues(Control control)
 {
     foreach (Control c in control.Controls)
     {
         if (c.Tag is JsonFormTag)
         {
             JsonFormTag tag = (JsonFormTag)c.Tag;
             if (c is NumericUpDown)
             {
                 if (tag.def != null)
                 {
                     ((NumericUpDown)c).Value = (int)tag.def;
                 }
                 else
                 {
                     ((NumericUpDown)c).Value = 0;
                 }
             }
             else if (c is CheckedListBox)
             {
                 ResetCheckedListBox((CheckedListBox)c);
             }
             else if (c is CheckBox)
             {
                 ((CheckBox)c).Checked = (bool)tag.def;
             }
             else if (tag.listBoxData != null)
             {
                 tag.listBoxData.backingList.Clear();
             }
             else if (!(c is Button))
             {
                 if (tag.def != null)
                 {
                     c.Text = (string)tag.def;
                 }
                 else
                 {
                     c.Text = "";
                 }
             }
         }
         if (c.Controls.Count > 0)
         {
             ControlResetValues(c);
         }
     }
 }
Example #5
0
        public static void ControlsLoadItem(Control control, object item)
        {
            ControlsResetValues(control);
            Resetting++;

            Dictionary <string, object> itemValues = (Dictionary <string, object>)item;

            string id = "-null-";

            if (itemValues.ContainsKey("id"))
            {
                id = (string)itemValues["id"];
            }

            foreach (Control c in control.Controls)
            {
                if (c.Tag is JsonFormTag)
                {
                    JsonFormTag tag = (JsonFormTag)c.Tag;
                    if (!string.IsNullOrEmpty(tag.key))
                    {
                        if (c is NumericUpDown)
                        {
                            SetInt(itemValues, tag.key, (NumericUpDown)c, id, tag.mandatory);
                        }
                        else if (c is CheckedListBox)
                        {
                            SetChecks(itemValues, tag.key, (CheckedListBox)c, id, tag.mandatory);
                        }
                        else if (c is CheckBox)
                        {
                            SetCheckBox(itemValues, tag.key, (CheckBox)c, id, tag.mandatory);
                        }
                        else
                        {
                            SetString(itemValues, tag.key, c, id, tag.mandatory);
                        }
                    }
                }
            }

            if (OnLoadItem != null)
            {
                OnLoadItem(item);
            }

            Resetting--;
        }
Example #6
0
 public static void ControlsResetValues(Control control)
 {
     Resetting++;
     if (OnReset != null)
     {
         OnReset();
     }
     foreach (Control c in control.Controls)
     {
         if (c.Tag is JsonFormTag)
         {
             JsonFormTag tag = (JsonFormTag)c.Tag;
             if (c is NumericUpDown)
             {
                 if (tag.def != null)
                 {
                     ((NumericUpDown)c).Value = (int)tag.def;
                 }
                 else
                 {
                     ((NumericUpDown)c).Value = 0;
                 }
             }
             else if (c is CheckedListBox)
             {
                 ResetCheckedListBox((CheckedListBox)c);
             }
             else if (c is CheckBox)
             {
                 ((CheckBox)c).Checked = (bool)tag.def;
             }
             else
             {
                 if (tag.def != null)
                 {
                     c.Text = (string)tag.def;
                 }
                 else
                 {
                     c.Text = "";
                 }
             }
         }
     }
     Resetting--;
 }
Example #7
0
 public static void UpdateDataSource(JsonFormTag.DataSourceType source, string newEntry)
 {
     if (source < JsonFormTag.DataSourceType.PRESET_MOD_COUNT)
     {
         if (!PresetDataSources[(int)source].Contains(newEntry))
         {
             PresetDataSources[(int)source].Add(newEntry);
             WinformsUtil.RefreshDataSources();
         }
     }
 }
Example #8
0
        public static string[] GetDataSource(JsonFormTag.DataSourceType source)
        {
            if (source < JsonFormTag.DataSourceType.PRESET_COUNT)
            {
                return PresetDataSources[(int)source].ToArray();
            }
            else
            {
                switch (source)
                {

                }
            }

            return null;
        }
Example #9
0
        public static string[] GetDataSource(JsonFormTag.DataSourceType source)
        {
            if (source < JsonFormTag.DataSourceType.PRESET_COUNT)
            {
                return PresetDataSources[(int)source].ToArray();
            }
            else
            {
                switch (source)
                {
                    case JsonFormTag.DataSourceType.TECHNIQUES:
                        return GetTechniques();
                    case JsonFormTag.DataSourceType.MATERIALS:
                        return GetMaterialNames();
                    case JsonFormTag.DataSourceType.SKILLS:
                        return GetSkills();
                    case JsonFormTag.DataSourceType.GUN_SKILLS:
                        return GetGunSkills();
                    case JsonFormTag.DataSourceType.CRAFT_CATEGORIES:
                        return GetCraftCategories();
                }
            }

            return null;
        }
Example #10
0
        public static void ControlsAttachHooks(Control control)
        {
            ControlsFillTags(control);

            foreach (Control c in control.Controls)
            {
                if (c.Tag is JsonFormTag)
                {
                    JsonFormTag tag = (JsonFormTag)c.Tag;

                    c.Enter += DisplayHelp;

                    //Handle data source hooks
                    switch (tag.dataSource)
                    {
                    case JsonFormTag.DataSourceType.ITEMS:
                        if (!(c is TextBox))
                        {
                            throw new InvalidCastException("Item Data Source is only allowed on TextBox controls.");
                        }
                        TextBox tb1 = (TextBox)c;
                        tb1.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
                        tb1.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                        tb1.AutoCompleteCustomSource = Storage.AutocompleteItemSource;
                        break;

                    case JsonFormTag.DataSourceType.BOOKS:
                        if (!(c is TextBox))
                        {
                            throw new InvalidCastException("Book Data Source is only allowed on TextBox controls.");
                        }
                        TextBox tb2 = (TextBox)c;
                        tb2.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
                        tb2.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                        tb2.AutoCompleteCustomSource = Storage.AutocompleteBookSource;
                        break;

                    case JsonFormTag.DataSourceType.NONE:

                        break;

                    default:
                        dataSourcedControls.Add(c);
                        break;
                    }

                    if (c is ComboBox)
                    {
                        ComboBox c1 = (ComboBox)c;
                        c1.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                        c1.AutoCompleteSource = AutoCompleteSource.ListItems;
                    }

                    if (c is NumericUpDown)
                    {
                        ((NumericUpDown)c).ValueChanged += NumericValueChanged;
                    }
                    else if (c is CheckedListBox)
                    {
                        ((CheckedListBox)c).ItemCheck += ChecksValueChanged;
                    }
                    else if (c is CheckBox)
                    {
                        ((CheckBox)c).CheckedChanged += CheckValueChanged;
                    }
                    else if (c is ListBox && tag.listBoxData != null)
                    {
                        //Set up data
                        ((ListBox)c).DataSource    = tag.listBoxData.backingList;
                        ((ListBox)c).DisplayMember = "Display";
                        listTags.Add(tag.listBoxData.backingList, tag);

                        tag.listBoxData.backingList.ListChanged += ListChanged;

                        //Attach other hooks
                        ((ListBox)c).SelectedIndexChanged      += ListSelectedIndexChanged;
                        tag.listBoxData.newButton.Click        += ListBoxNewClicked;
                        tag.listBoxData.deleteButton.Click     += ListBoxDeleteClicked;
                        tag.listBoxData.keyControl.TextChanged += ListBoxKeyChanged;
                        if (tag.listBoxData.valueControl != null)
                        {
                            tag.listBoxData.valueControl.ValueChanged += ListBoxValueChanged;
                        }

                        //Disable
                        tag.listBoxData.deleteButton.Enabled = false;
                        tag.listBoxData.keyControl.Enabled   = false;
                        if (tag.listBoxData.valueControl != null)
                        {
                            tag.listBoxData.valueControl.Enabled = false;
                        }
                    }
                    else
                    {
                        c.TextChanged += TextValueChanged;
                    }
                }
                if (c.Controls.Count > 0)
                {
                    ControlsAttachHooks(c);
                }
            }
        }