Beispiel #1
0
    private void Awake()
    {
        GameObject gridobject = GameObject.FindGameObjectWithTag("Grid");

        grid        = gridobject.GetComponent <Grid>();
        tileChooser = gridobject.GetComponent <TileChooser>();
        GameObject tileInfoListManagerObject = GameObject.FindGameObjectsWithTag("TileInfoListManager")[0];

        tileInfoListManager = tileInfoListManagerObject.GetComponent <TileInfoListManager>();

        //tileInfoListManager.DeleteTile(tileChooser.currentTile);
    }
Beispiel #2
0
 public void SetTileChooser(TileChooser tc)
 {
     this.tileChooser = tc;
 }
Beispiel #3
0
    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++;
        }
    }
Beispiel #4
0
 // Start is called before the first frame update
 void Start()
 {
     instance = this;
     player   = GameObject.FindGameObjectsWithTag("Player")[0];
 }