public Camera(MapEditorState state) { _state = state; Zoom = new TweenedDouble(state.Game, 2); _prevTotalSize = TotalSizeOnScreen; _prevMapSize = new Vector2(state.Map.Width, state.Map.Height); }
public override void Update(double deltaTime, double totalTime, long count) { if (!CurrentState.PauseEditor && _dataOperation == DataOperation.None) { int xadd = Input.Key(Keys.LeftAlt) || Input.Key(Keys.RightAlt) ? -1 : 1; if (Input.Key(Keys.LeftControl) || Input.Key(Keys.RightControl)) { xadd *= 5; } int yadd = xadd; while (Map.Width + xadd < 1) { xadd++; } while (Map.Width + xadd > 256) { xadd--; } while (Map.Height + yadd < 1) { yadd++; } while (Map.Height + yadd > 256) { yadd--; } if (Input.Key(Keys.LeftShift) || Input.Key(Keys.RightShift)) { if (Input.KeyPressed(Keys.Left)) { Map.Resize(Map.Width + xadd, Map.Height, xadd, 0); } if (Input.KeyPressed(Keys.Right)) { Map.Resize(Map.Width + xadd, Map.Height, 0, 0); } if (Input.KeyPressed(Keys.Up)) { Map.Resize(Map.Width, Map.Height + yadd, 0, yadd); } if (Input.KeyPressed(Keys.Down)) { Map.Resize(Map.Width, Map.Height + yadd, 0, 0); } } } Camera.Update(deltaTime, totalTime); Buttons["edit-tiles-mode"].Active = CurrentState is MapEditorTileEditState; Buttons["edit-attributes-mode"].Active = CurrentState is MapEditorEditAttributesState; Buttons["edit-info-mode"].Active = CurrentState is MapEditorEditInfoState; Buttons["keybinds-help-mode"].Active = CurrentState is MapEditorShowKeybindsState; Buttons["player-view-mode"].Active = CurrentState is MapEditorPlayerViewState; if (_dataOperation == DataOperation.None && !CurrentState.IsPointObscured(Game.Input.MousePosition)) { foreach (Button button in Buttons.Values.ToArray()) { button.Update(Game); } foreach (SelectionMenu menu in SelectionMenus.Values.ToArray()) { menu.Update(Game); } foreach (TextField field in TextFields.Values.ToArray()) { field.Update(Game); } foreach (ScrollableTextField field in ScrollableTextFields.Values.ToArray()) { field.Update(Game); } foreach (ChoiceField field in ChoiceFields.Values.ToArray()) { field.Update(Game); } } string str = "Map Editor\n" + "Name: \"" + Map.Info.Name + "\"\n" + "Size: " + Map.Width + "x" + Map.Height + "\n" + "[PLACEHOLDER PLACEHOLDER PLACEHOLDER]"; Vector2 measure = Game.DefaultFonts.Bold.Measure(15, str); Rectangle topTextRectangle = new Rectangle(10, (int)_topTextY, (int)(measure.X + 20), (int)(measure.Y + 20)); if (topTextRectangle.Contains(Input.MousePosition) && !topTextRectangle.Contains(Input.PreviousMousePosition)) { _topTextFade.TweenTo(0.6, TweenEaseType.EaseOutQuad, 0.4f); } else if (!topTextRectangle.Contains(Input.MousePosition) && topTextRectangle.Contains(Input.PreviousMousePosition)) { _topTextFade.TweenTo(2.0, TweenEaseType.EaseOutQuad, 0.4f); } if (_dataOperation == DataOperation.None) { CurrentState.Update(deltaTime, totalTime, count); } if (_exiting) { Game.CurrentState = new MainMenuState(); } if (_doPlaytest) { WorldState world = new WorldState(Map, "Map Editor Player", true); EventHandler <Engine.Game.UpdateEventArgs> watcher = null; watcher = (s, e) => { if (Game.CurrentState != world) { // galet Game.CurrentState.OnLeave(world); // helt bananas typeof(Engine.Game).GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(Game, world); MapEditorState mapState = new MapEditorState(); Game.CurrentState = mapState; Game.OnUpdateAfterState -= watcher; } }; Game.OnUpdateAfterState += watcher; world.UpdateHook += (s, e) => { if (Game.Input.KeyPressed(Keys.Escape)) { MapEditorState mapState = new MapEditorState(); Game.CurrentState = mapState; Game.OnUpdateAfterState -= watcher; } }; world.DrawHook += (s, e) => { Matrix oldTransform = e.Batch.Transform; e.Batch.Transform = Matrix.Identity; e.Batch.Text(FontStyle.ItalicBold, 16, "Playtesting map \"" + Map.Info.Name + "\"\nPress ESC to return to the map editor", new Vector2(8, 8), Color.White * (0.8f + (float)(0.2f * Math.Sin(Game.Time * 4)))); e.Batch.Transform = oldTransform; }; Game.CurrentState = world; } }