public bool ProcessEvent(Event e) { if (!MapLogic.Instance.IsLoaded) { return(false); } if (e.type == EventType.KeyDown) { switch (e.keyCode) { case KeyCode.LeftArrow: if (ScrollDeltaX == 0) { ScrollDeltaX = -1; } return(true); case KeyCode.RightArrow: if (ScrollDeltaX == 0) { ScrollDeltaX = 1; } return(true); case KeyCode.UpArrow: if (ScrollDeltaY == 0) { ScrollDeltaY = -1; } return(true); case KeyCode.DownArrow: if (ScrollDeltaY == 0) { ScrollDeltaY = 1; } return(true); case KeyCode.Plus: case KeyCode.Equals: // + = = case KeyCode.KeypadPlus: { int oldSpeed = MapLogic.Instance.Speed; if (!NetworkManager.IsClient) { MapLogic.Instance.Speed++; } if (oldSpeed != MapLogic.Instance.Speed) { MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]); } } return(true); case KeyCode.Minus: case KeyCode.KeypadMinus: { int oldSpeed = MapLogic.Instance.Speed; if (!NetworkManager.IsClient) { MapLogic.Instance.Speed--; } if (oldSpeed != MapLogic.Instance.Speed) { MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]); } } return(true); case KeyCode.F3: //if (NetworkManager.IsClient) { DiplomacyWindow wnd = Utils.CreateObjectWithScript <DiplomacyWindow>(); //Debug.LogFormat("created a window!"); } return(true); case KeyCode.Escape: { // todo: create main menu ExampleWindow wnd = Utils.CreateObjectWithScript <ExampleWindow>(); } return(true); case KeyCode.Space: // check if local unit is dead. // for dead local unit, space sends respawn. // for alive local unit, space toggles both spellbook and inventory. if (MapLogic.Instance.ConsolePlayer != null && !MapLogic.Instance.ConsolePlayer.Avatar.IsAlive) { Client.SendRespawn(); } else { bool cstate = InventoryVisible && SpellbookVisible; InventoryVisible = !cstate; SpellbookVisible = !cstate; Spellbook.Update(); } return(true); case KeyCode.BackQuote: InventoryVisible = !InventoryVisible; Spellbook.Update(); return(true); case KeyCode.Q: SpellbookVisible = !SpellbookVisible; Spellbook.Update(); return(true); } } else if (e.type == EventType.KeyUp) { switch (e.keyCode) { case KeyCode.LeftArrow: if (ScrollDeltaX == -1) { ScrollDeltaX = 0; } return(true); case KeyCode.RightArrow: if (ScrollDeltaX == 1) { ScrollDeltaX = 0; } return(true); case KeyCode.UpArrow: if (ScrollDeltaY == -1) { ScrollDeltaY = 0; } return(true); case KeyCode.DownArrow: if (ScrollDeltaY == 1) { ScrollDeltaY = 0; } return(true); } } else if (e.rawType == EventType.MouseMove) { UpdateInput(); return(true); } else if (e.rawType == EventType.MouseDown && e.button == 0) { // select unit if not selected yet if (HoveredObject != null && (SelectedObject == null || (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move && !Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt)) || (Commandbar.CurrentCommand == 0))) { SelectedObject = HoveredObject; OnObjectSelected(SelectedObject); } else if (SelectedObject != null && SelectedObject is IPlayerPawn && ((IPlayerPawn)SelectedObject).GetPlayer() == MapLogic.Instance.ConsolePlayer) { // todo: handle commands here // try to walk. if (SelectedObject.GetObjectType() == MapObjectType.Monster || SelectedObject.GetObjectType() == MapObjectType.Human) { MapUnit unit = (MapUnit)SelectedObject; if (GetCastSpell() != Spell.Spells.NoneSpell) { if (HoveredObject != null && (HoveredObject.GetObjectType() == MapObjectType.Monster || HoveredObject.GetObjectType() == MapObjectType.Human)) { Client.SendCastToUnit(unit, GetCastSpell(), (MapUnit)HoveredObject); } else { Client.SendCastToArea(unit, GetCastSpell(), MouseCellX, MouseCellY); } } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move) { Client.SendMoveUnit(unit, MouseCellX, MouseCellY); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Attack && HoveredObject != null && (HoveredObject.GetObjectType() == MapObjectType.Monster || HoveredObject.GetObjectType() == MapObjectType.Human)) { Client.SendAttackUnit(unit, (MapUnit)HoveredObject); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Pickup && MapLogic.Instance.GetSackAt(MouseCellX, MouseCellY) != null) { Client.SendPickupUnit(unit, MouseCellX, MouseCellY); // issue sack pickup command by current unit at target coordinates } } } return(true); } else if (e.rawType == EventType.MouseDown && e.button == 1) { SelectedObject = null; // deselect Commandbar.EnabledCommands = 0; return(true); } return(false); }
public bool ProcessEvent(Event e) { if (!MapLogic.Instance.IsLoaded) { if (MapLogic.Instance.IsLoading) { MouseCursor.SetCursor(MouseCursor.CurWait); } return(false); } if (e.type == EventType.KeyDown) { switch (e.keyCode) { case KeyCode.LeftArrow: if (ScrollDeltaX == 0) { ScrollDeltaX = -1; } return(true); case KeyCode.RightArrow: if (ScrollDeltaX == 0) { ScrollDeltaX = 1; } return(true); case KeyCode.UpArrow: if (ScrollDeltaY == 0) { ScrollDeltaY = -1; } return(true); case KeyCode.DownArrow: if (ScrollDeltaY == 0) { ScrollDeltaY = 1; } return(true); case KeyCode.Plus: case KeyCode.Equals: // + = = case KeyCode.KeypadPlus: { int oldSpeed = MapLogic.Instance.Speed; if (!NetworkManager.IsClient) { MapLogic.Instance.Speed++; } if (oldSpeed != MapLogic.Instance.Speed) { MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]); } } return(true); case KeyCode.Minus: case KeyCode.KeypadMinus: { int oldSpeed = MapLogic.Instance.Speed; if (!NetworkManager.IsClient) { MapLogic.Instance.Speed--; } if (oldSpeed != MapLogic.Instance.Speed) { MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]); } } return(true); case KeyCode.F3: //if (NetworkManager.IsClient) { DiplomacyWindow wnd = Utils.CreateObjectWithScript <DiplomacyWindow>(); //Debug.LogFormat("created a window!"); } return(true); case KeyCode.Escape: { // todo: create main menu ExampleWindow wnd = Utils.CreateObjectWithScript <ExampleWindow>(); } return(true); case KeyCode.Space: // check if local unit is dead. // for dead local unit, space sends respawn. // for alive local unit, space toggles both spellbook and inventory. if (MapLogic.Instance.ConsolePlayer != null && !MapLogic.Instance.ConsolePlayer.Avatar.IsAlive) { Client.SendRespawn(); } else { bool cstate = InventoryVisible && SpellbookVisible; InventoryVisible = !cstate; SpellbookVisible = !cstate; Spellbook.Update(); } return(true); case KeyCode.BackQuote: InventoryVisible = !InventoryVisible; Spellbook.Update(); return(true); case KeyCode.Q: SpellbookVisible = !SpellbookVisible; Spellbook.Update(); return(true); } } else if (e.type == EventType.KeyUp) { switch (e.keyCode) { case KeyCode.LeftArrow: if (ScrollDeltaX == -1) { ScrollDeltaX = 0; } return(true); case KeyCode.RightArrow: if (ScrollDeltaX == 1) { ScrollDeltaX = 0; } return(true); case KeyCode.UpArrow: if (ScrollDeltaY == -1) { ScrollDeltaY = 0; } return(true); case KeyCode.DownArrow: if (ScrollDeltaY == 1) { ScrollDeltaY = 0; } return(true); } } else if (e.rawType == EventType.MouseMove) { UpdateInput(); return(true); } else if (e.rawType == EventType.MouseDown && e.button == 0) { // select unit if not selected yet // to-do: unfuck this expression later... if (HoveredObject != null && (SelectedObject == null || (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move && GetCastSpell() == Spell.Spells.NoneSpell && !Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt)) || (Commandbar.CurrentCommand == 0)) && (SelectedObject == null || !(HoveredObject is MapStructure s && s.Class.Usable))) { SelectedObject = HoveredObject; } else if (SelectedObject != null && SelectedObject is IPlayerPawn && ((IPlayerPawn)SelectedObject).GetPlayer() == MapLogic.Instance.ConsolePlayer) { // todo: handle commands here // try to walk. if (SelectedObject is MapUnit unit) { Spell.Spells castSpId = GetCastSpell(); if (HoveredObject is MapStructure struc && struc.Class.Usable) { Client.SendUseStructure(unit, struc); } else if (castSpId != Spell.Spells.NoneSpell && (MapLogic.Instance.Nodes[MouseCellX, MouseCellY].Flags & MapNodeFlags.Visible) != 0) { Spell castSp = GetOneTimeCast(); if (castSp == null) { castSp = unit.GetSpell(castSpId); } if (HoveredObject != null && HoveredObject is MapUnit) { Client.SendCastToUnit(unit, castSp, (MapUnit)HoveredObject, MouseCellX, MouseCellY); } else { Client.SendCastToArea(unit, castSp, MouseCellX, MouseCellY); } if (castSp == OneTimeCast || Commandbar.CurrentCommandActual == MapViewCommandbar.Commands.Cast) { SpellbookVisible = false; if (Commandbar.CurrentCommandActual == MapViewCommandbar.Commands.Cast) { Commandbar.InitDefault(SelectedObject); } } OneTimeCast = null; } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move) { Client.SendMoveUnit(unit, MouseCellX, MouseCellY); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Attack && HoveredObject != null && HoveredObject is MapUnit) { Client.SendAttackUnit(unit, (MapUnit)HoveredObject); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Pickup && MapLogic.Instance.GetSackAt(MouseCellX, MouseCellY) != null) { Client.SendPickupUnit(unit, MouseCellX, MouseCellY); // issue sack pickup command by current unit at target coordinates } } }