/// <summary> /// Updates the user controls depending on selected object and in-game state /// </summary> /// <param id="state">In-game state defining the user controls state</param> private void UpdateUserControls(InGameStateEnum state) { switch (state) { case InGameStateEnum.Default: case InGameStateEnum.DragSelecting: cm.ApplyToAll(c => c.Enabled = false); break; case InGameStateEnum.DefaultSelected: case InGameStateEnum.Movement: case InGameStateEnum.Spell: case InGameStateEnum.Attack: case InGameStateEnum.BuildingPlacement: case InGameStateEnum.Building: case InGameStateEnum.Gather: case InGameStateEnum.Train: Debug.Assert(isObjectSelected); GameObject gObj = selectedObjects[0]; cm.GetControl("objMove").Enabled = gObj.CanDoOrder(GameObjectOrder.Idle); cm.GetControl("objCast").Enabled = gObj.CanDoOrder(GameObjectOrder.Spell); cm.GetControl("objAttack").Enabled = gObj.CanDoOrder(GameObjectOrder.Attack); cm.GetControl("objGather").Enabled = gObj.CanDoOrder(GameObjectOrder.Gather); cm.GetControl("objTrain").Enabled = gObj.CanDoOrder(GameObjectOrder.Train); var canBuild = gObj.CanDoOrder(GameObjectOrder.Construct); cm.GetControl("objBuild").Enabled = canBuild; cm.GetControl("objConstruct").Enabled = canBuild; break; default: break; } }
// UI CHANGE /// <summary> /// Changes the in-game state, setting proper tracking updates user controls /// </summary> /// <param id="state">New in-game state of the MapUI</param> /// <param id="autoCursor">Sets, whether autoCursor should be re-set</param> private void ChangeIngameState(InGameStateEnum state, bool autoCursor = false) { this.autoCursor = autoCursor; switch (state) { case InGameStateEnum.Default: case InGameStateEnum.DragSelecting: case InGameStateEnum.DefaultSelected: case InGameStateEnum.Attack: case InGameStateEnum.Train: case InGameStateEnum.Gather: mouseoverTileTracking = false; gameObjectTracking = true; break; case InGameStateEnum.Movement: mouseoverTileTracking = true; gameObjectTracking = false; break; case InGameStateEnum.Spell: if (Db.Instance.Effects.OrderBy(p => p.Value.Tier).ElementAt(entryIdx).Value.Spell.Target == SpellEntry.TargetType.Tile) { mouseoverTileTracking = true; gameObjectTracking = false; } else { mouseoverTileTracking = false; gameObjectTracking = true; } entryIdx = 0; break; case InGameStateEnum.BuildingPlacement: case InGameStateEnum.Building: mouseoverTileTracking = true; gameObjectTracking = true; entryIdx = 0; break; default: break; } inGameState = state; UpdateUserControls(state); }
// DISPOSING /// <summary> /// Flushes all the information about the map and resets the MapUI (while keeping the Game and ControllingPlayer) /// </summary> private void FlushMapInfo() { inGameState = InGameStateEnum.Default; mouseoverTile = null; mouseoverGameObject = null; map = null; mouseoverTileTracking = false; gameObjectTracking = true; mouseSelecting = false; }
// INITIALIZE /// <summary> /// Constructor for the MapUI class /// </summary> /// <param id="game">game, the MapUI will overlook</param> public MapUI(WildmenGame game) { this.game = game; this.map = this.game.Map; this.inGameState = InGameStateEnum.Default; }
/// <summary> /// Starts drag selecting of game objects /// </summary> /// <param id="start">Start vector of drag-selection</param> private void StartDragSelection(Vector2 start) { inGameState = InGameStateEnum.DragSelecting; mouseSelecting = true; mouseSelectingStart = start; }