public App() { // NWN2ModuleAnalyser.ExcelOutput e = new NWN2ModuleAnalyser.ExcelOutput(); // // ModuleStats s = new ModuleStats(); // s.Name = "Whatup"; // s.CumulativeStats.Actions["GiveGold"]++; // // e.PopulateColumn(s.GetSpreadsheetRows(),1,2); // e.PopulateColumn(s.GetSpreadsheetData(),2,2); // e.Quit(); FlipTranslator translator = new FakeTranslator(); FlipAttacher attacher = new FakeAttacher(translator); Nwn2Fitters fitters = new Nwn2Fitters(); Nwn2StatementFactory statements = new Nwn2StatementFactory(fitters); Nwn2TriggerFactory triggers = new Nwn2TriggerFactory(fitters); Nwn2ImageProvider images = new Nwn2ImageProvider(new NarrativeThreadsHelper()); Nwn2ObjectBlockFactory blocks = new Nwn2ObjectBlockFactory(images); Nwn2MoveableProvider provider = new Nwn2MoveableProvider(blocks, statements, triggers); FlipWindow window = new FlipWindow(provider, images, new FlipWindow.OpenDeleteScriptDelegate(Open), new FlipWindow.SaveScriptDelegate(Save), new Nwn2DeserialisationHelper()); window.Show(); }
public ScriptSelector(List <ScriptTriggerTuple> tuples, INwn2Session session, FlipWindow window) { if (tuples == null) { throw new ArgumentNullException("tuples"); } if (session == null) { throw new ArgumentNullException("session"); } if (window == null) { throw new ArgumentNullException("window"); } this.tuples = tuples; this.session = session; this.window = window; selected = null; InitializeComponent(); MouseButtonEventHandler scriptSelected = new MouseButtonEventHandler(OpenScript); scriptsListBox.MouseDoubleClick += scriptSelected; scriptsListBox.KeyDown += new KeyEventHandler(OpenScript); foreach (ScriptTriggerTuple tuple in tuples) { try { TriggerControl trigger = tuple.Trigger; if (trigger == null) { continue; } trigger.Padding = thickness; scriptsListBox.Items.Add(trigger); } catch (Exception) {} } }
/// <summary> /// Constructs a new <see cref="FlipPlugin"/> instance. /// </summary> public FlipPlugin() { preferences = new object(); service = new ServiceController(); window = null; string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); systemFolder = Path.Combine(myDocuments, "Adventure Author"); logsFolder = Path.Combine(systemFolder, "User logs"); scriptsFolder = Path.Combine(systemFolder, "Scripts"); try { Tools.EnsureDirectoryExists(systemFolder); Tools.EnsureDirectoryExists(logsFolder); Tools.EnsureDirectoryExists(scriptsFolder); } catch (Exception x) { MessageBox.Show("Could not create necessary Flip folders within this user's My Documents folder. " + "Logs and copies of scripts will not be saved, and the software may not work as intended.\n\n" + x); } }
public bool Save(FlipWindow window) { return(false); }
public bool SaveScript(FlipWindow window) { if (window == null) { throw new ArgumentNullException("window"); } if (attacher == null) { throw new InvalidOperationException("No attacher to save scripts with."); } if (!window.IsComplete) { //ActivityLog.Write(new Activity("TriedToSaveIncompleteScript")); Log.WriteMessage("tried to save incomplete script"); MessageBox.Show("Your script isn't finished! Fill in all the blanks before saving."); return(false); } IScriptFrame scriptFrame = window.GetCurrentScriptFrame(); AbstractScriptWriter scriptWriter; if (window.Mode == ScriptType.Conditional) { scriptWriter = new ConditionalScriptWriter(window.ConditionalFrame); } else { scriptWriter = new ScriptWriter(window.TriggerBar); } string code = scriptWriter.GetCombinedCode(); FlipScript script = new FlipScript(code, window.Mode, String.Empty); string address = scriptFrame.GetAddress(); try { string savedAs = attacher.Attach(script, address); window.TriggerBar.CurrentScriptIsBasedOn = savedAs; window.ConditionalFrame.CurrentScriptIsBasedOn = savedAs; window.IsDirty = false; //ActivityLog.Write(new Activity("SavedScript","SavedAs",savedAs)); Log.WriteAction(LogAction.saved, "script", "as " + savedAs); //MessageBox.Show("Script was saved successfully."); try { string nl = window.NaturalLanguage; if (String.IsNullOrEmpty(nl)) { window.NaturalLanguage = "Saved."; } else { window.NaturalLanguage = nl + Environment.NewLine + "Saved."; } } catch (Exception) {} return(true); } catch (MatchingInstanceNotFoundException x) { //ActivityLog.Write(new Activity("TriedToSaveScriptButTargetCouldNotBeFound","TargetType",x.Address.TargetType.ToString(),"TargetTagOrResRef",x.Address.InstanceTag)); Log.WriteMessage("tried to save script but couldn't find target (was looking for " + x.Address.TargetType + " with tag/resref " + x.Address.InstanceTag + ")"); MessageBox.Show(String.Format("There's no {0} like this (with tag '{1}') in any area that's open.\nMake sure that the area containing " + "the {0} is open when you try to save, or it won't work.", x.Address.TargetType, x.Address.InstanceTag)); return(false); } catch (Exception x) { string errorMessage = x.ToString(); if (errorMessage.Contains("flip_functions")) { try { string path = Path.Combine(NWN2Toolset.NWN2.IO.NWN2ResourceManager.Instance.OverrideDirectory.DirectoryName, "flip_functions.nss"); if (!File.Exists(path)) { MessageBox.Show("File " + path + " is missing. Scripts will not compile successfully. Please re-install Flip."); return(false); } } catch (Exception) {} } MessageBox.Show(String.Format("Something went wrong when saving the script.{0}{0}{1}", Environment.NewLine, errorMessage)); return(false); } }
/// <summary> /// Construct a new instance of FlipWindow, and forbid it from closing fully. /// </summary> protected void InitialiseFlip() { session = new Nwn2Session(); FlipTranslator translator = new NWScriptTranslator(); attacher = new NWScriptAttacher(translator, session, scriptsFolder); Nwn2Fitters fitters = new Nwn2Fitters(); triggers = new Nwn2TriggerFactory(fitters); scriptHelper = new ScriptHelper(triggers); Nwn2StatementFactory statements = new Nwn2StatementFactory(fitters); Nwn2ImageProvider images = new Nwn2ImageProvider(new NarrativeThreadsHelper()); blocks = new Nwn2ObjectBlockFactory(images); ToolsetEventReporter reporter = new ToolsetEventReporter(); provider = new Nwn2MoveableProvider(blocks, statements, triggers, reporter); window = new FlipWindow(provider, images, new FlipWindow.OpenDeleteScriptDelegate(OpenDeleteScriptDialog), new FlipWindow.SaveScriptDelegate(SaveScript), new Nwn2DeserialisationHelper()); window.Closing += delegate(object sender, CancelEventArgs e) { // Hide the window instead of closing it: e.Cancel = true; // Unless the user changes their mind about closing the script, // in which case don't even do that: if (window.AskWhetherToSaveCurrentScript() != MessageBoxResult.Cancel) { //window.CloseScript(); window.Visibility = Visibility.Hidden; //window.LeaveConditionMode(); Log.WriteAction(LogAction.exited, "flip"); } }; reporter.ModuleChanged += delegate { Action action = new Action ( delegate() { if (window == null) { return; } try { window.CloseScript(); window.Close(); } catch (Exception) {} } ); if (window != null) { window.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, action); } }; MenuItem addWildcardBlock = new MenuItem(); addWildcardBlock.Header = "Add Wildcard block"; addWildcardBlock.Click += delegate { try { CreateWildcardDialog dialog = new CreateWildcardDialog(); dialog.ShowDialog(); if (!String.IsNullOrEmpty(dialog.WildcardTag)) { ObjectBlock block = blocks.CreateWildcardBlock(dialog.WildcardTag); window.BlockBox.AddMoveable(Nwn2MoveableProvider.ValuesBagName, block, true); //ActivityLog.Write(new Activity("CreatedWildcardBlock","Block",block.GetLogText())); Log.WriteMessage("created wildcard block (" + block.GetLogText() + ")"); } } catch (Exception x) { MessageBox.Show("Something went wrong when creating a Wildcard block.\n\n" + x); } }; window.EditMenu.Items.Add(addWildcardBlock); MenuItem openTriggerlessScripts = new MenuItem(); openTriggerlessScripts.Header = "Open unattached script"; openTriggerlessScripts.Click += delegate { try { OpenAnyScriptViaDialog(); } catch (Exception x) { MessageBox.Show("Something went wrong when opening a script via its filename.\n\n" + x); } }; window.DevelopmentMenu.Items.Add(openTriggerlessScripts); // MenuItem analyseAllScripts = new MenuItem(); // analyseAllScripts.Header = "Analyse all scripts"; // analyseAllScripts.Click += delegate // { // try { // AnalyseAllScripts(); // } // catch (Exception x) { // MessageBox.Show("Something went wrong when analysing scripts.\n\n" + x); // } // }; // window.DevelopmentMenu.Items.Add(analyseAllScripts); // // MenuItem analyseScript = new MenuItem(); // analyseScript.Header = "Analyse script"; // analyseScript.Click += delegate // { // try { // AnalyseScript(); // } // catch (Exception x) { // MessageBox.Show("Something went wrong when analysing script.\n\n" + x); // } // }; // window.DevelopmentMenu.Items.Add(analyseScript); // MenuItem showLogWindow = new MenuItem(); // showLogWindow.Header = "Show log window"; // showLogWindow.Click += delegate // { // try { // new ActivityLogWindow().Show(); // } // catch (Exception x) { // MessageBox.Show("Something went wrong when launching the log window.\n\n" + x); // } // }; // window.DevelopmentMenu.Items.Add(showLogWindow); // Start recording debug messages and user actions: try { LogWriter.StartRecording("flip"); } catch (Exception x) { MessageBox.Show("Something went wrong when setting up a Flip user log.\n" + x); } reporter.AreaNameChanged += delegate(object oObject, NameChangedEventArgs eArgs) { UpdateScriptsFollowingTagChange(oObject, eArgs.OldName, eArgs.NewName, false); }; }