Exemplo n.º 1
0
 public Nwn2MoveableProvider(Nwn2ObjectBlockFactory blocks,
                             Nwn2StatementFactory statements,
                             Nwn2TriggerFactory triggers,
                             ToolsetEventReporter reporter) : this(blocks, statements, triggers)
 {
     if (reporter != null)
     {
         TrackToolsetChanges(reporter);
     }
 }
Exemplo n.º 2
0
        public Nwn2MoveableProvider(Nwn2ObjectBlockFactory blocks, Nwn2StatementFactory statements, Nwn2TriggerFactory triggers)
        {
            if (blocks == null)
            {
                throw new ArgumentNullException("blocks");
            }
            if (statements == null)
            {
                throw new ArgumentNullException("statements");
            }
            if (triggers == null)
            {
                throw new ArgumentNullException("triggers");
            }

            this.blocks     = blocks;
            this.statements = statements;
            this.triggers   = triggers;
            this.manager    = null;
        }
Exemplo n.º 3
0
        /// <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);
            };
        }