public SAV_EventWork(SaveFile sav) { InitializeComponent(); WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); if (sav is SAV7b s7b) { SAV = s7b.Blocks.EventWork; } else if (sav is SAV8SWSH s8ss) { SAV = s8ss.Blocks.EventWork; } Origin = sav; DragEnter += Main_DragEnter; DragDrop += Main_DragDrop; CB_Stats.Items.Clear(); for (int i = 0; i < SAV.MaxWork; i++) { CB_Stats.Items.Add(i.ToString()); } var work = GetStringList(sav.Version, "const"); var flag = GetStringList(sav.Version, "flags"); Editor = new SplitEventEditor <int>(SAV, work, flag); SuspendLayout(); editing = true; LoadFlags(Editor.Flag); LoadWork(Editor.Work); editing = false; ResumeLayout(); if (CB_Stats.Items.Count > 0) { CB_Stats.SelectedIndex = 0; } else { L_Stats.Visible = CB_Stats.Visible = NUD_Stat.Visible = false; TC_Features.TabPages.Remove(GB_Constants); } NUD_Flag.Maximum = SAV.MaxFlag - 1; NUD_Flag.Text = "0"; c_CustomFlag.Checked = SAV.GetFlag(0); Text = $"{Text} ({sav.Version})"; }
public SplitEventEditor(IEventWork <T> block, IEnumerable <string> work, IEnumerable <string> flag) { Block = block; // load lines var worklines = work.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5); Work = EventWorkUtil.GetVars(worklines, (index, t, data) => new EventWork <T>(index, t, data)); var flaglines = flag.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5); Flag = EventWorkUtil.GetVars(flaglines, (index, t, data) => new EventFlag(index, t, data)); // initialize lines foreach (var g in Work) { foreach (var item in g.Vars) { item.RawIndex = block.GetWorkRawIndex(item.Type, item.RelativeIndex); ((EventWork <T>)item).Value = block.GetWork(item.RawIndex); } } foreach (var g in Flag) { foreach (var item in g.Vars) { item.RawIndex = block.GetFlagRawIndex(item.Type, item.RelativeIndex); ((EventFlag)item).Flag = block.GetFlag(item.RawIndex); } } }
/// <summary> /// Compares a <see cref="before"/> and <see cref="after"/> <see cref="IEventWork{T}"/> object of the same type to find <see cref="EventFlag"/> changes. /// </summary> /// <typeparam name="T">Type of value used by <see cref="EventWork{T}"/></typeparam> /// <param name="before">Data before the event was triggered</param> /// <param name="after">Data after the event was triggered</param> /// <param name="on">List of flags that were turned on</param> /// <param name="off">List of flags that were turned off</param> public static void DiffSavesFlag <T>(IEventWork <T> before, IEventWork <T> after, List <int> on, List <int> off) { int max = before.MaxFlag; for (int i = 0; i < max; i++) { var b = before.GetFlag(i); var a = after.GetFlag(i); if (b == a) { continue; } var arr = a ? on : off; arr.Add(i); } }
private void ChangeCustomFlag(object sender, EventArgs e) { c_CustomFlag.Checked = SAV.GetFlag((int)NUD_Flag.Value); }