public Boolean enableField(DataBinding dataBinding, DataRow dataRow, Boolean enabled)
        {
            switch ((Net7.Table_item_base)dataBinding.enumeration)
            {
            case Net7.Table_item_base._item_base_id:
            {
                Boolean customItem = dataRow != null &&
                                     ColumnData.GetBoolean(dataRow, Net7.Table_item_base._custom_flag);
                if (customItem == false && enabled == true)
                {
                    enabled = false;
                }
                dataBinding.control.Enabled = enabled;
                return(true);
            }

            case Net7.Table_item_base._category:
            {
                if (enabled == true)
                {
                    if (m_gui.getCurrentEditor().getTableHandlers()[0].getTableIO().getState().Equals(TableIO.State.Add))
                    {
                        // Always enable in Add mode
                    }
                    else
                    {
                        Int32 code = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                        Items.ItemCategory category = (Items.ItemCategory)code;
                        enabled = Items.isComponent(category);
                    }
                }
            }
                dataBinding.control.Enabled = enabled;
                return(true);

            case Net7.Table_item_base._sub_category:
            {
                if (enabled == true)
                {
                    if (m_gui.getCurrentEditor().getTableHandlers()[0].getTableIO().getState().Equals(TableIO.State.Add))
                    {
                        // Always enable in Add mode
                    }
                    else
                    {
                        Int32 code = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                        Items.ItemSubCategory subCategory  = (Items.ItemSubCategory)code;
                        TabPage[]             listTabPages = getTabPages(subCategory);
                        enabled = listTabPages.Length == 1;
                    }
                }
            }
                dataBinding.control.Enabled = enabled;
                return(true);
            } // switch

            return(false);
        }
 public TabPage[] getTabPages(Items.ItemCategory category)
 {
     TabPage[] listTabPages;
     if (m_categoryTabPages.TryGetValue(category, out listTabPages))
     {
         return(listTabPages);
     }
     return(null);
 }
Esempio n. 3
0
        private void AddCategory(Items.ItemCategory Cat)
        {
            //cboCategory.Items.Add(Utility.FormParen((int)Cat, 2) + " " + Items.CategoryLookup(Cat));
            CodeValue codeValue = new CodeValue();

            codeValue.code  = (Int32)Cat;
            codeValue.value = Cat.ToString() + " (" + (Int32)Cat + ")";
            cboCategory.Items.Add(codeValue);
        }
        public void onCategorySelectionChanged(object sender, EventArgs e)
        {
            ComboBox  categoryCbo = (ComboBox)sender;
            CodeValue codeValue   = (CodeValue)categoryCbo.SelectedItem;

            // Still in view mode since the change has not yet propagated
            if (m_gui.getCurrentEditor().getTableHandlers()[0].getTableIO().getState().Equals(TableIO.State.View))
            {
                // We are editing.  If the category is enabled then we can only select a component
                Items.ItemCategory category = (Items.ItemCategory)codeValue.code;
                if (!Items.isComponent(category))
                {
                    MessageBox.Show("The category must remain a component");
                    codeValue = new CodeValue((int)Items.ItemCategory.Invalid);
                    categoryCbo.SelectedItem = codeValue;
                    return;
                }
            }


            CodeValue[] listSubCategory = Database.getItemSubCategories(codeValue.code);
            m_subCategoryControl.Items.Clear();
            if (listSubCategory != null && listSubCategory.Length != 0)
            {
                m_subCategoryControl.Items.AddRange(listSubCategory);
                m_subCategoryControl.SelectedItem = listSubCategory.GetValue(0);
                onSubCategorySelectionChanged(null, null); // Hack: Force a selection change event
            }
            else
            {
                m_subCategoryControl.Text = "";
            }

            Items.ItemCategory itemCategory = (Items.ItemCategory)codeValue.code;
            TabPage[]          tabPages     = getTabPages(itemCategory);
            if (tabPages != null)
            {
                m_gui.setTabPages(tabPages);
                // Rely on the child tables (i.e. Beams) to activate the restrictions when needed
                Restrictions.enableField(false);
                //m_gui.setEditor(Items.getEditorType(itemCategory), false);
                categoryCbo.Focus();
            }
        }
        public void onSubCategorySelectionChanged(object sender, EventArgs e)
        {
            CodeValue codeValue = (CodeValue)m_categoryControl.SelectedItem;

            Items.ItemCategory itemCategory = (Items.ItemCategory)codeValue.code;

            codeValue = (CodeValue)m_subCategoryControl.SelectedItem;
            Items.ItemSubCategory itemSubCategory = (Items.ItemSubCategory)codeValue.code;

            TabPage[] tabPages = getTabPages(itemSubCategory);
            if (tabPages != null)
            {
                m_gui.setTabPages(tabPages);
                // Rely on the child tables (i.e. Beams) to activate the restrictions when needed
                Restrictions.enableField(false);
                m_gui.setEditor(Items.getEditorType(itemSubCategory), false);
                m_subCategoryControl.Focus();
            }

            selectType(itemCategory, itemSubCategory);
        }
        public void selectType(Items.ItemCategory itemCategory, Items.ItemSubCategory itemSubCategory)
        {
            Net7.Enum_item_type type = Net7.Enum_item_type._Base;
            if (itemSubCategory.Equals(Items.ItemSubCategory.Ammo))
            {
                type = Net7.Enum_item_type._Ammo;
            }
            else if (itemSubCategory.Equals(Items.ItemSubCategory.Beam_Weapon))
            {
                type = Net7.Enum_item_type._Beam_Weapon;
            }
            else if (itemSubCategory.Equals(Items.ItemSubCategory.Missile_Launcher))
            {
                type = Net7.Enum_item_type._Missile_Launcher;
            }
            else if (itemSubCategory.Equals(Items.ItemSubCategory.Projectile_Launcher))
            {
                type = Net7.Enum_item_type._Projectile_Weapon;
            }
            else if (itemSubCategory.Equals(Items.ItemSubCategory.Engine))
            {
                type = Net7.Enum_item_type._Engine;
            }
            else if (itemSubCategory.Equals(Items.ItemSubCategory.Reactor))
            {
                type = Net7.Enum_item_type._Reactor;
            }
            else if (itemSubCategory.Equals(Items.ItemSubCategory.Shield))
            {
                type = Net7.Enum_item_type._Shields;
            }
            else if (itemCategory.Equals(Items.ItemCategory.Device))
            {
                type = Net7.Enum_item_type._Devices;
            }

            m_typeControl.SelectedItem = new CodeValue((int)type);
        }
        public Boolean displayField(DataBinding dataBinding, DataRow dataRow)
        {
            if (dataBinding.enumeration.Equals(Net7.Table_item_base._id))
            {
                String code = (dataRow == null) ? "" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                m_baseManufacturingBtn.ForeColor = (code.Length == 0 || Database.hasManufacturing(code)) ? Color.Black : Color.Red;
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._category))
            {
                // Show the relevant tab pages given the category
                Int32 code = (dataRow == null) ? 50 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                Items.ItemCategory category = (Items.ItemCategory)code;
                TabPage[]          listTabPages;
                if (m_categoryTabPages.TryGetValue(category, out listTabPages))
                {
                    m_gui.setTabPages(listTabPages);
                }
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._sub_category))
            {
                // Show the relevant tab pages given the sub-category
                Int32 code = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                Items.ItemSubCategory subCategory = (Items.ItemSubCategory)code;
                TabPage[]             listTabPages;
                if (m_subCategoryTabPages.TryGetValue(subCategory, out listTabPages))
                {
                    m_gui.setTabPages(listTabPages);
                }
                else if (m_subCategoryTabPages.TryGetValue(Items.ItemSubCategory.Other, out listTabPages))
                {
                    // Assume that the sub-category refers to a component
                    m_gui.setTabPages(listTabPages);
                }
                Int32       category        = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, Net7.Table_item_base._category);
                CodeValue[] listSubCategory = Database.getItemSubCategories((int)category);
                ComboBox    subCategories   = (ComboBox)dataBinding.control;
                subCategories.Items.Clear();
                subCategories.Items.AddRange(listSubCategory);

                // Rely on the child tables (i.e. Devices, Beams, Missile/Projectile Launcher)
                // to activate the restrictions when needed
                Restrictions.displayField(null, null, null);
                Restrictions.enableField(false);

                Int32 subCategoryId = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                m_gui.setEditor(Items.getEditorType(subCategory), false);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._description))
            {
                // Convert from E&B style
                String description = (dataRow == null) ? "" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                dataBinding.control.Text = Utility.ParseDescription(description);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._custom_flag))
            {
                ((CheckBox)dataBinding.control).Checked = (dataRow == null) ? false : ColumnData.GetBoolean(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._2d_asset))
            {
                dataBinding.control.Text = (dataRow == null) ? "744" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._max_stack))
            {
                dataBinding.control.Text = (dataRow == null) ? "1" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._3d_asset))
            {
                dataBinding.control.Text = (dataRow == null) ? "69" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._price))
            {
                dataBinding.control.Text = (dataRow == null) ? "0" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            return(false);
        }
 public void setTabPages(Items.ItemCategory category, TabPage[] listTabPages)
 {
     m_categoryTabPages.Add(category, listTabPages);
 }