コード例 #1
0
ファイル: NewMapDialog.cs プロジェクト: hallgeirl/Hiage
        public NewMapDialog(EditorModel model)
        {
            this.Build ();

            int counter = 0;
            foreach (string t in model.ResourceManager.Tilesets)
                comboTileset.InsertText(counter++, t);
            comboTileset.Active = 0;

            spinXOffset.Value = 0;
            spinYOffset.Value = 0;
        }
コード例 #2
0
ファイル: MapEditorState.cs プロジェクト: hallgeirl/Hiage
        public MapEditorState(Game game, EditorModel model)
            : base(game)
        {
            this.model = model;
            model.AddListener(this);

            display = game.Display;
            renderer = display.Renderer;
            input = game.Input;

            model.Display = display;
            model.Zoom = display.Zoom;
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: hallgeirl/Hiage
        public static void Main(string[] args)
        {
            //The model that is shared between the engine part and GUI part of the map editor
            EditorModel model = new EditorModel();

            //Start up the engine interaction thread (rendering and such)
            InteractThread thread = new InteractThread(model);
            Thread engineThread = new Thread(new ThreadStart(thread.MainLoop));
            engineThread.Start();

            //Make sure the resource manager has been set before continuing, and ensure that the opengl context has been set up.
            while ((model.ResourceManager == null || !Renderer.Ready) && model.Running);

            if (model.Running)
            {
                //Initialize and run the GUI
                Application.Init ();
                MainWindow win = new MainWindow (model);
                win.Show ();
                Application.Run ();
            }
        }
コード例 #4
0
ファイル: ObjectChooser.cs プロジェクト: hallgeirl/Hiage
        public ObjectChooser(EditorModel model)
            : base(Gtk.WindowType.Toplevel)
        {
            this.Build ();

            Deletable = false; //Why doesn't this work?

            //Prevent this window from closing
            DeleteEvent += delegate(object o, Gtk.DeleteEventArgs args) {
                args.RetVal = true;
            };

            TreeViewColumn nameColumn = new TreeViewColumn();
            CellRendererText nameCell = new CellRendererText();
            nameColumn.Title = "Object name";
            nameColumn.PackStart(nameCell, true);
            nameColumn.AddAttribute(nameCell, "text", 0);

            listObjects.AppendColumn(nameColumn);

            ListStore objectStore = new ListStore(typeof(string));
            listObjects.Model = objectStore;

            //Set up object list
            foreach (string o in model.ResourceManager.Objects)
            {
                objectStore.AppendValues(o);
            }

            listObjects.CursorChanged += delegate(object sender, EventArgs e) {
                TreeIter iter;
                if (listObjects.Selection.GetSelected(out iter))
                {
                    model.CurrentObject = (objectStore.GetValue(iter, 0) as string);
                }
            };
        }
コード例 #5
0
ファイル: MapEditorState.cs プロジェクト: hallgeirl/Hiage
        /*public override void Initialize(Game game)
        {
            display = game.Display;
            renderer = display.Renderer;
            input = game.Input;

            model.Display = display;
            model.Zoom = display.Zoom;
        }*/
        public void ModelChanged(EditorModel.VariableName v, object oldValue, object newValue)
        {
            switch (v)
            {
            case EditorModel.VariableName.Background:
                if (!string.IsNullOrEmpty((string)newValue))
                    Schedule(delegate {background = new ParallaxBackground(model.ResourceManager.GetTexture((string)newValue), 1, 0.5, model.Display); });
                break;
            }
        }
コード例 #6
0
ファイル: InteractThread.cs プロジェクト: hallgeirl/Hiage
 //Initialize
 public InteractThread(EditorModel model)
 {
     this.model = model;
 }
コード例 #7
0
ファイル: MainWindow.cs プロジェクト: hallgeirl/Hiage
    //Handle any updates to the common model
    public void ModelChanged(EditorModel.VariableName var, object oldValue, object newValue)
    {
        switch (var)
        {
        case EditorModel.VariableName.Background:
            //Find the background in the combobox and set that element as active
            Application.Invoke(delegate {
                TreeIter iter;
                comboBackgrounds.Model.GetIterFirst(out iter);
                bool found = false;
                do
                {
                    GLib.Value thisRow = new GLib.Value();
                    comboBackgrounds.Model.GetValue(iter, 0, ref thisRow);
                    if ((thisRow.Val as string).Equals(newValue))
                    {
                        comboBackgrounds.SetActiveIter(iter);
                        found = true;
                        break;
                    }
                } while (comboBackgrounds.Model.IterNext (ref iter));
                if (!found)
                {
                    Log.Write("Background \"" + newValue + "\" was not found in combo box.", Log.WARNING);
                }
            });
            break;
        case EditorModel.VariableName.MousePosition:
            Vector v = (Vector)newValue;
            Application.Invoke(delegate {
                Vector tilePosition = null;
                if (model.TileMap != null)
                {
                    try
                    {
                        tilePosition = model.TileMap.WorldToTilePosition(v);
                    }
                    catch (IndexOutOfRangeException)
                    {
                    }
                }
                labelMousePos.Text = "(" + v.X.ToString("N2") + ", " + v.Y.ToString("N2") + ")" + (tilePosition != null ? ", tile (" + tilePosition.X + "," + tilePosition.Y + ")" : "");
            });
            break;

        case EditorModel.VariableName.TileMap:
            TileMap tm = (TileMap)newValue;
            if (tm != null)
            {
                Application.Invoke(delegate {
                    labelWidth.Text = "" + model.TileMap.Width;
                    labelHeight.Text = "" + model.TileMap.Height;
                    labelLayers.Text = "" + model.TileMap.Layers;
                    spinDrawToLayer.SetRange(1, tm.Layers);
                    spinDrawToLayer.Value = 1;
                });
            }
            break;

        case EditorModel.VariableName.MapID:
            if (entryMapID.Text != (string)newValue)
            {
                Application.Invoke(delegate {
                    entryMapID.Text = (string)newValue;
                });
            }
            break;

        case EditorModel.VariableName.Changed:
            UpdateTitle();
            break;

        case EditorModel.VariableName.Filename:
            UpdateTitle();
            break;
        }
    }
コード例 #8
0
ファイル: MainWindow.cs プロジェクト: hallgeirl/Hiage
    public MainWindow(EditorModel model)
        : base(Gtk.WindowType.Toplevel)
    {
        //Set the model, and add this window as a listener to the model
        this.model = model;
        model.AddListener(this);
        tileChooserWindow = new TileChooser(model);
        objectChooserWindow = new ObjectChooser(model);
        tileChooserWindow.Visible = false;
        objectChooserWindow.Visible = false;

        //Build window from design
        Build();

        Title = WINDOW_TITLE;

        #region Event handlers
        #region Radio buttons
        //Set up event handlers
        radioDrawTiles.Toggled += delegate {
            if (radioDrawTiles.Active)
            {
                model.CurrentTool = EditorModel.Tool.DrawTile;
                tileChooserWindow.Visible = true;
            }
            else
                tileChooserWindow.Visible = false;
        };

        radioCreateObjects.Toggled += delegate {
            if (radioCreateObjects.Active)
            {
                model.CurrentTool = EditorModel.Tool.CreateObject;
                objectChooserWindow.Visible = true;
            }
            else
                objectChooserWindow.Visible = false;
        };

        radioSelectObjects.Toggled += delegate {
            if (radioSelectObjects.Active)
            {
                model.CurrentTool = EditorModel.Tool.SelectObject;
            }
        };

        radioDrawTiles.Toggle();
        #endregion

        #region Background, draw-to-layer spin

        comboBackgrounds.Changed += delegate(object sender, EventArgs e) {
            model.Background = ((ComboBox)sender).ActiveText;
            Log.Write("Changed background to " + ((ComboBox)sender).ActiveText);
        };

        spinDrawToLayer.Changed += delegate {
            model.DrawToLayer = spinDrawToLayer.ValueAsInt;
        };

        entryMapID.Changed += delegate {
            model.MapID = entryMapID.Text;
        };

        #endregion

        #region Grid snapping
        // default value for snapping
        spinGridOffsetX.Value = 0;
        spinGridOffsetY.Value = 0;

        model.SnapToGrid = checkSnapToGrid.Active;
        model.GridSizeX = spinGridSizeX.ValueAsInt;
        model.GridSizeY = spinGridSizeY.ValueAsInt;
        model.GridOffsetX = spinGridOffsetX.ValueAsInt;
        model.GridOffsetY = spinGridOffsetY.ValueAsInt;

        checkSnapToGrid.Toggled += delegate {
            model.SnapToGrid = checkSnapToGrid.Active;
        };

        spinGridSizeX.Changed += delegate {
            model.GridSizeX = spinGridSizeX.ValueAsInt;
        };
        spinGridSizeY.Changed += delegate {
            model.GridSizeY = spinGridSizeY.ValueAsInt;
        };
        spinGridOffsetX.Changed += delegate {
            model.GridOffsetX = spinGridOffsetX.ValueAsInt;
        };
        spinGridOffsetY.Changed += delegate {
            model.GridOffsetY = spinGridOffsetY.ValueAsInt;
        };
        #endregion

        //Set up event handlers for menu actions
        #region File->New
        NewAction.Activated += delegate {
            bool continueNew = false; //Used to stop the new map action if the user presses "cancel" on the question on wether or not to save
            //Check if the map has been changed. If so, ask the user if he/she would like to save.
            if (model.Changed)
                QuerySave(delegate { continueNew = true; SaveAction.Activate(); }, delegate {continueNew = true;});
            else continueNew = true;

            //If continueNew is false, the user pressed cancel and we should therefor stop creating a new map.
            if (continueNew)
            {
                NewMapDialog newMapDialog = new NewMapDialog(model);

                newMapDialog.Response += delegate(object o, ResponseArgs args) {
                    switch (args.ResponseId)
                    {
                    case ResponseType.Ok:
                        NewMapDialog dlg = (NewMapDialog)o;

                        MapEditorState.Schedule(delegate {
                            model.CurrentTileset = model.ResourceManager.GetTileset(dlg.Tileset);
                            model.TileMap = new TileMap(model.Display, model.CurrentTileset, dlg.MapWidth, dlg.MapHeight, dlg.MapDepth, dlg.XOffset, dlg.YOffset, dlg.TileSize);
                            model.Display.CameraX = 0;
                            model.Display.CameraY = 0;
                            model.Display.Zoom = 100;
                            model.Changed = false;
                            model.Filename = "";
                            model.Objects.Clear();
                            model.DrawToLayer = 1;
                            model.Background = "";
                        });
                        break;

                    case ResponseType.Cancel:
                        //Do nothing
                        break;
                    }
                };

                newMapDialog.Run();
                newMapDialog.Destroy();
            }
        };
        #endregion

        #region File->Open
        OpenAction.Activated += delegate {
            bool continueOpen = false; //Used to stop the new map action if the user presses "cancel" on the question on wether or not to save
            //Check if the map has been changed. If so, ask the user if he/she would like to save.
            if (model.Changed)
                QuerySave(delegate { continueOpen = true; SaveAction.Activate(); }, delegate {continueOpen = true;});
            else continueOpen = true;

            //If continueOpen is false, the user pressed cancel and we should therefor stop opening another map.
            if (continueOpen)
            {
                FileChooserDialog dlg = new FileChooserDialog("Open map", this, FileChooserAction.Open, "Open", ResponseType.Ok, "Cancel", ResponseType.Cancel);
                FileFilter f = new FileFilter();
                f.AddPattern("*.xml");
                dlg.Filter = f;

                dlg.Response += delegate(object o, ResponseArgs args) {
                    switch (args.ResponseId)
                    {
                    case ResponseType.Ok:
                        string filename = dlg.Filename;

                        MapEditorState.Schedule(delegate{
                            try
                            {
                                MapDescriptor mapDescriptor = new MapLoader().LoadResource(filename, "");
                                TileMap newTm = new TileMap(model.Display, model.ResourceManager, mapDescriptor);
                                model.MapID = mapDescriptor.MapID;
                                model.CurrentTileset = newTm.Tileset;
                                model.TileMap = newTm;
                                model.Objects.Clear();
                                foreach (MapDescriptor.MapObject obj in mapDescriptor.Objects)
                                {
                                    Log.Write("Spawning object " + obj.Name);
                                    MapObject newObj = new MapObject(model.ResourceManager.GetObjectDescriptor(obj.Name), model.ResourceManager, model.Display.Renderer, new Vector(obj.X, obj.Y));
                                    model.Objects.Add(newObj);
                                }
                                model.Filename = filename;
                                model.Changed = false;
                                model.DrawToLayer = 1;
                                model.Background = mapDescriptor.Background;
                                foreach (KeyValuePair<string, string> p in mapDescriptor.ExtraProperties)
                                    model.ExtraProperties.Add(p.Key, p.Value);
                            }
                            catch (Exception e)
                            {
                                Application.Invoke(delegate {
                                    Log.Write("Unable to open map " + filename + ": " + e.Message,Log.ERROR);
                                    MessageDialog mdlg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Unable to open map " + filename + ": " + e.Message);
                                    mdlg.Run();
                                    mdlg.Destroy();
                                });
                            }
                        });
                        break;
                    case ResponseType.Cancel:
                        break;
                    }
                };

                dlg.Run();
                dlg.Destroy();

            }
        };
        #endregion

        #region File->Save
        SaveAction.Activated += delegate {
            if (!string.IsNullOrEmpty(model.Filename))
            {
                SaveMap(model.Filename);
                model.Changed = false;
            }
            else
            {
                ShowSaveAs();
            }
        };
        #endregion

        #region File->Save As
        SaveAsAction.Activated += delegate { ShowSaveAs(); };
        #endregion

        #region File->Quit
        QuitAction.Activated += delegate {
            bool continueQuit = false; //Used to stop the new map action if the user presses "cancel" on the question on wether or not to save
            //Check if the map has been changed. If so, ask the user if he/she would like to save.
            if (model.Changed)
                QuerySave(delegate { continueQuit = true; SaveAction.Activate(); }, delegate {continueQuit = true;});
            else continueQuit = true;

            if (continueQuit)
            {
                model.Running = false;

                Application.Quit();
            }
        };
        #endregion

        #endregion

        int pos = 0;
        foreach (string texture in model.ResourceManager.Textures)
        {
            comboBackgrounds.InsertText(pos, texture);
            pos++;
        }
    }