Exemple #1
0
    protected void OnBrushLoad(object o, EventArgs args)
    {
        try {
            if (tilemap == null)
            {
                ErrorDialog.ShowError("Brush: No tilemap selected",
                                      "You have to select a tilemap before you load a brush");
                return;
            }

            fileChooser.Title  = "Choose a Brush";
            fileChooser.Action = Gtk.FileChooserAction.Open;
            fileChooser.SetCurrentFolder(Settings.Instance.LastBrushDir);
            fileChooser.Filter = fileChooser.Filters[3];
            int result = fileChooser.Run();
            fileChooser.Hide();
            if (result != (int)Gtk.ResponseType.Ok)
            {
                return;
            }
            Settings.Instance.LastBrushDir = fileChooser.CurrentFolder;
            Settings.Instance.Save();
            string brushFile = fileChooser.Filename;

            TileBrushTool editor = new TileBrushTool(this, level.Tileset, brushFile);
            SetTool(editor);
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }
    }
Exemple #2
0
 private void Load(string fileName)
 {
     try {
         //undoSnapshots.Clear();
         UndoManager.Clear();
         Level newLevel = (Level)serializer.Read(fileName);
         if (newLevel.Version < 2)
         {
             ErrorDialog.ShowError("Couldn't load level: Old Level Format not supported",
                                   "Supertux-Editor does not support Supertux-0.1.x levels");
             return;
         }
         CurrentLevel  = newLevel;
         this.fileName = fileName;
         Settings.Instance.addToRecentDocuments(fileName);
         Settings.Instance.Save();
         UpdateUndoButtons();
         UpdateTitlebar();
         UpdateRecentDocuments();
         UndoManager.MarkAsSaved();
         ToolButtonCamera.Sensitive = true;
     } catch (Exception e) {
         ErrorDialog.Exception("Error loading level", e);
     }
 }
Exemple #3
0
    /// <summary>Run the current version of the level in Tuxjunior</summary>
    protected void OnPlay(object o, EventArgs args)
    {
        if (level == null)
        {
            return;
        }

        if (!File.Exists(Settings.Instance.TuxjuniorExe))
        {
            ErrorDialog.ShowError("The TuxJunior binary does not seem to exist." + Environment.NewLine +
                                  "Please set the correct location of it in the settings.");
            return;
        }
        try {
            string tempName = System.IO.Path.GetTempPath();

            if (level.isWorldmap)
            {
                tempName += "/tuxjunior-editor.tmp.stwm";
            }
            else
            {
                tempName += "/tuxjunior-editor.tmp.stl";
            }

            serializer.Write(tempName, level);
            Process.Start(Settings.Instance.TuxjuniorExe, "\"" + tempName + "\"");
        } catch (Exception e) {
            ErrorDialog.Exception("Couldn't start tuxjunior", e);
        }
    }
Exemple #4
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);
        }
    }
Exemple #5
0
 public void SetObject(object NewObject, string title)
 {
     try {
         if (Object != null && NewObject != null && Object.GetType() == NewObject.GetType())
         {
             foreach (ICustomSettingsWidget wg in customWidgets)                     //notify all custom widgets
             {
                 wg.ChangeObject(NewObject);
             }
             this.Object = NewObject;
             foreach (FieldOrProperty field in fieldTable)                           //and also all self-managed widgets
             {
                 OnFieldChanged(NewObject, field, null);
             }
             titleLabel.Markup = "<b>" + title + "</b>";
         }
         else
         {
             CreatePropertyWidgets(title, NewObject);
             this.Object = NewObject;
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Exemple #6
0
 private void OnResize(object o, EventArgs args)
 {
     try {
         new ResizeDialog(sector, application.CurrentTilemap);
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Exemple #7
0
 private void OnResizeActivated(object o, EventArgs args)
 {
     try {
         new ResizeDialog(sector);
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
    private void OnClone(object o, EventArgs args)
    {
        if (activeObject == null)
        {
            return;
        }

        try {
            object      newObject  = ((ICloneable)activeObject).Clone();
            IGameObject gameObject = (IGameObject)newObject;
            sector.Add(gameObject, gameObject.GetType().Name + " (clone)");
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }
    }
Exemple #9
0
    /// <summary>Run the current version of the level in Supertux</summary>
    protected void OnPlay(object o, EventArgs args)
    {
        if (level == null)
        {
            return;
        }

        try {
            string tempName = System.IO.Path.GetTempPath();

            if (level.isWorldmap)
            {
                tempName += "/supertux-editor.tmp.stwm";
            }
            else
            {
                tempName += "/supertux-editor.tmp.stl";
            }

            serializer.Write(tempName, level);

            Process supertux_process = new Process();
            supertux_process.StartInfo.FileName  = Settings.Instance.SupertuxExe;
            supertux_process.StartInfo.Arguments = "\"" + tempName + "\"";
            String working_dir = System.IO.Path.GetDirectoryName(Settings.Instance.SupertuxExe);
            if (working_dir != null)
            {
                supertux_process.StartInfo.WorkingDirectory = working_dir;
            }

            /*
             * Avoid problems with xdg-open being used wrongly and
             * exceptions not being thrown. These problems happen
             * when UseShellExecute = true.
             */
            supertux_process.StartInfo.UseShellExecute = false;

            supertux_process.Start();
        } catch (System.ComponentModel.Win32Exception /*e*/) {
            ErrorDialog.ShowError("The SuperTux binary does not seem to exist." + Environment.NewLine +
                                  "Please set the correct location of it in the settings." + Environment.NewLine +
                                  "(The current setting is `" + Settings.Instance.SupertuxExe + "')");
        } catch (Exception e) {
            ErrorDialog.Exception("Couldn't start supertux. You might try checking the configuration value for the path to the SuperTux binary.", e);
        }
    }
Exemple #10
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();
    }
Exemple #11
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);
     }
 }
Exemple #12
0
 private void Remove(IGameObject Object, bool NoUndo, ref Command command)
 {
     if (!NoUndo)
     {
         command = new ObjectRemoveCommand(
             "Delete Object " + Object,
             Object,
             this);
     }
     GameObjects.Remove(Object);
     try {
         if (ObjectRemoved != null)
         {
             ObjectRemoved(this, Object);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Exemple #13
0
 private void Add(IGameObject Object, string type, bool NoUndo, ref Command command)
 {
     if (!NoUndo)
     {
         command = new ObjectAddCommand(
             "Created Object '" + type + "'",
             Object,
             this);
     }
     GameObjects.Add(Object);
     try {
         if (ObjectAdded != null)
         {
             ObjectAdded(this, Object);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Exemple #14
0
    /// <summary>Create a new blank level</summary>
    protected void OnNew(object o, EventArgs args)
    {
        if (!ChangeConfirm("create a blank level"))
        {
            return;
        }

        try {
            UndoManager.Clear();
            Level level = LevelUtil.CreateLevel();
            ChangeCurrentLevel(level);
        } catch (Exception e) {
            ErrorDialog.Exception("Couldn't create new level", e);
        }
        fileName = null;
        UpdateUndoButtons();
        UpdateTitlebar();
        UndoManager.MarkAsSaved();
    }
Exemple #15
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);
     }
 }
Exemple #16
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();
    }
Exemple #17
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);
     }
 }
Exemple #18
0
    protected void Save(bool chooseName)
    {
        if (fileName == null)
        {
            chooseName = true;
        }

        if (level == null)
        {
            return;
        }

        if (chooseName)
        {
            fileChooser.Title  = "Select file to save Level";
            fileChooser.Action = Gtk.FileChooserAction.Save;
            fileChooser.SetCurrentFolder(Settings.Instance.LastDirectoryName);
            fileChooser.Filter = fileChooser.Filters[(level.isWorldmap)?2:1];
            int result = fileChooser.Run();
            fileChooser.Hide();
            if (result != (int)Gtk.ResponseType.Ok)
            {
                return;
            }
            Settings.Instance.LastDirectoryName = fileChooser.CurrentFolder;
            Settings.Instance.addToRecentDocuments(fileChooser.Filename);
            Settings.Instance.Save();
            UpdateRecentDocuments();
            fileName = fileChooser.Filename;
        }
        QACheck.ReplaceDeprecatedTiles(level);

        try {
            serializer.Write(fileName, level);
        } catch (Exception e) {
            ErrorDialog.Exception("Couldn't save level", e);
        }

        UndoManager.MarkAsSaved();
        UpdateTitlebar();
    }
Exemple #19
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);
     }
 }
Exemple #20
0
    private void OnMotionNotify(object o, MotionNotifyEventArgs args)
    {
        try {
            Vector pos = new Vector((float)args.Event.X, (float)args.Event.Y);
            MousePos = MouseToWorld(pos);

            if (dragging)
            {
                SetTranslation(dragStartTranslation +
                               (pos - dragStartMouse) / Zoom);
            }
            else if (Editor != null)
            {
                Editor.OnMouseMotion(MousePos, args.Event.State);
            }

            args.RetVal = true;
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }
    }
Exemple #21
0
    private void OnButtonRelease(object o, ButtonReleaseEventArgs args)
    {
        try {
            MousePos = MouseToWorld(
                new Vector((float)args.Event.X, (float)args.Event.Y));

            if (args.Event.Button == 2)
            {
                dragging = false;
                QueueDraw();
            }
            else if (Editor != null)
            {
                Editor.OnMouseButtonRelease(MousePos, (int)args.Event.Button, args.Event.State);
            }

            args.RetVal = true;
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }
    }
Exemple #22
0
    protected void OnBrushSaveAs(object o, EventArgs args)
    {
        try {
            ITool editor = sectorSwitchNotebook.CurrentRenderer.Editor;
            if (!(editor is TileBrushTool))
            {
                ErrorDialog.ShowError("No brush editor active",
                                      "You need to open a brush before you can save changes to it");
                return;
            }
            TileBrushTool brushTool = (TileBrushTool)editor;

            fileChooser.Title  = "Choose a Brush";
            fileChooser.Action = Gtk.FileChooserAction.Save;
            fileChooser.SetCurrentFolder(Settings.Instance.LastBrushDir);
            fileChooser.Filter = fileChooser.Filters[3];
            int result = fileChooser.Run();
            fileChooser.Hide();
            if (result != (int)Gtk.ResponseType.Ok)
            {
                return;
            }
            Settings.Instance.LastBrushDir = fileChooser.CurrentFolder;
            Settings.Instance.Save();
            string brushFile = fileChooser.Filename;

            brushTool.Brush.saveToFile(brushFile);

            /*
             * try {
             *      LispSerializer serializer = new LispSerializer(typeof(Brush));
             *      serializer.Write(brushFile, brushEditor.Brush);
             * } catch(Exception e) {
             *      ErrorDialog.Exception("Couldn't save brush", e);
             * }
             */
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }
    }
Exemple #23
0
 private void OnEntryChanged(object o, EventArgs args)
 {
     try {
         Gtk.Entry       entry = (Gtk.Entry)o;
         FieldOrProperty field = fieldTable[widgetTable.IndexOf(entry)];
         if (field.Type == typeof(string))
         {
             return;
         }
         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();
             }
         }
         else if (field.Type == typeof(int))
         {
             int parsed = Int32.Parse(entry.Text);
             if (parsed.ToString() != entry.Text)
             {
                 entry.Text = parsed.ToString();
             }
         }
         else
         {
             throw new ApplicationException(
                       "PropertiesView.OnEntryChanged, \"" + 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.");
         }
     } catch (FormatException fe) {
         errorLabel.Text = fe.Message;
         return;
     } catch (Exception e) {
         ErrorDialog.Exception(e);
         return;
     }
     errorLabel.Text = String.Empty;
 }
Exemple #24
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);
    }
Exemple #25
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);
     }
 }
 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;
         }
     }
 }
Exemple #27
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;
 }