private void addProgression(ItemStep stepFrom, ItemStep stepTo) { if (stepFrom == stepTo) { return; } int indexFrom = Steps.FindIndex(o => { return(o == stepFrom); }); int indexTo = Steps.FindIndex(o => { return(o == stepTo); }); if (stepTo.Step.ProgressFrom < 0) { stepTo.Step.ProgressFrom = indexFrom; } if (stepFrom.Step.ProgressTo < 0) // Create a default progression { stepFrom.Step.ProgressTo = indexTo; } else // Create an optional progression { stepFrom.Step.Progressions.Add(new Scenario.Step.Progression(indexTo)); } drawIProgressions(); updatePropertyView(); expStepProperty.IsExpanded = false; expProgressionProperty.IsExpanded = true; }
private void deleteStep(ItemStep ist) { int iStep = Steps.FindIndex(obj => { return(obj == ist); }); int iFrom = (ist.Step.ProgressFrom > iStep) ? ist.Step.ProgressFrom - 1 : ist.Step.ProgressFrom; int iTo = (ist.Step.ProgressTo > iStep) ? ist.Step.ProgressTo - 1 : ist.Step.ProgressTo; // Remove the selected Step from the stack and visual Steps.RemoveAt(iStep); canvasDesigner.Children.Remove(ist); foreach (ItemStep.UIEProgression uiep in ist.IProgressions) { canvasDesigner.Children.Remove(uiep); } foreach (ItemStep s in Steps) { // Adjust all references past the index -= 1 if (s.Step.ProgressTo > iStep) { s.Step.ProgressTo -= 1; } if (s.Step.ProgressFrom > iStep) { s.Step.ProgressFrom -= 1; } // Tie any references to the removed Step to its references Steps if (s.Step.ProgressTo == iStep) { s.Step.ProgressTo = iTo; } if (s.Step.ProgressFrom == iStep) { s.Step.ProgressFrom = iFrom; } // Remove any optional Progressions that target the deleted Step for (int i = 0; i < s.Step.Progressions.Count; i++) { Scenario.Step.Progression p = s.Step.Progressions [i]; if (p.DestinationIndex == iStep) { s.Step.Progressions.RemoveAt(i); } } } // Set all Steps' indices for their Labels for (int i = 0; i < Steps.Count; i++) { Steps [i].SetNumber(i); } // Refresh all IProgressions (visual lines) drawIProgressions(); }
private void addStep(ItemStep ist) { if (ist == null) { ist = new ItemStep(); } // Init ItemStep ist.Init(); ist.IStep.MouseLeftButtonDown += IStep_MouseLeftButtonDown; ist.IStep.MouseLeftButtonUp += IStep_MouseLeftButtonUp; ist.IStep.MouseMove += IStep_MouseMove; ist.IStepEnd.MouseLeftButtonDown += IStepEnd_MouseLeftButtonDown; // Add to lists and display elements Steps.Add(ist); canvasDesigner.Children.Add(ist); Canvas.SetZIndex(ist, 1); // Select the added step, give a default name by its index selectStep(ist); ist.SetNumber(Steps.FindIndex(o => { return(o == selStep); })); // Refresh the Properties View and draw Progression elements/colors updatePropertyView(); drawIProgressions(); expStepProperty.IsExpanded = true; expProgressionProperty.IsExpanded = true; }
private void selectStep(ItemStep ist) { selStep = ist; foreach (ItemStep i in Steps) { i.IStep.StrokeThickness = (i == selStep) ? i.StrokeThickness_Selected : i.StrokeThickness_Default; } }
private void drawIProgressions() { // Completely recreate and add all progression lines to list and canvas foreach (ItemStep iStep in Steps) { foreach (ItemStep.UIEProgression uiep in iStep.IProgressions) { canvasDesigner.Children.Remove(uiep); } iStep.IProgressions.Clear(); if (iStep.Step.ProgressTo > -1 && iStep.Step.ProgressTo < Steps.Count) { // Draw default progress ItemStep iTo = Steps [iStep.Step.ProgressTo]; ItemStep.UIEProgression uiep = new ItemStep.UIEProgression(iStep, iTo, canvasDesigner); iStep.IProgressions.Add(uiep); } foreach (Scenario.Step.Progression p in iStep.Step.Progressions) { if (p.DestinationIndex >= Steps.Count) { continue; } ItemStep iTo = Steps [p.DestinationIndex]; ItemStep.UIEProgression uiep = new ItemStep.UIEProgression(iStep, iTo, canvasDesigner); iStep.IProgressions.Add(uiep); } // Add all new progression lines to canvas foreach (ItemStep.UIEProgression uiep in iStep.IProgressions) { canvasDesigner.Children.Add(uiep); Canvas.SetZIndex(uiep, 0); } // Color IStepEnd depending on whether it has progressions if (iStep?.IProgressions?.Count == 0) { iStep.IStepEnd.Fill = iStep.Fill_StepEndNoProgression; } else if (iStep?.IProgressions?.Count == 1) { iStep.IStepEnd.Fill = iStep.Fill_StepEndNoOptionalProgression; } else if (iStep?.IProgressions?.Count > 1) { iStep.IStepEnd.Fill = iStep.Fill_StepEndMultipleProgressions; } } }
private void IStep_MouseMove(object sender, MouseEventArgs e) { if (mouseCaptured) { double x = e.GetPosition(LayoutRoot).X; double y = e.GetPosition(LayoutRoot).Y; xShape += x - xCanvas; xCanvas = x; yShape += y - yCanvas; yCanvas = y; ItemStep istep = ((ItemStep.UIEStep)sender).ItemStep; Canvas.SetLeft(selStep, II.Math.Clamp(xShape, 0, canvasDesigner.ActualWidth - istep.ActualWidth)); Canvas.SetTop(selStep, II.Math.Clamp(yShape, 0, canvasDesigner.ActualHeight - istep.ActualHeight)); updateIProgressions(); } }
private void newScenario() { if (promptUnsavedWork() != MessageBoxResult.OK) { return; } // Reset buffer parameters selStep = null; selEnd = null; mouseCaptured = false; // Clear master lists and UI elements canvasDesigner.Children.Clear(); Steps.Clear(); // Clear scenario data ScenarioAuthor = ""; ScenarioName = ""; ScenarioDescription = ""; updateScenarioProperty(); }
private void loadFile(string filepath) { StreamReader sr = new StreamReader(filepath); // Read savefile metadata indicating data formatting // Supports II:T1 file structure string metadata = sr.ReadLine(); if (!metadata.StartsWith(".ii:t1")) { loadFail(); return; } // Savefile type 1: validated and encrypted // Line 1 is metadata (.ii:t1) // Line 2 is hash for validation (hash taken of raw string data, unobfuscated) // Line 3 is savefile data encrypted by AES encoding string hash = sr.ReadLine().Trim(); string file = Encryption.DecryptAES(sr.ReadToEnd().Trim()); if (hash != Encryption.HashSHA256(file)) { loadFail(); return; } StringReader sRead = new StringReader(file); string line, pline; StringBuilder pbuffer; Scenario sc = new Scenario(false); try { while ((line = sRead.ReadLine()) != null) { if (line == "> Begin: Scenario") { pbuffer = new StringBuilder(); while ((pline = sRead.ReadLine()) != null && pline != "> End: Scenario") { pbuffer.AppendLine(pline); } sc.Load_Process(pbuffer.ToString()); } } } catch { loadFail(); } finally { sRead.Close(); } // Convert loaded scenario to Scenario Editor data structures ScenarioAuthor = sc.Author; ScenarioName = sc.Name; ScenarioDescription = sc.Description; Steps.Clear(); canvasDesigner.Children.Clear(); for (int i = 0; i < sc.Steps.Count; i++) { // Add to the main Steps stack ItemStep ist = new ItemStep(); ist.Init(); ist.Step = sc.Steps [i]; ist.SetNumber(i); ist.SetName(ist.Step.Name); // After all UIElements are initialized, will need to "refresh" the line positions via loadIProgressions isLoading = true; ist.LayoutUpdated += loadIProgressions; ist.IStep.MouseLeftButtonDown += IStep_MouseLeftButtonDown; ist.IStep.MouseLeftButtonUp += IStep_MouseLeftButtonUp; ist.IStep.MouseMove += IStep_MouseMove; ist.IStepEnd.MouseLeftButtonDown += IStepEnd_MouseLeftButtonDown; // Add to lists and display elements Steps.Add(ist); canvasDesigner.Children.Add(ist); Canvas.SetZIndex(ist, 1); Canvas.SetLeft(ist, ist.Step.IPositionX); Canvas.SetTop(ist, ist.Step.IPositionY); } // Refresh the Properties View with the newly selected step selectStep(Steps.Count > 0 ? Steps [0] : null); updatePropertyView(); updateScenarioProperty(); drawIProgressions(); expStepProperty.IsExpanded = true; expProgressionProperty.IsExpanded = true; }