Example #1
0
    public void OnMouseButtonRelease(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null)
        {
            return;
        }

        UpdateMouseTilePos(mousePos);

        if ((button == 1) && drawing)
        {
            drawing = false;

            // use backup of Tilemap to create undo command
            TilemapModifyCommand command = new TilemapModifyCommand(
                ActionName + " on Tilemap \"" + application.CurrentTilemap.Name + "\"",
                application.CurrentTilemap,
                tilemapBackup,
                application.CurrentTilemap.SaveState());
            UndoManager.AddCommand(command);
        }
        if ((button == 3) && selecting)
        {
            UpdateSelection();

            SelectionDoneAction(selection);

            selection.FireChangedEvent();
            selecting = false;
        }

        Redraw();
    }
Example #2
0
    private void OnComboBoxChanged(object o, EventArgs args)
    {
        try {
            ComboBoxEntry comboBox = (ComboBoxEntry)o;
            string        s        = comboBox.ActiveText;

            // strip off comments from licenseTemplateTexts
            if (s == "non-redistributable (forbid sharing and modification of this level)")
            {
                s = s.Substring(0, s.IndexOf(" ("));
            }
            if (s == "GPL 2+ / CC-by-sa 3.0 (allow sharing and modification of this level)")
            {
                s = s.Substring(0, s.IndexOf(" ("));
            }

            if (s != (string)Field.GetValue(Object))                    //no change => no undo item
            {
                PropertyChangeCommand command = new PropertyChangeCommand(
                    "Changed value of " + Field.Name,
                    Field,
                    Object,
                    s);
                command.Do();
                UndoManager.AddCommand(command);
            }
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }
    }
    private void OnChooseColor(object sender, EventArgs args)
    {
        Drawing.Color col = new Drawing.Color();
        col.Red   = ((float)colorButton.Color.Red) / 65535f;
        col.Blue  = ((float)colorButton.Color.Blue) / 65535f;
        col.Green = ((float)colorButton.Color.Green) / 65535f;
        col.Alpha = 1f;
        if (useAlpha)
        {
            col.Alpha = ((float)colorButton.Alpha) / 65535f;
        }

        if (col != (Drawing.Color)Field.GetValue(Object))
        {
            PropertyChangeCommand command = new PropertyChangeCommand(
                "Changed value of " + Field.Name,
                Field,
                Object,
                col);
            command.Do();
            UndoManager.AddCommand(command);
            //Console.WriteLine("ChooseColorWidget change col r{0},g{1},b{2},a{3}", col.Red, col.Green, col.Blue, col.Alpha);
            //Console.WriteLine("ChooseColorWidget change gtk color r{0},g{1},b{2},a{3}", colorButton.Color.Red, colorButton.Color.Green, colorButton.Color.Blue, colorButton.Alpha);
        }
    }
Example #4
0
    private void OnShiftLeft(object o, EventArgs args)
    {
        Command command = new PathShiftCommand("Path shifted backwards", path, -1);

        command.Do();
        UndoManager.AddCommand(command);
        Redraw();
    }
Example #5
0
    private void OnShiftRight(object o, EventArgs args)
    {
        Command command = new PathShiftCommand("Path shifted forward", path, 1);

        command.Do();
        UndoManager.AddCommand(command);
        Redraw();
    }
Example #6
0
    public void DeleteCurrentPath()
    {
        SetToolSelect();
        Command command = new PropertyChangeCommand("Deleted path from " + iPathToEdit.GetType().ToString(),
                                                    FieldOrProperty.Lookup(iPathToEdit.GetType().GetProperty("Path")), iPathToEdit, null);

        command.Do();
        UndoManager.AddCommand(command);
    }
Example #7
0
    public void Remove(IGameObject Object, bool NoUndo)
    {
        Command command = null;

        Remove(Object, NoUndo, ref command);
        if (!NoUndo)
        {
            UndoManager.AddCommand(command);
        }
    }
Example #8
0
    private void OnDelete(object o, EventArgs args)
    {
        Command command = new SortedListRemoveCommand <Path.Node>("Added Path node", path, field, selectedNode);

        command.Do();
        UndoManager.AddCommand(command);
        selectedNode = null;
        dragging     = false;
        Redraw();
    }
Example #9
0
    public void OnMouseButtonRelease(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (dragging && selectedNode.Pos != originalPos)
        {
            Command command = new PropertyChangeCommand("Moved Path Node", FieldOrProperty.Lookup(typeof(Path.Node).GetProperty("Pos")), selectedNode, selectedNode.Pos, originalPos);
            UndoManager.AddCommand(command);
        }

        dragging = false;
    }
Example #10
0
    public void Add(IGameObject Object, string type, bool NoUndo)
    {
        Command command = null;

        Add(Object, type, NoUndo, ref command);
        if (!NoUndo)
        {
            UndoManager.AddCommand(command);
        }
    }
Example #11
0
    private void OnDragDataReceived(object o, DragDataReceivedArgs args)
    {
        string data = System.Text.Encoding.UTF8.GetString(args.SelectionData.Data);

        if (!badguySprites.ContainsKey(data))
        {
            badguySprites.Add(data, CrateSprite(data));
        }

        if (data != "")
        {
            if (badguys.Count == 0)
            {
                Gtk.Drag.SourceSet(this, Gdk.ModifierType.Button1Mask,
                                   source_table, DragAction.Move);
            }

            Command command;
            if (draggedID > NONE)                       //We were moving
            {
                if (SelectedObjectNr > draggedID)
                {
                    SelectedObjectNr--;
                }
                if (SelectedObjectNr == draggedID)
                {
                    draggedID = NONE;
                    return;
                }
                command = new SortedListMoveCommand <string>(
                    "Changed position of badguy  \"" + data + "\" in the queue",
                    _object, field, draggedID, SelectedObjectNr);
                draggedID = NONE;
            }
            else                                        //We were adding
            {
                command = new SortedListAddCommand <string>(
                    "Added badguy \"" + data + "\" into the queue",
                    _object, field, data, SelectedObjectNr);
            }
            command.Do();
            UndoManager.AddCommand(command);

            dragging = false;

            //update heigth
            SetSizeRequest(-1, ROW_HEIGHT * ((badguys.Count - 1) / TILES_PER_ROW + 1));
        }


        Gtk.Drag.Finish(args.Context, true, false, args.Time);
    }
Example #12
0
    private void OnDeletePath(object o, EventArgs args)
    {
        IPathObject pathObject = (IPathObject)selectedObjects[0];

        if (pathObject.Path != null)
        {
            Command command = new PropertyChangeCommand("Removed path from " + selectedObjects[0],
                                                        LispReader.FieldOrProperty.Lookup(typeof(IPathObject).GetProperty("Path")),
                                                        selectedObjects[0],
                                                        null);
            command.Do();
            UndoManager.AddCommand(command);
        }
    }
Example #13
0
    private void OnDeletePath(object o, EventArgs args)
    {
        IPathObject pathObject = (IPathObject)application.CurrentTilemap;

        if (pathObject.Path != null)
        {
            Command command = new PropertyChangeCommand("Removed path of Tilemap " + application.CurrentTilemap.Name + " (" + application.CurrentTilemap.ZPos + ")",
                                                        FieldOrProperty.Lookup(typeof(Tilemap).GetProperty("Path")),
                                                        application.CurrentTilemap,
                                                        null);
            command.Do();
            UndoManager.AddCommand(command);
        }
    }
Example #14
0
 private void OnDelete(object o, EventArgs args)
 {
     if (path.Nodes.Count > 1)
     {
         Command command = new SortedListRemoveCommand <Path.Node>("Deleted Path node", path, field, selectedNode);
         command.Do();
         UndoManager.AddCommand(command);
         selectedNode = null;
         dragging     = false;
         Redraw();
     }
     else
     {
         Application.EditorApplication.DeleteCurrentPath();
     }
 }
Example #15
0
    private void OnDelete(object o, EventArgs args)
    {
        List <IObject> Objects  = new List <IObject>(selectedObjects);          //OnObjectRemoved() tries to access selectedObject and that's not possible during "foreach"
        List <Command> commands = new List <Command>();
        Command        command  = null;

        foreach (IGameObject selectedObject in Objects)
        {
            sector.Remove(selectedObject, ref command);
            commands.Add(command);
        }
        if (commands.Count > 1)                                                 //If there are more items, then create multiCommand, otherwise keep single one
        {
            command = new MultiCommand("Deleted " + commands.Count.ToString() + " objects", commands);
        }
        UndoManager.AddCommand(command);
    }
Example #16
0
    protected void OnOk(object o, EventArgs args)
    {
        try {
            PropertyChangeCommand command = new PropertyChangeCommand(
                "Changed value of " + field.Name,
                field,
                object_,
                scriptEditor.Buffer.Text);
            command.Do();
            UndoManager.AddCommand(command);
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }

        field.Changed -= OnFieldChanged;
        scriptDialog.Hide();
    }
Example #17
0
 private void OnCreateNew(object o, EventArgs args)
 {
     try {
         Sector           sector  = LevelUtil.CreateSector("NewSector");
         SectorAddCommand command = new SectorAddCommand(
             "Added sector",
             sector,
             level);
         command.OnSectorAdd    += OnSectorAdd;
         command.OnSectorRemove += OnSectorRemove;
         command.Do();
         UndoManager.AddCommand(command);
         OnSectorChanged(level, sector);
         OnPropertiesActivated(null, null);
     } catch (Exception e) {
         ErrorDialog.Exception("Couldn't create new sector", e);
     }
 }
Example #18
0
    private void OnDragEnd(object o, DragEndArgs args)
    {
        if (draggedID > NONE)                   //Widget.DragFailed is not aviable for windows users
        {
            Command command = new SortedListRemoveCommand <string>(
                "Removed badguy \"" + draggedBadguy + "\" from the queue",
                _object, field, draggedID);
            command.Do();
            UndoManager.AddCommand(command);

            draggedID     = NONE;
            draggedBadguy = "";
            dragging      = false;
            if (badguys.Count == 0)
            {
                Gtk.Drag.SourceUnset(this);
            }
        }
    }
Example #19
0
 public void Add(IGameObject Object, string type, bool NoUndo)
 {
     if (!NoUndo)
     {
         ObjectAddCommand command = new ObjectAddCommand(
             "Created Object '" + type + "'",
             Object,
             this);
         UndoManager.AddCommand(command);
     }
     GameObjects.Add(Object);
     try {
         if (ObjectAdded != null)
         {
             ObjectAdded(this, Object);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #20
0
 public void Remove(IGameObject Object, bool NoUndo)
 {
     if (!NoUndo)
     {
         ObjectRemoveCommand command = new ObjectRemoveCommand(
             "Delete Object " + Object,
             Object,
             this);
         UndoManager.AddCommand(command);
     }
     GameObjects.Remove(Object);
     try {
         if (ObjectRemoved != null)
         {
             ObjectRemoved(this, Object);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #21
0
    private void OnDeleteActivated(object o, EventArgs args)
    {
        // Don't remove sector if it is the only one.
        if (level.Sectors.Count == 1)
        {
            application.PrintStatus("A level has to have at least one sector.");
            return;
        }

        application.PrintStatus("Sector '" + sector.Name + "' removed.");
        SectorRemoveCommand command = new SectorRemoveCommand(
            "Removed sector",
            sector,
            level);

        command.OnSectorAdd    += OnSectorAdd;
        command.OnSectorRemove += OnSectorRemove;
        command.Do();
        UndoManager.AddCommand(command);
    }
Example #22
0
    protected void OnOk(object o, EventArgs args)
    {
        try {
            uint newWidth  = UInt32.Parse(WidthEntry.Text);
            uint newHeight = UInt32.Parse(HeightEntry.Text);
            //application.TakeUndoSnapshot( "Sector resized to " + newWidth + "x" + newHeight);
            SectorSizeChangeCommand command = new SectorSizeChangeCommand(
                undoTitleBase + " resized to " + newWidth + "x" + newHeight,
                sector,
                tilemap,
                newWidth,
                newHeight);
            command.Do();
            UndoManager.AddCommand(command);
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }

        resizeDialog.Hide();
    }
Example #23
0
 private void OnComboBoxChanged(object o, EventArgs args)
 {
     try {
         ComboBox comboBox = (ComboBox)o;
         string   newText  = comboBox.ActiveText;
         string   oldText  = (string)Field.GetValue(Object);
         if (newText != oldText)
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + Field.Name,
                 Field,
                 Object,
                 newText);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #24
0
 private void OnCheckButtonToggled(object o, EventArgs args)
 {
     try {
         Gtk.CheckButton checkButton = (Gtk.CheckButton)o;
         FieldOrProperty field       = fieldTable[widgetTable.IndexOf(checkButton)];
         bool            oldValue    = (bool)field.GetValue(Object);
         bool            newValue    = checkButton.Active;
         if (oldValue != newValue)                   //no change => no Undo action
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 newValue);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #25
0
    private void OnClone(object o, EventArgs args)
    {
        List <Command> commands = new List <Command>();
        Command        command  = null;

        foreach (IGameObject selectedObject in selectedObjects)
        {
            try {
                object      newObject  = ((ICloneable)selectedObject).Clone();
                IGameObject gameObject = (IGameObject)newObject;
                sector.Add(gameObject, gameObject.GetType().Name + " (clone)", ref command);
                commands.Add(command);
            } catch (Exception e) {
                ErrorDialog.Exception(e);
            }
        }
        if (commands.Count > 1)                                                 //If there are more items, then create multiCommand, otherwise keep single one
        {
            command = new MultiCommand("Cloned " + commands.Count.ToString() + " objects", commands);
        }
        UndoManager.AddCommand(command);
    }
Example #26
0
 private void OnComboBoxChanged(object o, EventArgs args)
 {
     try {
         Gtk.ComboBox    comboBox = (Gtk.ComboBox)o;
         FieldOrProperty field    = fieldTable[widgetTable.IndexOf(comboBox)];
         // Parse the string back to enum.
         Enum oldValue = (Enum)field.GetValue(Object);
         Enum newValue = (Enum)Enum.Parse(field.Type, comboBox.ActiveText);
         if (!oldValue.Equals(newValue))                     //no change => no Undo action
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 newValue);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #27
0
    public void OnMouseButtonRelease(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null)
        {
            return;
        }

        UpdateMouseTilePos(mousePos);

        if (button == 3 && state == State.SELECTING)
        {
            UpdateSelection();

            SelectionDoneAction(selection);

            selection.FireChangedEvent();
        }

        if ((button == 1) && (state != State.NONE))
        {
            if (state == State.FILLING)
            {
                UpdateSelection();

                PerformActionOnSelection(Modifiers);
            }

            // use backup of Tilemap to create undo command
            TilemapModifyCommand command = new TilemapModifyCommand(
                ActionName + " on Tilemap \"" + application.CurrentTilemap.Name + "\"",
                application.CurrentTilemap,
                tilemapBackup,
                application.CurrentTilemap.SaveState());
            UndoManager.AddCommand(command);
        }
        state = State.NONE;

        Redraw();
    }
Example #28
0
    public void OnMouseButtonRelease(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (dragging)
        {
            dragging = false;

            if (mousePos != pressPoint)
            {
                //moveStarted = false;
                ObjectAreaChangeCommand command = new ObjectAreaChangeCommand(
                    "Moved Object " + activeObject,
                    originalArea,
                    getNewPosition(mousePos, SnapValue(Modifiers)),
                    activeObject);
                UndoManager.AddCommand(command);
                moveObject(mousePos, SnapValue(Modifiers));
            }
            else
            {
                MakeActive(FindNext(mousePos));
                Redraw();
            }
        }
    }
 private void OnEntryChangeDone(object o, FocusOutEventArgs args)
 {
     try {
         Entry entry = (Entry)o;
         if ((string)Field.GetValue(Object) == entry.Text)
         {
             return;
         }
         PropertyChangeCommand command = new PropertyChangeCommand(
             "Changed value of " + Field.Name,
             Field,
             Object,
             entry.Text);
         command.Do();
         UndoManager.AddCommand(command);
     } catch (Exception e) {
         ErrorDialog.Exception(e);
         string val = (string)Field.GetValue(Object);
         if (val != null)
         {
             entry.Text = val;
         }
     }
 }
Example #30
0
 private void OnEntryChangeDone(object o, Gtk.FocusOutEventArgs args)
 {
     try {
         Gtk.Entry             entry = (Gtk.Entry)o;
         FieldOrProperty       field = fieldTable[widgetTable.IndexOf(entry)];
         PropertyChangeCommand command;
         if (field.Type == typeof(string))
         {
             if ((string)field.GetValue(Object) == entry.Text)
             {
                 return;
             }
             command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 entry.Text);
         }
         else if (field.Type == typeof(float))
         {
             float parsed = Single.Parse(entry.Text);
             if (parsed.ToString() != entry.Text && parsed.ToString() + "." != entry.Text)
             {
                 entry.Text = parsed.ToString();
             }
             if ((float)field.GetValue(Object) == parsed)
             {
                 return;
             }
             command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 parsed);
         }
         else if (field.Type == typeof(int))
         {
             int parsed = Int32.Parse(entry.Text);
             if (parsed.ToString() != entry.Text)
             {
                 entry.Text = parsed.ToString();
             }
             if ((int)field.GetValue(Object) == parsed)
             {
                 return;
             }
             command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 parsed);
         }
         else
         {
             throw new ApplicationException(
                       "PropertiesView.OnEntryChangeDone, \"" + field.Type.FullName + "\" is not implemented yet. " +
                       "If you are a developer, please fix it, else report this full error message and what you did to cause it to the supertux developers.");
         }
         command.Do();
         UndoManager.AddCommand(command);
     } catch (FormatException fe) {
         errorLabel.Text = fe.Message;
         return;
     } catch (Exception e) {
         ErrorDialog.Exception(e);
         return;
     }
     errorLabel.Text = String.Empty;
 }