/// <summary> /// Adds a Struct (a Variable structure) to the "VarTable" List. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void contextclick_AddVariable(object sender, EventArgs e) { using (var dialog = new VariableDialog()) { if (dialog.ShowDialog(this) == DialogResult.OK) { BeginUpdate(); TreeNode top = TopNode; var field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = SelectedNode.Nodes.Count.ToString(); // Structs in Lists do not have a Label field.Struct = new Struct(); field.Struct.typeid = 0; // <- that's what's in the UTCs I've looked at. string text = GeneralGFF.ConstructNodetext(field); var node = new Sortable(text, field.label); node.Tag = field; int id = SelectedNode.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.CExoString; field.label = "Name"; field.CExoString = _varLabel; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.DWORD; field.label = "Type"; field.DWORD = _varType; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.label = "Value"; switch (_varType) // TODO: delete the nodes above or put this above there { case VariableDialog.Type_non: // not stable in toolset. is Disabled in the dialog return; case VariableDialog.Type_INT: field.type = FieldTypes.INT; field.INT = Int32.Parse(_varValue); break; case VariableDialog.Type_FLOAT: field.type = FieldTypes.FLOAT; field.FLOAT = Single.Parse(_varValue); break; case VariableDialog.Type_STRING: field.type = FieldTypes.CExoString; field.CExoString = _varValue; break; case VariableDialog.Type_LOCATION: // not stable in toolset. is Disabled in the dialog return; case VariableDialog.Type_UINT: // and I can't see this being useful at all. field.type = FieldTypes.DWORD; field.DWORD = UInt32.Parse(_varValue); break; } text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); SelectedNode = SelectedNode.Nodes[id]; SelectedNode.Expand(); TopNode = top; _f.GffData.Changed = true; _f.GffData = _f.GffData; EndUpdate(); node.EnsureVisible(); // yes those calls are in a specific sequence. } } }
/// <summary> /// Adds a Struct (an InventoryItem structure) to the "ItemList" List. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void contextclick_AddInventoryItem(object sender, EventArgs e) { BeginUpdate(); TreeNode top = TopNode; int id = SelectedNode.Nodes.Count; var field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = id.ToString(); // Structs in Lists do not have a Label field.Struct = new Struct(); field.Struct.typeid = (uint)id; // <- that's what's in the UTCs I've looked at. string text = GeneralGFF.ConstructNodetext(field); var node = new Sortable(text, field.label); node.Tag = field; id = SelectedNode.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.label = "Dropable"; field.BYTE = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.CResRef; field.label = "EquippedRes"; field.CResRef = String.Empty; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.label = "Pickpocketable"; field.BYTE = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.WORD; field.label = "Repos_PosX"; field.WORD = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.WORD; field.label = "Repos_PosY"; field.WORD = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); SelectedNode = SelectedNode.Nodes[id]; SelectedNode.Expand(); TopNode = top; _f.GffData.Changed = true; _f.GffData = _f.GffData; EndUpdate(); node.EnsureVisible(); // yes those calls are in a specific sequence. }
/// <summary> /// Adds a Struct (an EquippedItem structure) to the "Equip_ItemList" List. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void contextclick_AddEquippedItem(object sender, EventArgs e) { GffData.Field field; _bitslot = 0; for (int i = 0; i != SelectedNode.Nodes.Count; ++i) { field = (GffData.Field)SelectedNode.Nodes[i].Tag; _bitslot |= field.Struct.typeid; } using (var f = new EquippedItemDialog(_bitslot)) { _bitslot = 0; if (f.ShowDialog(this) == DialogResult.OK) { BeginUpdate(); TreeNode top = TopNode; field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = SelectedNode.Nodes.Count.ToString(); // Structs in Lists do not have a Label field.Struct = new Struct(); field.Struct.typeid = _bitslot; // <- that's what's in the UTCs I've looked at. string text = GeneralGFF.ConstructNodetext(field); var node = new Sortable(text, field.label); node.Tag = field; int id = SelectedNode.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.label = "Dropable"; field.BYTE = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.CResRef; field.label = "EquippedRes"; field.CResRef = String.Empty; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.label = "Pickpocketable"; field.BYTE = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.WORD; field.label = "Repos_PosX"; field.WORD = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.WORD; field.label = "Repos_PosY"; field.WORD = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); // keep the List's nodes in the correct sequence -> // they are arranged by Struct.typeid ascending int i; // iterator for the sortables int j; // tracker for the node # added // store all the sortable Structs in the List -> // NOTE: This is not an ideal routine. Because it adds all // the nodes to the tree, then removes them, then adds them // all again. It should, rather, just construct the Struct // and its fields, then add the Struct to the tree. var sortables = new List <Sortable>(); for (i = 0; i != SelectedNode.Nodes.Count; ++i) { sortables.Add((Sortable)SelectedNode.Nodes[i]); } SelectedNode.Nodes.Clear(); // NOTE: 'SelectedNode' is the "Equip_ItemList" list-field. // re-add the sortables before the added sortable -> i = j = 0; while (i != sortables.Count) { field = (GffData.Field)sortables[i].Tag; if (field.Struct.typeid < _bitslot) { // NOTE: 'field.label' doesn't need to be changed here sortables[i].Text = GeneralGFF.ConstructNodetextEquipped(field); SelectedNode.Nodes.Add(sortables[i]); j = i; } ++i; } id = ++j; // re-add the last sortable into the sequence -> // replace vals that were set above for the Struct's label and its Sortable's text and label field = (GffData.Field)sortables[sortables.Count - 1].Tag; field.label = sortables[sortables.Count - 1]._label = j.ToString(); sortables[sortables.Count - 1].Text = GeneralGFF.ConstructNodetextEquipped(field); SelectedNode.Nodes.Add(sortables[sortables.Count - 1]); // re-add the sortables that go after the added sortable -> i = 0; while (i != sortables.Count) { field = (GffData.Field)sortables[i].Tag; if (field.Struct.typeid > _bitslot) { field.label = sortables[i]._label = (++j).ToString(); sortables[i].Text = GeneralGFF.ConstructNodetextEquipped(field); SelectedNode.Nodes.Add(sortables[i]); } ++i; } SelectedNode = SelectedNode.Nodes[id]; SelectedNode.Expand(); TopNode = top; _f.GffData.Changed = true; _f.GffData = _f.GffData; EndUpdate(); node.EnsureVisible(); // yes those calls are in a specific sequence. } } }
/// <summary> /// Adds a Struct (a Class structure) to the "ClassList" List. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void contextclick_AddClass(object sender, EventArgs e) { BeginUpdate(); TreeNode top = TopNode; var field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = SelectedNode.Nodes.Count.ToString(); // Structs in Lists do not have a Label field.Struct = new Struct(); field.Struct.typeid = 2; // <- that's what's in the UTCs I've looked at. string text = GeneralGFF.ConstructNodetext(field); var node = new Sortable(text, field.label); node.Tag = field; int id = SelectedNode.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.INT; field.label = "Class"; field.INT = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.SHORT; field.label = "ClassLevel"; field.SHORT = 1; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); for (int i = 0; i != 10; ++i) { field = new GffData.Field(); field.type = FieldTypes.List; field.label = LABEL_PREFIX_KNOWN + i; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); } for (int i = 0; i != 10; ++i) { field = new GffData.Field(); field.type = FieldTypes.List; field.label = LABEL_PREFIX_MEMORIZED + i; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); } SelectedNode = SelectedNode.Nodes[id]; SelectedNode.Expand(); TopNode = top; _f.GffData.Changed = true; _f.GffData = _f.GffData; EndUpdate(); node.EnsureVisible(); // yes those calls are in a specific sequence. }
/// <summary> /// Adds an apparel-type. /// </summary> void AddApparel(string label) { BeginUpdate(); TreeNode top = TopNode; var field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = label; field.Struct = new Struct(); field.Struct.typeid = 0; // <- that's what's in the UTCs I've looked at. string text = GeneralGFF.ConstructNodetext(field); var node = new Sortable(text, field.label); node.Tag = field; int id = SelectedNode.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = "ArmorTint"; field.Struct = new Struct(); field.Struct.typeid = 0; // <- that's what's in the UTCs I've looked at. text = GeneralGFF.ConstructNodetext(field); var tint = new Sortable(text, field.label); tint.Tag = field; SelectedNode.Nodes[id].Nodes.Add(tint); AddTints(tint); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.BYTE = 0; field.label = "ArmorVisualType"; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.BYTE = 0; field.label = "Variation"; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); SelectedNode = SelectedNode.Nodes[id]; SelectedNode.Expand(); TopNode = top; _f.GffData.Changed = true; _f.GffData = _f.GffData; EndUpdate(); node.EnsureVisible(); // yes those calls are in a specific sequence. }
/// <summary> /// Adds a Struct (a Spell structure) to either a "KnownList*" or a /// "MemorizedList*" List (in the "ClassList"). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void contextclick_AddSpell(object sender, EventArgs e) { BeginUpdate(); TreeNode top = TopNode; var field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = SelectedNode.Nodes.Count.ToString(); // Structs in Lists do not have a Label field.Struct = new Struct(); field.Struct.typeid = 3; // <- that's what's in the UTCs I've looked at. string text = GeneralGFF.ConstructNodetext(field); var node = new Sortable(text, field.label); node.Tag = field; int id = SelectedNode.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.WORD; field.label = "Spell"; field.WORD = 0; // default spell-id #0 text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.label = "SpellFlags"; field.BYTE = 1; // what is that text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.BYTE; field.label = "SpellMetaMagic"; field.BYTE = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); SelectedNode = SelectedNode.Nodes[id]; SelectedNode.Expand(); TopNode = top; _f.GffData.Changed = true; _f.GffData = _f.GffData; EndUpdate(); node.EnsureVisible(); // yes those calls are in a specific sequence. }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void contextclick_AddDamageReduction(object sender, EventArgs e) { BeginUpdate(); TreeNode top = TopNode; var field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = SelectedNode.Nodes.Count.ToString(); // Structs in Lists do not have a Label field.Struct = new Struct(); field.Struct.typeid = 2; // <- that's what's in the UTCs I've looked at. string text = GeneralGFF.ConstructNodetext(field); var node = new Sortable(text, field.label); node.Tag = field; int id = SelectedNode.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.SHORT; field.label = "DmgRedctAmt"; field.SHORT = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.SHORT; field.label = "DmgRedctFlags"; field.SHORT = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; SelectedNode.Nodes[id].Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.List; field.label = "DmgRedctSubList"; text = GeneralGFF.ConstructNodetext(field); var list = new Sortable(text, field.label); list.Tag = field; SelectedNode.Nodes[id].Nodes.Add(list); field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = "0"; // Structs in Lists do not have a Label field.Struct = new Struct(); field.Struct.typeid = 2; // <- that's what's in the UTCs I've looked at. text = GeneralGFF.ConstructNodetext(field); var @struct = new Sortable(text, field.label); @struct.Tag = field; list.Nodes.Add(@struct); field = new GffData.Field(); field.type = FieldTypes.SHORT; field.label = "DmgRedctSubType"; field.SHORT = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; @struct.Nodes.Add(node); field = new GffData.Field(); field.type = FieldTypes.SHORT; field.label = "DmgRedctType"; field.SHORT = 0; text = GeneralGFF.ConstructNodetext(field); node = new Sortable(text, field.label); node.Tag = field; @struct.Nodes.Add(node); SelectedNode = SelectedNode.Nodes[id]; SelectedNode.Expand(); list.Expand(); @struct.Expand(); TopNode = top; _f.GffData.Changed = true; _f.GffData = _f.GffData; EndUpdate(); node.EnsureVisible(); // yes those calls are in a specific sequence. }
/// <summary> /// Adds a Field to a treenode. /// </summary> /// <param name="field">a Field to add</param> /// <param name="parent">a treenode to add it to</param> /// <param name="locale">a locale if applicable</param> static void AddField(GffData.Field field, TreeNode parent, GffData.Locale locale = null) { // TODO: Refactor things throughout the code such that the Tag of a // treenode is *either* a GffData.Field *or* a GffData.Locale. string text = GeneralGFF.ConstructNodetext(field, locale); var node = new Sortable(text, field.label); node.Tag = field; parent.Nodes.Add(node); switch (field.type) { case FieldTypes.Struct: // childs can be of any Type. { List <uint> fieldids = field.Struct.fieldids; for (int i = 0; i != fieldids.Count; ++i) { AddField(GffReader.Fields[(int)fieldids[i]], node); } break; } case FieldTypes.List: // childs are Structs. { List <uint> list = field.List; for (int i = 0; i != list.Count; ++i) { // NOTE: Structs in Lists do not have a Label inside a GFF-file. // so give Structs in Lists a pseudo-label for their treenode(s) field = new GffData.Field(); field.type = FieldTypes.Struct; field.label = i.ToString(); field.Struct = GffReader.Structs[(int)list[i]]; AddField(field, node); } break; } case FieldTypes.CExoLocString: // childs are Locales. if (field.Locales != null) { int locales = field.Locales.Count; for (int i = 0; i != locales; ++i) { locale = field.Locales[i]; var fieldloc = new GffData.Field(); fieldloc.type = FieldTypes.locale; fieldloc.localeid = (uint)i; fieldloc.label = GffData.Locale.GetLanguageString(locale.langid, locale.F); AddField(fieldloc, node, locale); LocaleDialog.SetLocaleFlag(ref field.localeflags, locale.langid, locale.F); } } break; } }