// returns current value public string getValue(string key) { DefinitionDataType keyType = Database.attributeDefinitions[key].DataType; if (values.ContainsKey(key)) { return(values[key]); } else { // default value if (keyType == DefinitionDataType.Sprite) { //if no sprite set yet, then set as first one on list :) string defVal = Database.attributeDefinitions[key].DefaultValue; if (defVal.Length > 0 && Database.GMXspritesFiltered.Contains(defVal)) { return(defVal); } return(Database.GMXspritesFiltered[0]); } else { return(Database.attributeDefinitions[key].DefaultValue); } } }
// if dropdown will return value label instead real value public string getValueLabel(string key) { if (Database.attributeDefinitions[key].GroupLink > -1) { DefinitionDataType keyType = Database.attributeDefinitions[key].DataType; switch (keyType) { case DefinitionDataType.Bool: case DefinitionDataType.Int: if (values.ContainsKey(key)) { int val = 0; int.TryParse(values[key], out val); return(Database.groupDefinitions.ElementAt(Database.attributeDefinitions[key].GroupLink).Value[val]); } else { return(Database.attributeDefinitions[key].DefaultValue); } } // for others value is actually proper label... } return(getValue(key)); }
public static KeyValuePair <string, DefinitionDataType> ShowDialog(string Caption, string AttrName, DefinitionDataType AttrType) { DefinitionDataType type; Form prompt = new Form(); prompt.Width = 350; prompt.Height = 107; prompt.Text = Caption; prompt.FormBorderStyle = FormBorderStyle.FixedToolWindow; prompt.StartPosition = FormStartPosition.CenterParent; prompt.ControlBox = false; prompt.ShowInTaskbar = false; Label textLabel = new Label() { Left = 12, Top = 9, Height = 13, Text = "Attribute data:" }; TextBox textBox = new TextBox() { Left = 12, Top = 25, Text = AttrName, Width = 150 }; ComboBox dropDown = new ComboBox() { Left = 182, Top = 25, Width = 150, DropDownStyle = ComboBoxStyle.DropDownList }; Button confirmation = new Button() { Text = "OK", Left = 276, Width = 56, Top = 50, DialogResult = DialogResult.OK }; confirmation.Font = new Font(confirmation.Font, FontStyle.Bold); confirmation.Image = new Bitmap(ItemPacker2013.Properties.Resources.tick); confirmation.TextImageRelation = TextImageRelation.ImageBeforeText; confirmation.TextAlign = ContentAlignment.MiddleRight; Button cancel = new Button { Text = "Cancel", Left = 190, Width = 75, Top = 50, DialogResult = DialogResult.Cancel }; cancel.Image = new Bitmap(ItemPacker2013.Properties.Resources.cross); cancel.TextImageRelation = TextImageRelation.ImageBeforeText; cancel.TextAlign = ContentAlignment.MiddleRight; foreach (DefinitionDataType definition in Enum.GetValues(typeof(DefinitionDataType))) { dropDown.Items.Add(definition.ToString()); if (AttrType == definition) { dropDown.SelectedIndex = dropDown.Items.Count - 1; } } confirmation.Click += (sender, e) => { prompt.Close(); }; cancel.Click += (sender, e) => { textBox.Text = ""; }; prompt.Controls.Add(textLabel); prompt.Controls.Add(textBox); prompt.Controls.Add(dropDown); prompt.Controls.Add(confirmation); prompt.Controls.Add(cancel); prompt.ShowDialog(); if (!Enum.TryParse(dropDown.Text, true, out type)) { type = DefinitionDataType.String; } return(new KeyValuePair <string, DefinitionDataType>(textBox.Text, type)); }