Example #1
0
 public ConditionalScriptWriter(ConditionalFrame conditionalFrame)
 {
     if (conditionalFrame == null)
     {
         throw new ArgumentNullException("conditionalFrame");
     }
     this.conditionalFrame = conditionalFrame;
 }
Example #2
0
        public void Add(ConditionalFrame frame)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }

            string name = "DialogueConditionalCheck";

            if (!events.ContainsKey(name))
            {
                events.Add(name, 1);
            }
            else
            {
                events[name]++;
            }
        }
Example #3
0
        public virtual string GetLogText()
        {
            Moveable moveable = UIHelper.TryFindParent <Moveable>(this);

            if (moveable != null)
            {
                return(moveable.GetLogText());
            }

            ConditionalFrame conditionalFrame = UIHelper.TryFindParent <ConditionalFrame>(this);

            if (conditionalFrame != null)
            {
                return(conditionalFrame.GetLogText());
            }

            Spine spine = UIHelper.TryFindParent <Spine>(this);

            if (spine != null)
            {
                return("Script");                           // if we find a Spine but not a Moveable it must be the main script
            }
            TriggerBar triggerBar = UIHelper.TryFindParent <TriggerBar>(this);

            if (triggerBar != null)
            {
                return(triggerBar.GetLogText());
            }

            DependencyObject parent = UIHelper.GetParentObject(this);

            if (parent != null)
            {
                return(parent.ToString());
            }

            return("unknown");
        }
Example #4
0
        public FlipWindow(MoveableProvider provider,
                          ImageProvider imageProvider,
                          OpenDeleteScriptDelegate openDeleteScriptDelegate,
                          SaveScriptDelegate saveScriptDelegate,
                          DeserialisationHelper deserialisationHelper)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (imageProvider == null)
            {
                throw new ArgumentNullException("imageProvider");
            }
            if (openDeleteScriptDelegate == null)
            {
                throw new ArgumentNullException("openDeleteScriptDelegate");
            }
            if (saveScriptDelegate == null)
            {
                throw new ArgumentNullException("saveScriptDelegate");
            }
            if (deserialisationHelper == null)
            {
                throw new ArgumentNullException("deserialisationHelper");
            }

            this.provider                 = provider;
            this.imageProvider            = imageProvider;
            this.openDeleteScriptDelegate = openDeleteScriptDelegate;
            this.saveScriptDelegate       = saveScriptDelegate;
            ChosenDeserialisationHelper   = deserialisationHelper;

            InitializeComponent();

            /*
             * New SizedCanvas which unlike Canvas reports a desired size
             * (by overriding MeasureOverride) based on the positions of
             * its children, and hence can be used with a ScrollViewer.
             */
            mainCanvas            = new SizedCanvas();
            mainCanvas.Name       = "mainCanvas";
            mainCanvas.Background = Brushes.Transparent;
            mainCanvas.AllowDrop  = true;
            scrollViewer.Content  = mainCanvas;

            blockBox = new MoveablesPanel();
            Grid.SetRow(blockBox, 1);
            Grid.SetColumn(blockBox, 1);
            Grid.SetRowSpan(blockBox, 2);
            blockBox.PreviewDrop += ReturnMoveableToBox;

            provider.Populate(blockBox);

            mainGrid.Children.Add(blockBox);

            /*
             * Was MouseDown but ScrollViewer suppresses this event
             * so now using PreviewMouseDown. GetDragSource only
             * gets a reference to what was clicked on and where,
             * so there's no reason to believe this change would
             * affect any other program logic, and it doesn't seem to.
             */
            PreviewMouseDown += GetDragSource;
            MouseMove        += StartDrag;
            mainCanvas.Drop  += DroppedOnCanvas;

            PreviewDragEnter += CreateAdorner;
            PreviewDragOver  += UpdateAdorner;
            PreviewDragLeave += DestroyAdorner;
            PreviewDrop      += DestroyAdorner;

            // Set up trigger bar:
            triggerBar = new TriggerBar(new SpineFitter());
            triggerBar.SaveButton.Click += SaveScript;
            Canvas.SetTop(triggerBar, 30);
            Canvas.SetLeft(triggerBar, 30);
            mainCanvas.Children.Add(triggerBar);
            triggerBar.Changed += ScriptChanged;
            UpdateNaturalLanguageView(triggerBar);

            // Set up conditional frame:
            conditionalFrame = new ConditionalFrame();
            conditionalFrame.SaveButton.Click += SaveScript;
            //conditionalFrame.FinishButton.Click += LeaveConditionModeWithDialog;
            Canvas.SetTop(conditionalFrame, 30);
            Canvas.SetLeft(conditionalFrame, 30);
            mainCanvas.Children.Add(conditionalFrame);
            conditionalFrame.Changed += ScriptChanged;
            UpdateNaturalLanguageView(conditionalFrame);

            if (mainCanvas.ContextMenu == null)
            {
                mainCanvas.ContextMenu = new ContextMenu();
            }
            MenuItem paste = new MenuItem();

            paste.Header = "Paste";
            paste.Click += delegate
            {
                try {
                    if (Moveable.CopiedToClipboard != null)
                    {
                        Moveable copied   = Moveable.CopiedToClipboard.DeepCopy();
                        Point    position = Mouse.GetPosition(this);
                        copied.MoveTo(position);
                        PlaceInWorkspace(copied);
                        //ActivityLog.Write(new Activity("PlacedBlock","Block",copied.GetLogText(),"PlacedOn","Canvas"));
                        Log.WriteAction(LogAction.placed, "block", copied.GetLogText() + " on canvas");
                    }
                }
                catch (Exception x) {
                    MessageBox.Show("Something went wrong when copy-pasting.\n\n" + x);
                }
            };
            mainCanvas.ContextMenu.Items.Add(paste);
            mainCanvas.ContextMenuOpening += delegate
            {
                paste.IsEnabled = (Moveable.CopiedToClipboard != null);
            };

            LeaveConditionMode();
        }