public override void Update(double deltaTime, double totalTime, long count) { BaseState.Buttons["layer-terrain"].Active = Layer == Tile.MapLayer.Terrain; BaseState.Buttons["layer-decoration"].Active = Layer == Tile.MapLayer.Decoration; BaseState.Buttons["layer-npc"].Active = Layer == Tile.MapLayer.NPC; BaseState.Buttons["layer-control"].Active = Layer == Tile.MapLayer.Control; BaseState.Buttons["layer-terrain"].Disabled = SelectedTile != new Point(-1, -1); BaseState.Buttons["layer-decoration"].Disabled = SelectedTile != new Point(-1, -1); BaseState.Buttons["layer-npc"].Disabled = SelectedTile != new Point(-1, -1); BaseState.Buttons["layer-control"].Disabled = SelectedTile != new Point(-1, -1); if (Game.Input.KeyPressed(Keys.T) && SelectedTile == new Point(-1, -1)) { MapEditorTileEditState state = new MapEditorTileEditState(); state.Layer = Layer; BaseState.CurrentState = state; return; } if (Game.Input.MousePressed(MouseButton.Left) && !BaseState.IsPointObscured(Input.MousePosition) && SelectedTile == new Point(-1, -1)) { bool canCurrentTileHaveMetadata = BaseState.Map[Layer, HoveredTile.X, HoveredTile.Y].HasEditableAttributes; if (canCurrentTileHaveMetadata) { SelectedTile = HoveredTile; TileMetadata attribs = BaseState.Map.GetMetadata(Layer, SelectedTile.X, SelectedTile.Y); int currentY = Game.GraphicsDevice.Viewport.Bounds.Height / 2 - 300 / 2 + 30; _editors = BaseState.Map[Layer, SelectedTile.X, SelectedTile.Y].AttributeEditors(BaseState, ref currentY); if (attribs != null) { foreach (TileAttributeEditor editor in _editors) { if (attribs.IsKeySet(editor.Name)) { editor.ValueFromExistingTile(attribs[editor.Name]); } } } BaseState.Buttons.Add("exit-edit-button", new Button() { Text = "Finish editing", Font = Game.DefaultFonts.Bold, Position = new TweenedVector2(Game, Vector2.Zero), Clicked = (btn) => { FinalizeEdit(); } }); } } if (BaseState.Buttons.ContainsKey("exit-edit-button")) { BaseState.Buttons["exit-edit-button"].Position. TweenTo(new Vector2( Game.GraphicsDevice.Viewport.Bounds.Width / 2 - BaseState.Buttons["exit-edit-button"].Rectangle.Width / 2, Game.GraphicsDevice.Viewport.Bounds.Height / 2 + 300 / 2 - 32), TweenEaseType.Linear, 0); } Vector2 offset = new Vector2( Game.GraphicsDevice.Viewport.Bounds.Width - _lastBounds.Width, Game.GraphicsDevice.Viewport.Bounds.Height - _lastBounds.Height) / 2; foreach (KeyValuePair <string, Button> pair in BaseState.Buttons) { if (pair.Key.StartsWith("editor-")) { pair.Value.Position.TweenTo(pair.Value.Position + offset, TweenEaseType.Linear, 0); } } foreach (KeyValuePair <string, SelectionMenu> pair in BaseState.SelectionMenus) { if (pair.Key.StartsWith("editor-")) { pair.Value.Rectangle.TweenTo(new Rectangle( pair.Value.Rectangle.Value.X + (int)offset.X, pair.Value.Rectangle.Value.Y + (int)offset.Y, 0, 0), TweenEaseType.Linear, 0); } } foreach (KeyValuePair <string, TextField> pair in BaseState.TextFields) { if (pair.Key.StartsWith("editor-")) { pair.Value.Position.TweenTo(pair.Value.Position + offset, TweenEaseType.Linear, 0); } } foreach (KeyValuePair <string, ScrollableTextField> pair in BaseState.ScrollableTextFields) { if (pair.Key.StartsWith("editor-")) { pair.Value.Area.TweenTo(new Rectangle( pair.Value.Area.Value.X + (int)offset.X, pair.Value.Area.Value.Y + (int)offset.Y, pair.Value.Area.Value.Width, pair.Value.Area.Value.Height), TweenEaseType.Linear, 0); } } foreach (KeyValuePair <string, ChoiceField> pair in BaseState.ChoiceFields) { if (pair.Key.StartsWith("editor-")) { pair.Value.Position.TweenTo(pair.Value.Position + offset, TweenEaseType.Linear, 0); } } _lastBounds = Game.GraphicsDevice.Viewport.Bounds; }
public override void Update(double deltaTime, double totalTime, long count) { /* TODO if(Game.Input.KeyPressed(Keys.E)) * { * _lastSelection = Menu.Selected; * Menu.Selected = 0; * } * * if(Game.Input.KeyReleased(Keys.E)) * { * Menu.Selected = _lastSelection; * _lastSelection = -1; * } */ if (Game.Input.KeyPressed(Keys.T) && !Menu.IsHovered) { MapEditorEditAttributesState state = new MapEditorEditAttributesState(); state.Layer = Layer; BaseState.CurrentState = state; return; } Menu.Disabled = !Menu.IsHovered && (_eraseMode || Game.Input.Key(Keys.E)); BaseState.Buttons["tool-paintone"].Active = _tool == EditTool.PaintOne; BaseState.Buttons["tool-rectangle"].Active = _tool == EditTool.PaintRectangle; BaseState.Buttons["eraser"].Active = _eraseMode || Game.Input.Key(Keys.E); BaseState.Buttons["layer-terrain"].Active = Layer == Tile.MapLayer.Terrain; BaseState.Buttons["layer-decoration"].Active = Layer == Tile.MapLayer.Decoration; BaseState.Buttons["layer-npc"].Active = Layer == Tile.MapLayer.NPC; BaseState.Buttons["layer-control"].Active = Layer == Tile.MapLayer.Control; if (BaseState.Buttons["tool-paintone"].Position.IsComplete) { float alpha = 1.0f; if (Menu.IsHovered) { alpha = 0.0f; } BaseState.Buttons["tool-paintone"].Alpha = MathHelper.Lerp(BaseState.Buttons["tool-paintone"].Alpha, alpha, (float)deltaTime * 25f); BaseState.Buttons["tool-rectangle"].Alpha = MathHelper.Lerp(BaseState.Buttons["tool-rectangle"].Alpha, alpha, (float)deltaTime * 25f); BaseState.Buttons["eraser"].Alpha = MathHelper.Lerp(BaseState.Buttons["eraser"].Alpha, alpha, (float)deltaTime * 25f); BaseState.Buttons["layer-terrain"].Alpha = MathHelper.Lerp(BaseState.Buttons["layer-terrain"].Alpha, alpha, (float)deltaTime * 25f); BaseState.Buttons["layer-decoration"].Alpha = MathHelper.Lerp(BaseState.Buttons["layer-decoration"].Alpha, alpha, (float)deltaTime * 25f); BaseState.Buttons["layer-npc"].Alpha = MathHelper.Lerp(BaseState.Buttons["layer-npc"].Alpha, alpha, (float)deltaTime * 25f); BaseState.Buttons["layer-control"].Alpha = MathHelper.Lerp(BaseState.Buttons["layer-control"].Alpha, alpha, (float)deltaTime * 25f); } if (!BaseState.IsPointObscured(Input.MousePosition)) { if (Input.MousePressed(MouseButton.Middle) && !Input.Mouse(MouseButton.Left)) { _tool = _tool == EditTool.PaintOne ? EditTool.PaintRectangle : EditTool.PaintOne; } if (Input.KeyPressed(Keys.R) && !_eraseMode && !Game.Input.Key(Keys.E)) { string flip = Input.Key(Keys.LeftShift) ? "flip-v" : "flip-h"; Tile tile = BaseState.Map[Menu.SelectedTile.Layer, SelectedTile.X, SelectedTile.Y]; TileMetadata meta = BaseState.Map.GetMetadata(Menu.SelectedTile.Layer, SelectedTile.X, SelectedTile.Y); int currentY = 0; // TODO: make it easier to call this function without removing menus TileAttributeEditor[] editors = tile.AttributeEditors(BaseState, ref currentY); if (editors != null) { foreach (TileAttributeEditor editor in editors) { if (editor.Name == flip) { bool enable = !(meta != null && meta.IsKeySet(flip) && meta[flip] == "True"); if (enable) { if (meta == null) { meta = new TileMetadata(); } meta[flip] = "True"; BaseState.Map.SetMetadata(Menu.SelectedTile.Layer, SelectedTile.X, SelectedTile.Y, meta); } else { meta[flip] = ""; } } editor.Dispose(); } } } switch (_tool) { case EditTool.PaintOne: if (Input.Mouse(MouseButton.Left)) { BaseState.Map[_eraseMode || Game.Input.Key(Keys.E) ? Layer : Menu.SelectedTile.Layer, SelectedTile.X, SelectedTile.Y] = _eraseMode || Game.Input.Key(Keys.E) ? Tile.Find("", Layer) : Menu.SelectedTile; } break; case EditTool.PaintRectangle: if (Input.MousePressed(MouseButton.Left)) { _startingTile = SelectedTile; } if (Input.MouseReleased(MouseButton.Left)) { for (int x = _rectangleToolRect.X; x <= _rectangleToolRect.X + _rectangleToolRect.Width; x++) { for (int y = _rectangleToolRect.Y; y <= _rectangleToolRect.Y + _rectangleToolRect.Height; y++) { BaseState.Map[_eraseMode || Game.Input.Key(Keys.E) ? Layer : Menu.SelectedTile.Layer, x, y] = _eraseMode || Game.Input.Key(Keys.E) ? Tile.Find("", Layer) : Menu.SelectedTile; } } _startingTile = new Point(-1, -1); } break; } } Menu.MaxHeight = Game.GraphicsDevice.Viewport.Bounds.Height / 2; Menu.Update(Game); }