/// <summary> /// Handles the GlobalApply it. Applies all altered data to their /// <c>structs</c>. /// </summary> /// <param name="sender"> /// <list type="bullet"> /// <item><c><see cref="it_ApplyGlobal"/></c></item> /// <item><c><see cref="it_Save"/></c></item> /// <item><c><see cref="it_Saveas"/></c></item> /// </list></param> /// <param name="e"></param> /// <remarks>See <c><see cref="Click_apply()">Click_apply()</see></c> to /// apply altered data to only the selected <c>struct</c>.</remarks> void Click_applyGlobal(object sender, EventArgs e) { SetTitleText(); // TitleText will be written again (properly) by Write2daFile() if saved. it_ApplyGlobal.Enabled = false; int total; switch (Type) { case Type2da.Spells: { Spell spell; total = Spells.Count; for (int id = 0; id != total; ++id) { spell = Spells[id]; if (spell.differ != control_Spells.bit_clean) { spell.differ = control_Spells.bit_clean; spell.isChanged = true; // this flag will be cleared by Write2daFile() SpellChanged spellchanged = SpellsChanged[id]; spell.spellinfo = spellchanged.spellinfo; spell.targetinfo = spellchanged.targetinfo; spell.effectweight = spellchanged.effectweight; spell.effecttypes = spellchanged.effecttypes; spell.damageinfo = spellchanged.damageinfo; spell.savetype = spellchanged.savetype; spell.savedctype = spellchanged.savedctype; Spells[id] = spell; SpellsChanged.Remove(id); if (id == Id) // is currently selected tree-node { HenchControl.SetResetColor(DefaultForeColor); AfterSelect_node(null, null); // refresh all displayed data for the current spell jic } Tree.Nodes[id].ForeColor = Color.Blue; } } break; } case Type2da.Racial: { Race race; total = Races.Count; for (int id = 0; id != total; ++id) { race = Races[id]; if (race.differ != control_Racial.bit_clean) { race.differ = control_Racial.bit_clean; race.isChanged = true; // this flag will be cleared by Write2daFile() RaceChanged racechanged = RacesChanged[id]; race.flags = racechanged.flags; race.feat1 = racechanged.feat1; race.feat2 = racechanged.feat2; race.feat3 = racechanged.feat3; race.feat4 = racechanged.feat4; race.feat5 = racechanged.feat5; Races[id] = race; RacesChanged.Remove(id); if (id == Id) // is currently selected tree-node { HenchControl.SetResetColor(DefaultForeColor); AfterSelect_node(null, null); // refresh all displayed data for the current race jic } Tree.Nodes[id].ForeColor = Color.Blue; } } break; } case Type2da.Classes: { Class @class; total = Classes.Count; for (int id = 0; id != total; ++id) { @class = Classes[id]; if (@class.differ != control_Classes.bit_clean) { @class.differ = control_Classes.bit_clean; @class.isChanged = true; // this flag will be cleared by Write2daFile() ClassChanged classchanged = ClassesChanged[id]; @class.flags = classchanged.flags; @class.feat1 = classchanged.feat1; @class.feat2 = classchanged.feat2; @class.feat3 = classchanged.feat3; @class.feat4 = classchanged.feat4; @class.feat5 = classchanged.feat5; @class.feat6 = classchanged.feat6; @class.feat7 = classchanged.feat7; @class.feat8 = classchanged.feat8; @class.feat9 = classchanged.feat9; @class.feat10 = classchanged.feat10; @class.feat11 = classchanged.feat11; Classes[id] = @class; ClassesChanged.Remove(id); if (id == Id) // is currently selected tree-node { HenchControl.SetResetColor(DefaultForeColor); AfterSelect_node(null, null); // refresh all displayed data for the current class jic } Tree.Nodes[id].ForeColor = Color.Blue; } } break; } } }
/// <summary> /// Gets a bitwise <c>int</c> containing flags for fields that have /// changed. /// </summary> /// <param name="class">a <c>Class</c> <c>struct</c></param> /// <param name="classchanged">a <c>ClassChanged</c> <c>struct</c></param> /// <returns>bitwise <c>int</c> containing flags for fields that have /// changed</returns> internal static int ClassDiffer(Class @class, ClassChanged classchanged) { int differ = control_Classes.bit_clean; if (@class.flags != classchanged.flags) { differ |= control_Classes.bit_flags; } if (@class.feat1 != classchanged.feat1) { differ |= control_Classes.bit_feat1; } if (@class.feat2 != classchanged.feat2) { differ |= control_Classes.bit_feat2; } if (@class.feat3 != classchanged.feat3) { differ |= control_Classes.bit_feat3; } if (@class.feat4 != classchanged.feat4) { differ |= control_Classes.bit_feat4; } if (@class.feat5 != classchanged.feat5) { differ |= control_Classes.bit_feat5; } if (@class.feat6 != classchanged.feat6) { differ |= control_Classes.bit_feat6; } if (@class.feat7 != classchanged.feat7) { differ |= control_Classes.bit_feat7; } if (@class.feat8 != classchanged.feat8) { differ |= control_Classes.bit_feat8; } if (@class.feat9 != classchanged.feat9) { differ |= control_Classes.bit_feat9; } if (@class.feat10 != classchanged.feat10) { differ |= control_Classes.bit_feat10; } if (@class.feat11 != classchanged.feat11) { differ |= control_Classes.bit_feat11; } return(differ); }
/// <summary> /// Fills displayed fields w/ data from the class' Id. /// </summary> internal override void SelectId() { ClassFlags_text.Clear(); // clear the info-fields to force TextChanged events -> ClassFeat1_text.Clear(); ClassFeat2_text.Clear(); ClassFeat3_text.Clear(); ClassFeat4_text.Clear(); ClassFeat5_text.Clear(); ClassFeat6_text.Clear(); ClassFeat7_text.Clear(); ClassFeat8_text.Clear(); ClassFeat9_text.Clear(); ClassFeat10_text.Clear(); ClassFeat11_text.Clear(); Class @class = he.Classes[he.Id]; bool dirty = (@class.differ != bit_clean); ClassChanged classchanged; if (dirty) { classchanged = he.ClassesChanged[he.Id]; } else { classchanged = new ClassChanged(); // not used. } int val = @class.flags; ClassFlags_reset.Text = val.ToString(); if (dirty) { val = classchanged.flags; } ClassFlags_text.Text = val.ToString(); val = @class.feat1; ClassFeat1_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat1; } ClassFeat1_text.Text = val.ToString(); val = @class.feat2; ClassFeat2_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat2; } ClassFeat2_text.Text = val.ToString(); val = @class.feat3; ClassFeat3_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat3; } ClassFeat3_text.Text = val.ToString(); val = @class.feat4; ClassFeat4_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat4; } ClassFeat4_text.Text = val.ToString(); val = @class.feat5; ClassFeat5_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat5; } ClassFeat5_text.Text = val.ToString(); val = @class.feat6; ClassFeat6_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat6; } ClassFeat6_text.Text = val.ToString(); val = @class.feat7; ClassFeat7_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat7; } ClassFeat7_text.Text = val.ToString(); val = @class.feat8; ClassFeat8_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat8; } ClassFeat8_text.Text = val.ToString(); val = @class.feat9; ClassFeat9_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat9; } ClassFeat9_text.Text = val.ToString(); val = @class.feat10; ClassFeat10_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat10; } ClassFeat10_text.Text = val.ToString(); val = @class.feat11; ClassFeat11_reset.Text = val.ToString(); if (dirty) { val = classchanged.feat11; } ClassFeat11_text.Text = val.ToString(); }
/// <summary> /// Handles <c>TextChanged</c> event on the Classes pages. /// </summary> /// <param name="sender"> /// <list type="bullet"> /// <item><c><see cref="ClassFlags_text"/></c></item> /// <item><c><see cref="ClassFeat1_text"/></c></item> /// <item><c><see cref="ClassFeat2_text"/></c></item> /// <item><c><see cref="ClassFeat3_text"/></c></item> /// <item><c><see cref="ClassFeat4_text"/></c></item> /// <item><c><see cref="ClassFeat5_text"/></c></item> /// <item><c><see cref="ClassFeat6_text"/></c></item> /// <item><c><see cref="ClassFeat7_text"/></c></item> /// <item><c><see cref="ClassFeat8_text"/></c></item> /// <item><c><see cref="ClassFeat9_text"/></c></item> /// <item><c><see cref="ClassFeat10_text"/></c></item> /// <item><c><see cref="ClassFeat11_text"/></c></item> /// </list></param> /// <param name="e"></param> void TextChanged_classes(object sender, EventArgs e) { // NOTE: TextChanged needs to fire when HenchSpells loads in order // to set the checkboxes and dropdown-fields. // // 'BypassDiffer' is set true since this does not need to go through // creating and deleting each SpellChanged-struct (since nothing has // changed yet OnLoad of the 2da-file). // // 'BypassDiffer' is also set true by AfterSelect_node() since the // Spell-structs already contain proper diff-data. int val; if (Int32.TryParse((sender as TextBox).Text, out val)) { Button bu; TextBox tb_hex, tb_bin; int bit; bool isFlags = (sender == ClassFlags_text); if (isFlags) { // if (InfoVersionChange_class(ref val)) // TonyAI 2.3+ allow class InfoVersion to be 0. // { // ClassFlags_text.Text = val.ToString(); // return; // refire this funct. // } bu = ClassFlags_reset; tb_hex = ClassFlags_hex; tb_bin = ClassFlags_bin; bit = bit_flags; } else if (sender == ClassFeat1_text) { bu = ClassFeat1_reset; tb_hex = ClassFeat1_hex; tb_bin = ClassFeat1_bin; bit = bit_feat1; } else if (sender == ClassFeat2_text) { bu = ClassFeat2_reset; tb_hex = ClassFeat2_hex; tb_bin = ClassFeat2_bin; bit = bit_feat2; } else if (sender == ClassFeat3_text) { bu = ClassFeat3_reset; tb_hex = ClassFeat3_hex; tb_bin = ClassFeat3_bin; bit = bit_feat3; } else if (sender == ClassFeat4_text) { bu = ClassFeat4_reset; tb_hex = ClassFeat4_hex; tb_bin = ClassFeat4_bin; bit = bit_feat4; } else if (sender == ClassFeat5_text) { bu = ClassFeat5_reset; tb_hex = ClassFeat5_hex; tb_bin = ClassFeat5_bin; bit = bit_feat5; } else if (sender == ClassFeat6_text) { bu = ClassFeat6_reset; tb_hex = ClassFeat6_hex; tb_bin = ClassFeat6_bin; bit = bit_feat6; } else if (sender == ClassFeat7_text) { bu = ClassFeat7_reset; tb_hex = ClassFeat7_hex; tb_bin = ClassFeat7_bin; bit = bit_feat7; } else if (sender == ClassFeat8_text) { bu = ClassFeat8_reset; tb_hex = ClassFeat8_hex; tb_bin = ClassFeat8_bin; bit = bit_feat8; } else if (sender == ClassFeat9_text) { bu = ClassFeat9_reset; tb_hex = ClassFeat9_hex; tb_bin = ClassFeat9_bin; bit = bit_feat9; } else if (sender == ClassFeat10_text) { bu = ClassFeat10_reset; tb_hex = ClassFeat10_hex; tb_bin = ClassFeat10_bin; bit = bit_feat10; } else // sender == ClassFeat11_text { bu = ClassFeat11_reset; tb_hex = ClassFeat11_hex; tb_bin = ClassFeat11_bin; bit = bit_feat11; } if (!he.BypassDiffer) { Class @class = he.Classes[he.Id]; ClassChanged classchanged; if (@class.differ != bit_clean) { classchanged = he.ClassesChanged[he.Id]; } else { classchanged = new ClassChanged(); classchanged.flags = @class.flags; classchanged.feat1 = @class.feat1; classchanged.feat2 = @class.feat2; classchanged.feat3 = @class.feat3; classchanged.feat4 = @class.feat4; classchanged.feat5 = @class.feat5; classchanged.feat6 = @class.feat6; classchanged.feat7 = @class.feat7; classchanged.feat8 = @class.feat8; classchanged.feat9 = @class.feat9; classchanged.feat10 = @class.feat10; classchanged.feat11 = @class.feat11; } if (isFlags) { classchanged.flags = val; } else if (sender == ClassFeat1_text) { classchanged.feat1 = val; } else if (sender == ClassFeat2_text) { classchanged.feat2 = val; } else if (sender == ClassFeat3_text) { classchanged.feat3 = val; } else if (sender == ClassFeat4_text) { classchanged.feat4 = val; } else if (sender == ClassFeat5_text) { classchanged.feat5 = val; } else if (sender == ClassFeat6_text) { classchanged.feat6 = val; } else if (sender == ClassFeat7_text) { classchanged.feat7 = val; } else if (sender == ClassFeat8_text) { classchanged.feat8 = val; } else if (sender == ClassFeat9_text) { classchanged.feat9 = val; } else if (sender == ClassFeat10_text) { classchanged.feat10 = val; } else // sender == ClassFeat11_text { classchanged.feat11 = val; } // check it @class.differ = ClassDiffer(@class, classchanged); he.Classes[he.Id] = @class; Color color; if (@class.differ != bit_clean) { he.ClassesChanged[he.Id] = classchanged; color = Color.Crimson; } else { he.ClassesChanged.Remove(he.Id); if (@class.isChanged) { color = Color.Blue; } else { color = DefaultForeColor; } } _he.SetNodeColor(color); } he.PrintCurrent(val, tb_hex, tb_bin); int differ = he.Classes[he.Id].differ; if ((differ & bit) != 0) { bu.ForeColor = Color.Crimson; } else { bu.ForeColor = DefaultForeColor; } if (isFlags) { state_ClassFlags(val); // PrintInfoVersion_class(val); } else { state_ClassFeats(sender as Control); } _he.EnableApplys(differ != bit_clean); } // else TODO: error dialog here. }
/// <summary> /// Handler for the "apply changed data to currently selected /// spell/race/class" button. /// </summary> /// <param name="sender">bu_Apply</param> /// <param name="e"></param> /// <remarks>See /// <c><see cref="Click_applyGlobal()">Click_applyGlobal()</see></c> to /// apply all altered data globally.</remarks> void Click_apply(object sender, EventArgs e) { SetTitleText(); switch (Type) { case Type2da.Spells: { Spell spell = Spells[Id]; if (spell.differ != control_Spells.bit_clean) { spell.differ = control_Spells.bit_clean; spell.isChanged = true; SpellChanged spellchanged = SpellsChanged[Id]; spell.spellinfo = spellchanged.spellinfo; spell.targetinfo = spellchanged.targetinfo; spell.effectweight = spellchanged.effectweight; spell.effecttypes = spellchanged.effecttypes; spell.damageinfo = spellchanged.damageinfo; spell.savetype = spellchanged.savetype; spell.savedctype = spellchanged.savedctype; Spells[Id] = spell; SpellsChanged.Remove(Id); HenchControl.SetResetColor(DefaultForeColor); AfterSelect_node(null, null); // refresh all displayed data for the current spell jic } if (Spells[Id].isChanged) // this goes outside the SpellsChanged check above because uh color goes screwy if not. { Tree.SelectedNode.ForeColor = Color.Blue; } else // I doubt this ever *needs* to run ... but safety. { Tree.SelectedNode.ForeColor = DefaultForeColor; } break; } case Type2da.Racial: { Race race = Races[Id]; if (race.differ != control_Racial.bit_clean) { race.differ = control_Racial.bit_clean; race.isChanged = true; RaceChanged racechanged = RacesChanged[Id]; race.flags = racechanged.flags; race.feat1 = racechanged.feat1; race.feat2 = racechanged.feat2; race.feat3 = racechanged.feat3; race.feat4 = racechanged.feat4; race.feat5 = racechanged.feat5; Races[Id] = race; RacesChanged.Remove(Id); HenchControl.SetResetColor(DefaultForeColor); AfterSelect_node(null, null); // refresh all displayed data for the current node jic } if (Races[Id].isChanged) // this goes outside the RacesChanged check above because uh color goes screwy if not. { Tree.SelectedNode.ForeColor = Color.Blue; } else // I doubt this ever *needs* to run ... but safety. { Tree.SelectedNode.ForeColor = DefaultForeColor; } break; } case Type2da.Classes: { Class @class = Classes[Id]; if (@class.differ != control_Classes.bit_clean) { @class.differ = control_Classes.bit_clean; @class.isChanged = true; ClassChanged classchanged = ClassesChanged[Id]; @class.flags = classchanged.flags; @class.feat1 = classchanged.feat1; @class.feat2 = classchanged.feat2; @class.feat3 = classchanged.feat3; @class.feat4 = classchanged.feat4; @class.feat5 = classchanged.feat5; @class.feat6 = classchanged.feat6; @class.feat7 = classchanged.feat7; @class.feat8 = classchanged.feat8; @class.feat9 = classchanged.feat9; @class.feat10 = classchanged.feat10; @class.feat11 = classchanged.feat11; Classes[Id] = @class; ClassesChanged.Remove(Id); HenchControl.SetResetColor(DefaultForeColor); AfterSelect_node(null, null); // refresh all displayed data for the current node jic } if (Classes[Id].isChanged) // this goes outside the ClassesChanged check above because uh color goes screwy if not. { Tree.SelectedNode.ForeColor = Color.Blue; } else // I doubt this ever *needs* to run ... but safety. { Tree.SelectedNode.ForeColor = DefaultForeColor; } break; } } }
/// <summary> /// This funct is used only for /// <c><see cref="Click_clearCoreAiVersion()">Click_clearCoreAiVersion()</see></c>. /// </summary> /// <param name="str"></param> /// <param name="all"><c>true</c> to apply version to all classes else /// apply to changed classes only</param> /// <remarks>Used to be a helper for <c>Click_setCoreAiVersion()</c>.</remarks> void SetInfoVersion_classes(string str, bool all) { Class @class; ClassChanged classchanged; int classflags0, classflags, differ; bool dirty; int ver = (Int32.Parse(str) << HENCH_SPELL_INFO_VERSION_SHIFT); // the return from the dialog. int total = Classes.Count; for (int id = 0; id != total; ++id) { @class = Classes[id]; if (dirty = ((@class.differ & control_Classes.bit_flags) != 0)) { classflags0 = ClassesChanged[id].flags; } else if (all || @class.isChanged) { classflags0 = @class.flags; } else { continue; // ignore clean class-structs if !all } if ((classflags0 & hc.HENCH_SPELL_INFO_VERSION_MASK) != ver) { if (!BypassInfoVersion) { classflags = ((classflags0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK) | ver); } else { classflags = (classflags0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK); // wipe version info for TonyAI 2.3+ } if (id == Id) { HenchControl.SetMasterText(classflags.ToString()); // firing the TextChanged event takes care of it. } else { if (dirty) { classchanged = ClassesChanged[id]; } else { classchanged = new ClassChanged(); classchanged.feat1 = @class.feat1; classchanged.feat2 = @class.feat2; classchanged.feat3 = @class.feat3; classchanged.feat4 = @class.feat4; classchanged.feat5 = @class.feat5; classchanged.feat6 = @class.feat6; classchanged.feat7 = @class.feat7; classchanged.feat8 = @class.feat8; classchanged.feat9 = @class.feat9; classchanged.feat10 = @class.feat10; classchanged.feat11 = @class.feat11; } classchanged.flags = classflags; // check it differ = control_Classes.ClassDiffer(@class, classchanged); @class.differ = differ; Classes[id] = @class; Color color; if (differ != control_Classes.bit_clean) { ClassesChanged[id] = classchanged; color = Color.Crimson; } else { ClassesChanged.Remove(id); if (@class.isChanged) { color = Color.Blue; } else { color = DefaultForeColor; } } Tree.Nodes[id].ForeColor = color; } } } }