Exemple #1
0
        public void OpenScript(NWN2GameScript script)
        {
            if (script == null)
            {
                throw new ArgumentNullException("script");
            }

            LaunchFlip();

            if (window.AskWhetherToSaveCurrentScript() == MessageBoxResult.Cancel)
            {
                return;
            }

            script.Demand();

            try {
                FlipScript flipScript = scriptHelper.GetFlipScript(script, Attachment.Ignore);

                if (flipScript == null)
                {
                    throw new InvalidOperationException("Script could not be understood as a Flip script.");
                }

                TriggerControl trigger;

                try {
                    trigger = scriptHelper.GetTrigger(script);
                }
                catch (ArgumentException) {
                    trigger = null;
                }

                ScriptTriggerTuple tuple = new ScriptTriggerTuple(flipScript, trigger);

                window.OpenFlipScript(tuple);

                //ActivityLog.Write(new Activity("OpenedScript","ScriptName",script.Name,"Event",triggerTextForLog));

                if (trigger != null)
                {
                    Log.WriteAction(LogAction.opened, "script", script.Name + " (attached to '" + trigger.GetLogText() + "')");
                }
                else
                {
                    Log.WriteAction(LogAction.opened, "script", script.Name);
                }
            }
            catch (Exception x) {
                throw new ApplicationException("Failed to open script '" + script.Name + "'.", x);
            }
        }
Exemple #2
0
        protected void DeleteSelectedScript()
        {
            TriggerControl t = scriptsListBox.SelectedItem as TriggerControl;

            if (t == null)
            {
                MessageBox.Show("Select a script to delete.");
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("Are you sure you want to permanently delete this script?",
                                                          "Delete script?",
                                                          MessageBoxButton.YesNo,
                                                          MessageBoxImage.Warning,
                                                          MessageBoxResult.No);

                if (result == MessageBoxResult.No)
                {
                    return;
                }

                // HACK
                // Should actually be adding ScriptTriggerTuple directly
                // to the ListBox and representing it with a DataTemplate
                // so that only the TriggerControl is displayed, but
                // that's too finicky to get into just now, so add the
                // TriggerControl directly and search for the ScriptSlotTuple
                // that possesses it.

                selected = GetOwner(t);

                try {
                    session.DeleteScript(selected.Script.Name);
                    scriptsListBox.Items.Remove(scriptsListBox.SelectedItem);

                    if (selected.Trigger != null)
                    {
                        Log.WriteAction(LogAction.deleted, "script", selected.Script.Name + " (was attached to '" + selected.Trigger.GetLogText() + "')");
                    }
                    else
                    {
                        Log.WriteAction(LogAction.deleted, "script", selected.Script.Name);
                    }
                }
                catch (Exception x) {
                    MessageBox.Show("Something went wrong when deleting script.\n" + x);
                }
            }
        }
Exemple #3
0
        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) {}
            }
        }
Exemple #4
0
        protected void OpenSelectedScript()
        {
            TriggerControl t = scriptsListBox.SelectedItem as TriggerControl;

            if (t == null)
            {
                MessageBox.Show("Select a script to open.");
            }
            else
            {
                // HACK
                // Should actually be adding ScriptTriggerTuple directly
                // to the ListBox and representing it with a DataTemplate
                // so that only the TriggerControl is displayed, but
                // that's too finicky to get into just now, so add the
                // TriggerControl directly and search for the ScriptSlotTuple
                // that possesses it.

                selected = GetOwner(t);

                try {
                    if (selected.Trigger is BlankTrigger)
                    {
                        selected.Trigger = null;
                    }
                    window.OpenFlipScript(selected.DeepCopy());

                    if (selected.Trigger != null)
                    {
                        Log.WriteAction(LogAction.opened, "script", selected.Script.Name + " (attached to '" + selected.Trigger.GetLogText() + "')");
                    }
                    else
                    {
                        Log.WriteAction(LogAction.opened, "script", selected.Script.Name);
                    }

                    Close();
                }
                catch (Exception x) {
                    MessageBox.Show("Something went wrong when opening script.\n" + x);
                }
            }
        }