Пример #1
0
 private void setAllButton_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Really Set all to Currently Selected Tile Type?", "Confirm Set All", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         TileTool.SetAll((String)pbox_TilePreview.Tag);
     }
 }
Пример #2
0
        // TODO: MultiTileGridLayer stuff should move into appropriate class
        public void SetTool(TileTool tool)
        {
            if (LayerContext == null)
            {
                return;
            }

            if (_selection != null && tool == TileTool.Select)
            {
                _selection.Activate();
            }
            else if (_selection != null)
            {
                _selection.Deactivate();
            }

            if (_currentTool != null)
            {
                _currentTool.Dispose();
            }

            switch (tool)
            {
            case TileTool.Select:
                _currentTool = new TileSelectTool(LayerContext.History, Layer as MultiTileGridLayer, LayerContext.Annotations, this);
                break;

            case TileTool.Draw:
                TileDrawTool drawTool = new TileDrawTool(LayerContext.History, Layer as MultiTileGridLayer, LayerContext.Annotations);
                drawTool.Info = Info;
                drawTool.BindTilePoolController(_tilePoolController);
                drawTool.BindTileBrushManager(_tileBrushController);
                _currentTool = drawTool;
                break;

            case TileTool.Erase:
                _currentTool = new TileEraseTool(LayerContext.History, Layer as MultiTileGridLayer, LayerContext.Annotations);
                break;

            case TileTool.Fill:
                TileFillTool fillTool = new TileFillTool(LayerContext.History, Layer as MultiTileGridLayer, _sourceType);
                fillTool.BindTilePoolController(_tilePoolController);
                fillTool.BindTileBrushManager(_tileBrushController);
                _currentTool = fillTool;
                break;

            default:
                _currentTool = null;
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            graphics.PreferredBackBufferHeight = 480;
            graphics.PreferredBackBufferWidth  = 640;
            IsFixedTimeStep = true;
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferMultiSampling            = true;
            graphics.ApplyChanges();
            //initialize the various tools we'll use
            EditorScreen.initialize(form, this);
            TileTool.InitializeTool(this, form);
            ModelTool.InitializeTool(this, form);
            NPCTool.InitializeTool(this, form);



            base.Initialize();
        }
Пример #4
0
    public override async void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        property.serializedObject.Update();

        GUI.enabled = false;
        EditorGUI.ObjectField(position, label, TileManager.Current.GetTile <Tile>(property.vector2IntValue), typeof(Tile), true);
        GUI.enabled = true;

        if (Event.current.isKey && Event.current.keyCode == KeyCode.Escape)
        {
            token?.Cancel();
            token = null;
            property.serializedObject.RepaintInspector();
        }

        if (GUI.Button(new Rect(position.xMax - 26, position.y, 26, position.height), token != null ? "•" : "☉"))
        {
            if (token != null)
            {
                token.Cancel();
                token = null;
            }
            else
            {
                token = new CancellationTokenSource();
                var(tile, isSuccessful) = await TileTool.PickTile(token.Token);

                token = null;
                if (isSuccessful && tile.position != property.vector2IntValue)
                {
                    if (tile.GetType().Name == typeof(Tile).Name && fieldInfo.FieldType != typeof(Tile))
                    {
                        tile = await TileManager.Current.SwapTile(tile.position, fieldInfo.FieldType, false);
                    }

                    if (tile?.GetType() == attribute.type)
                    {
                        property.vector2IntValue = tile.position;
                        property.serializedObject.ApplyModifiedProperties();
                    }
                }
            }
        }
    }
Пример #5
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        _tileTool = (TileTool)target;

        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Creating Foreground Rows and Columns", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create Row"))
        {
            _tileTool.CreateRow();
        }

        if (GUILayout.Button("Create Column"))
        {
            _tileTool.CreateColumn();
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();


        EditorGUILayout.LabelField("Color Shift Tools", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Darken"))
        {
            _tileTool.DarkenColors();
        }
        if (GUILayout.Button("Lighten"))
        {
            _tileTool.LightenColors();
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Recent Creation Tools", EditorStyles.boldLabel);

        if (GUILayout.Button("Delete"))
        {
            _tileTool.DeleteRecent();
        }

        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Colorize"))
        {
            _tileTool.ColorizeTiles();
        }

        if (GUILayout.Button("FlipX"))
        {
            _tileTool.FlipSpritesX();
        }

        if (GUILayout.Button("FlipY"))
        {
            _tileTool.FlipSpritesY();
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Set Sprite Order"))
        {
            _tileTool.SetSpriteLayer();
        }

        if (GUILayout.Button("Set Sprite Sort Layer"))
        {
            _tileTool.SetSpriteSortingLayer();
        }

        EditorGUILayout.EndHorizontal();
    }
Пример #6
0
    public static void  Init()
    {
        TileTool window = (TileTool)EditorWindow.GetWindow(typeof(TileTool));

        window.Show();
    }
Пример #7
0
        static public void update(GameTime gameTime, World world)
        {
            //get current state of keyboard and mouse
            currentMouseState = Mouse.GetState();
            currentKeyState   = Keyboard.GetState();

            //keyboard actions
            HandleArrowKeys();

            if (currentKeyState.IsKeyDown(Keys.A))
            {
                lookAtPosition -= new Vector3(GameDraw.cameraOffset.Length() / 100, 0, 0);
            }
            if (currentKeyState.IsKeyDown(Keys.D))
            {
                lookAtPosition += new Vector3(GameDraw.cameraOffset.Length() / 100, 0, 0);
            }
            if (currentKeyState.IsKeyDown(Keys.S))
            {
                lookAtPosition += new Vector3(0, GameDraw.cameraOffset.Length() / 100, 0);
            }
            if (currentKeyState.IsKeyDown(Keys.W))
            {
                lookAtPosition -= new Vector3(0, GameDraw.cameraOffset.Length() / 100, 0);
            }
            //undo action
            //check whether a ctrl is down, and the Z key has been pressed (was up, is now down)
            if ((currentKeyState.IsKeyDown(Keys.LeftControl) || currentKeyState.IsKeyDown(Keys.RightControl)) &&
                (currentKeyState.IsKeyDown(Keys.Z) && prevKeyState.IsKeyUp(Keys.Z)))
            {
                //make sure the next history isn't empty
                if (editor.zoneHistory[editor.historyIndex + 1] != null)
                {
                    //increase history index by one if possible
                    editor.historyIndex++;
                    if (editor.historyIndex >= editor.historySize)
                    {
                        editor.historyIndex = editor.historySize - 1;
                    }

                    //change to the historical zone
                    game.world.addZone(editor.zoneHistory[editor.historyIndex]);
                    game.world.changeZone(editor.zoneHistory[editor.historyIndex]);
                    GameDraw.MakeAdjBuffers(game.world);
                }
            }
            //redo action
            //check whether a ctrl is down, and the Y key has been pressed (was up, is now down)
            if ((currentKeyState.IsKeyDown(Keys.LeftControl) || currentKeyState.IsKeyDown(Keys.RightControl)) &&
                (currentKeyState.IsKeyDown(Keys.Y) && prevKeyState.IsKeyUp(Keys.Y)))
            {
                //make sure there is room for us to redo
                if (editor.historyIndex > 0)
                {
                    editor.historyIndex--;

                    //if so then restore the next zone state
                    game.world.addZone(editor.zoneHistory[editor.historyIndex]);
                    game.world.changeZone(editor.zoneHistory[editor.historyIndex]);
                    GameDraw.MakeAdjBuffers(game.world);
                }
            }

            //mouse actions
            {
                //if mouse is down
                if (currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    //check if mouse has been pressed, and if so then save current history
                    //that way you can undo to whatever the state was before the mouse was pressed
                    if (prevMouseState.LeftButton == ButtonState.Released && currentMouseState.LeftButton == ButtonState.Pressed)
                    {
                        updateHistory();
                    }


                    //if we have an actual tile selected do the different options
                    if (game.selectedX != -1 && game.selectedY != -1)
                    {
                        //if we are in the tile section
                        if (editor.toolTab.SelectedTab == editor.TileSpritesTab)
                        {
                            TileTool.ApplyImage();
                        }
                        //if we are in the tile settings tab
                        if (editor.toolTab.SelectedTab == editor.TilePropertiesTab)
                        {
                            TileTool.ApplySettings();
                        }
                        //if we are in the NPC tab
                        if (editor.toolTab.SelectedTab == editor.NPCTab)
                        {
                            if (NPCTool.toolType == NPCToolType.PlaceNPC)
                            {
                                NPCTool.PlaceNPC();
                            }
                            else if (NPCTool.toolType == NPCToolType.SetWanderArea)
                            {
                                //on start setting the wander area
                                if (prevMouseState.LeftButton == ButtonState.Released)
                                {
                                    NPCTool.StartSetWander();
                                }
                            }
                            else if (NPCTool.toolType == NPCToolType.EditNPC)
                            {
                                //on click pick up the NPC
                                if (prevMouseState.LeftButton == ButtonState.Released)
                                {
                                    NPCTool.PickUpNPC();
                                }
                                //update postion of NPC if we have one active
                                if (editor.activeNPCEdit != null)
                                {
                                    //if there are no obstables
                                    if (world.currentArea.tile[game.selectedX, game.selectedY].isClear())
                                    {
                                        editor.activeNPCEdit.tileCoords = new Point(game.selectedX, game.selectedY);
                                    }
                                }
                            }
                            else if (NPCTool.toolType == NPCToolType.DeleteNPC)
                            {
                                NPCTool.DeleteNPC();
                            }
                        }
                        //if we are in the model tab
                        if (editor.toolTab.SelectedTab == editor.SceneryTab)
                        {
                            //place a new model if new is selected
                            if (editor.modelNewRadio.Checked)
                            {
                                if (editor.sceneryBox.SelectedItem != null)
                                {
                                    ModelTool.PlaceModel();
                                }
                            }
                            //if delete is selected then it should act as a delete tool
                            else if (editor.modelDeleteRadio.Checked)
                            {
                                ModelTool.DeleteModel();
                            }
                            //edit model if edit is selected
                            else if (editor.modelEditRadio.Checked)
                            {
                                //on "click" rather than whenever pressed
                                if (prevMouseState.LeftButton == ButtonState.Released)
                                {
                                    ModelTool.EditModel();
                                    //on mouse down we "pick up" the scenery object
                                    ModelTool.PickUpScenery();
                                }
                            }
                        }
                    }
                }
                //on mouse release
                if (prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                {
                    //if we have an actual tile selected do the different options
                    if (game.selectedX != -1 && game.selectedY != -1)
                    {
                        //if we are in the model tab
                        if (editor.toolTab.SelectedTab == editor.SceneryTab && editor.modelEditRadio.Checked)
                        {
                            //on mouse up we "drop" the scenery object
                            ModelTool.DropScenery();
                        }
                        //if we are on the NPC tab
                        if (editor.toolTab.SelectedTab == editor.NPCTab)
                        {
                            if (NPCTool.toolType == NPCToolType.SetWanderArea && editor.NPCEditRadio.Checked)
                            {
                                NPCTool.EndSetWander();
                            }
                            else if (NPCTool.toolType == NPCToolType.EditNPC && editor.NPCEditRadio.Checked)
                            {
                                if (NPCTool.holdingNPC)
                                {
                                    NPCTool.DropNPC();
                                }
                            }
                        }
                    }
                }

                //when we release the mouse we want to save the current state as the most recent history
                if (prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                {
                    //if the history index is zero we want to save the current zone
                    if (editor.historyIndex == 0)
                    {
                        editor.zoneHistory[0] = new Zone(game.world.currentArea);
                    }
                }

                HandleScrollWheelActions();
            }

            //update previous mouse/keyboard state
            prevMouseState = currentMouseState;
            prevKeyState   = currentKeyState;
        }