/// <summary> /// Handle events from UIElements and/or backend objects /// </summary> /// <param name="sender"></param> /// <param name="eventID"></param> /// <param name="data"></param> public virtual void HandleEvent(bool DownStream, Backend.Events eventID, params object[] data) { if (DownStream) { // Frontend to backend (send) switch (eventID) { case Events.FinishedAnimation: _logic.HandleEvent(true, Events.FinishedAnimation, data); break; case Events.MoveActor: _logic.HandleEvent(true, Events.MoveActor, data); break; case Backend.Events.Chat: if (_logic is PureLogic) { _statusbox.AddLine((string)data[0], Color.Pink); } else { (_logic as NetLogic).SendChat((string)data[0]); } break; case Backend.Events.AddDragItem: _draggedObject = (GridElement)data[0]; _toolbar.dragItem = _draggedObject; break; case Backend.Events.Settings: if (_focus is Lobby) { _status = Backend.GameStatus.NoRedraw; NetPlayer tmp = ((Lobby)_focus).network; _focus.Dispose(); _interfaceElements.Remove(_focus); _focus = null; if (tmp.connected) { if (_logic is PureLogic) { _logic = new NetLogic(this, tmp); ((NetLogic)_logic).RequestMap(); } else { tmp.parent = _logic; HandleEvent(true, Events.ContinueGame, true); } } else { if (_logic is NetLogic) { _logic = new PureLogic(this); _logic.HandleEvent(true, Events.Initialize); HandleEvent(true, Events.ContinueGame, true); } else HandleEvent(true, Events.ContinueGame, true); } } break; case Events.Initialize: if (_logic is PureLogic) { _logic.HandleEvent(true, Events.Initialize); _logic.HandleEvent(true, Events.ContinueGame); } break; case Events.TileEntered: _logic.HandleEvent(true, Events.TileEntered, data); break; case Backend.Events.ShowMenu: _logic.HandleEvent(true, Events.Pause); if (_focus is CharacterWindow) { _focus.Dispose(); _interfaceElements.Remove(_focus); _toolbar.HandleEvent(true, Backend.Events.ContinueGame, 13); _status = Backend.GameStatus.Running; } if (_status == Backend.GameStatus.Running) { _ShowMenu(); } else HandleEvent(true, Backend.Events.ContinueGame, 0); break; case Backend.Events.ShowCharacter: _logic.HandleEvent(true, Events.Pause); if (_status == Backend.GameStatus.Running) _ShowCharacterWindow((Backend.Actor)data[0], 0); else { if (_focus is CharacterWindow) { if (((CharacterWindow)_focus).page != 0) { ((CharacterWindow)_focus).page = 0; _toolbar.HandleEvent(true, Backend.Events.ContinueGame, 10); return; } HandleEvent(true, Backend.Events.ContinueGame, 0); } else { if (_focus is Window) { _focus.Dispose(); _interfaceElements.Remove(_focus); _focus = null; _status = Backend.GameStatus.Running; } _ShowCharacterWindow((Backend.Actor)data[0], 0); _toolbar.HandleEvent(true, Backend.Events.ContinueGame, 10); } } break; case Backend.Events.ShowAbilities: _logic.HandleEvent(true, Events.Pause); if (_status == Backend.GameStatus.Running) _ShowCharacterWindow((Backend.Actor)data[0], 2); else { if (_focus is CharacterWindow) { if (((CharacterWindow)_focus).page != 2) { ((CharacterWindow)_focus).page = 2; _toolbar.HandleEvent(true, Backend.Events.ContinueGame, 12); return; } HandleEvent(true, Backend.Events.ContinueGame, 0); } else { if (_focus is Window) { _focus.Dispose(); _interfaceElements.Remove(_focus); _focus = null; _status = Backend.GameStatus.Running; } _ShowCharacterWindow((Backend.Actor)data[0], 2); _toolbar.HandleEvent(true, Backend.Events.ContinueGame, 12); } } break; case Backend.Events.ShowInventory: _logic.HandleEvent(true, Events.Pause); if (_status == Backend.GameStatus.Running) _ShowCharacterWindow((Backend.Actor)data[0], 1); else { if (_focus is CharacterWindow) { if (((CharacterWindow)_focus).page != 1) { ((CharacterWindow)_focus).page = 1; _toolbar.HandleEvent(true, Backend.Events.ContinueGame, 11); return; } _focus.Dispose(); _interfaceElements.Remove(_focus); _focus = null; _status = Backend.GameStatus.Running; HandleEvent(true, Backend.Events.ContinueGame, 0); } else { if (_focus is Window) { _focus.Dispose(); _interfaceElements.Remove(_focus); _focus = null; _status = Backend.GameStatus.Running; } _ShowCharacterWindow((Backend.Actor)data[0], 1); _toolbar.HandleEvent(true, Backend.Events.ContinueGame, 11); } } break; case Backend.Events.FetchFile: _logic.HandleEvent(true, Events.Pause); if (data.Length > 0) { string file = data[0].ToString(); _files2fetch.Enqueue(file); if (_status != Backend.GameStatus.FetchingData) { _prevState = _status; _status = Backend.GameStatus.FetchingData; _LoadFile(file, wc_DownloadProgressChanged, wc_DownloadFileCompleted); } } break; case Backend.Events.LoadFromCheckPoint: _status = Backend.GameStatus.NoRedraw; _logic.HandleEvent(true, Events.LoadFromCheckPoint, _playerID); break; case Backend.Events.Network: if (_logic is NetLogic) { _logic.HandleEvent(true, Events.Pause); _ShowLANWindow(((NetLogic)_logic).network); } else { _ShowLANWindow(); } /* //_secondPlayer = true; _lan = true; foreach (UIElement element in _interfaceElements) { element.HandleEvent(true, Backend.Events.ToggleButton, Backend.Events.Player2, true); element.HandleEvent(true, Backend.Events.ToggleButton, Backend.Events.Player1, false); element.HandleEvent(true, Backend.Events.ToggleButton, Backend.Events.Local, false); element.HandleEvent(true, Backend.Events.ToggleButton, Backend.Events.LAN, true); } // _mainmap2.enabled = false; _mainmap1.Resize(new Rectangle(5, 5, _graphics.GraphicsDevice.Viewport.Width - 230, ((_graphics.GraphicsDevice.Viewport.Height - 20)) - 115));*/ break; case Backend.Events.ContinueGame: if ((_status != Backend.GameStatus.NoRedraw) || (data.Count() > 0)) { _PlayMusic(); _logic.HandleEvent(true, Events.ContinueGame); if (_logic is PureLogic) { for (int i = 0; i < _logic.map.actors.Count; ++i) { if (_logic.map.actors[i] is Player) { _playerID = i; break; } } } if (_focus is Window) { _focus.Dispose(); _interfaceElements.Remove(_focus); } _toolbar.HandleEvent(true, Backend.Events.ContinueGame, -1); if (Mouse.GetState().LeftButton == ButtonState.Pressed) { _mainmap1.noMove = true; } _mainmap1.playerID = _playerID; _minimap1.playerID = _playerID; _logic.map.actors[_playerID].online = true; _mainmap1.resetActors(); //_mainmap2.resetActors(); _mana.actor = _logic.map.actors[_playerID]; _health.actor = _logic.map.actors[_playerID]; _toolbar.actor = _logic.map.actors[_playerID]; _status = GameStatus.Running; _focus = null; } break; case Backend.Events.About: _logic.HandleEvent(true, Events.Pause); if (_focus is Window) { _focus.Dispose(); _interfaceElements.Remove(_focus); _focus = null; } _ShowAbout(); break; case Backend.Events.EndGame: _logic.HandleEvent(true, Events.EndGame); Exit(); break; case Backend.Events.NewMap: _status = Backend.GameStatus.NoRedraw; _logic.HandleEvent(true, Backend.Events.NewMap); break; case Backend.Events.ResetGame: _status = Backend.GameStatus.NoRedraw; _logic.HandleEvent(true, Events.ResetGame); break; case Backend.Events.ButtonPressed: switch ((Backend.Buttons)data[0]) { case Backend.Buttons.Save: _ShowFileDialog(true); break; case Backend.Buttons.Restore: _ShowFileDialog(false); break; } break; case Backend.Events.ActivateAbility: _logic.HandleEvent(true, Events.ActivateAbility, data); break; case Backend.Events.SaveLoad: if (_logic is PureLogic) { PureLogic tmp = _logic as PureLogic; if ((bool)data[0]) tmp.Save((string)data[1]); else tmp.Restore((string)data[1]); } HandleEvent(true, Backend.Events.ContinueGame); break; case Backend.Events.ChangeMap: _status = Backend.GameStatus.NoRedraw; _playerID = (int)data[0]; _logic.map.actors[_playerID].online = true; _mainmap1.playerID = _playerID; _minimap1.playerID = _playerID; _mainmap1.map = _logic.map; _minimap1.map = _logic.map; _health.actor = _logic.map.actors[_playerID]; _mana.actor = _logic.map.actors[_playerID]; _toolbar.actor = _logic.map.actors[_playerID]; _mainmap1.resetActors(); if (_logic.map.actors[_playerID].tile != null) _minimap1.MoveCamera(_logic.map.actors[_playerID].tile.coords); HandleEvent(false, Events.ShowMessage, "You entered " + _logic.map.name + "."); _PlayMusic(); _status = Backend.GameStatus.Paused; _logic.HandleEvent(false, Events.ContinueGame); break; } } else { // Backend to Frontend (received) switch (eventID) { case Backend.Events.AddPlayer: _mainmap1.resetActors(); break; case Backend.Events.RemovePlayer: _mainmap1.resetActors(); break; case Backend.Events.Disconnect: HandleEvent(true, Events.Network); break; case Backend.Events.Attack: _mainmap1.HandleEvent(true, Events.AnimateActor, data[0], Backend.Activity.Attack); break; case Backend.Events.ActorText: if (data.Length > 3) _mainmap1.floatNumber((Coords)data[1], (string)data[2], (Color)data[3]); else _mainmap1.floatNumber((Coords)data[1], (string)data[2], Color.White); // defender, _map.actors[defender].tile.coords, "Evade") break; case Backend.Events.DamageActor: // , defender, _map.actors[defender].tile.coords, _map.actors[defender].health, damage); _mainmap1.HandleEvent(true, Events.AnimateActor, data[0], Backend.Activity.Hit); if ((int)data[0] == _playerID) { _PlaySoundEffect(SoundFX.Damage); } _mainmap1.floatNumber((Coords)data[1], ((int)data[3]).ToString(), ((int)data[0] == _playerID) ? Color.Red : Color.White); break; case Backend.Events.KillActor: if ((int)data[0] < _logic.map.actors.Count) { _mainmap1.HandleEvent(true, Events.AnimateActor, data[0], Backend.Activity.Die); if ((int)data[0] == _playerID) { _PlaySoundEffect(SoundFX.Damage); } _mainmap1.floatNumber((Coords)data[1], ((int)data[3]).ToString(), ((int)data[0] == _playerID) ? Color.Red : Color.White); HandleEvent(false, Events.ShowMessage, _logic.map.actors[(int)data[0]].name + " was killed."); } break; case Backend.Events.ChangeStats: break; case Backend.Events.FireProjectile: break; case Backend.Events.PlaySound: _PlaySoundEffect((Backend.SoundFX)data[0]); break; case Backend.Events.ActivateAbility: /* if ((int)data[0] == _playerID) { if ((int)data[1] < 0) { int item = (int)data[1] + 1; } else { if ((int)data[1] > 0) { int ability = (int)data[1] - 1; } } }*/ break; case Backend.Events.Dialog: //from, to, message, new Backend.DialogLine[] { new Backend.DialogLine("Goodbye", -1) } _ShowTextBox((string)data[2]); HandleEvent(false, Events.ShowMessage, ((Actor)data[1]).name + "->" + ((Actor)data[0]).name + ":" + (string)data[2]); break; case Backend.Events.Shop: _ShowShopWindow((Actor)data[0], (Actor)data[1]); HandleEvent(false, Events.ShowMessage, ((Actor)data[0]).name + " and " + ((Actor)data[1]).name + " traded items."); break; case Events.SetItemTiles: break; case Events.Checkpoint: break; case Events.GameOver: _ShowEndGame("You escaped from the Dungeon!", "Game won"); break; case Backend.Events.FinishedAnimation: break; case Backend.Events.AnimateActor: _mainmap1.HandleEvent(true, Events.AnimateActor, data); break; case Backend.Events.ShowMessage: _AddMessage(data[0].ToString(), data.Length > 1 ? data[1] : null); break; case Events.MoveActor: _mainmap1.HandleEvent(true, Events.MoveActor, data); break; case Backend.Events.ChangeMap: _logic.ChangeMap((string)data[0], (Coords)data[1]); break; } } }
public override void Update(GameTime gameTime) { if (!_updating) { if ((_actor.newItems > 0) && (_functions[11].flash == 0)) { _functions[11].flash = 2; } if ((_actor.skills > 0) && (_functions[12].flash == 0)) { _functions[12].flash = 2; } if ((_actor.abilityPoints > 0) && (_functions[10].flash == 0)) { _functions[10].flash = 2; } _lastCheck += gameTime.ElapsedGameTime.Milliseconds; _updating = true; for (int i = 0; i < 10; ++i) { if ((_functions[i].id < 0) && (_actor.Items(-_functions[i].id).destroyed)) { if (_actor.Items(-_functions[i].id).itemType == Backend.ItemType.Potion) { bool found = false; for (int j = 0; j < _actor.inventory.Count; ++j) { if ((_actor.inventory[j].itemType == Backend.ItemType.Potion) && (_actor.inventory[j].effects[0].property == _actor.Items(-_functions[i].id).effects[0].property) && (!_actor.inventory[j].destroyed)) { bool duplicate = false; for (int k = 0; k < 10; ++k) { if (_actor.quickList[k] == -_actor.inventory[j].id) { duplicate = true; break; } } if (!duplicate) { found = true; _actor.quickList[i] = -_actor.inventory[j].id; _parent.HandleEvent(true, Backend.Events.UpdateToolbar, i, _actor.quickList[i]); _functions[i] = new GridElement(_actor.quickList[i], _actor.inventory[j].name, _actor.inventory[j].icon, _content, false, true, 5); break; } } } if (!found) { _functions[i].id = 0; _functions[i].enabled = false; } } else { _functions[i].id = 0; _functions[i].enabled = false; } } if (((_functions[i].id > 0) && ((_actor.mana > _actor.abilities[_functions[i].id - 1].cost) && (_actor.abilities[_functions[i].id - 1].currentCool <= 0))) || (_functions[i].id < 0)) _functions[i].enabled = true; else { _functions[i].enabled = false; if ((_lastCheck > 70) && (_functions[i].id > 0) && (_actor.abilities[_functions[i].id - 1].currentCool > 0)) _actor.abilities[_functions[i].id - 1].currentCool -= 1; } } if (_lastCheck > 350) { _lastCheck = 0; for (int i = 0; i < 13; ++i) { if (_functions[i].flash > 0) { _functions[i].flash -= 1; } } } _updating = false; } }
public bool OnMouseUp(int button) { if (_status != Backend.GameStatus.GameOver) { for (int i = 0; i < _interfaceElements.Count; ++i) { if (_interfaceElements[i].OnMouseUp(button)) { _draggedObject = null; return true; } } _draggedObject = null; return true; } else { _draggedObject = null; if (_focus != null) _focus.OnMouseUp(button); return true; } }
public override bool OnMouseUp(int button) { int cursel = Pos2Tile(Mouse.GetState().X, Mouse.GetState().Y); if (cursel != -1) { switch (cursel) { case 10: _functions[10].check = !_functions[10].check; _parent.HandleEvent(true, Backend.Events.ShowCharacter, _actor); break; case 11: _functions[11].check = !_functions[11].check; _parent.HandleEvent(true, Backend.Events.ShowInventory, _actor); break; case 12: _functions[12].check = !_functions[12].check; _parent.HandleEvent(true, Backend.Events.ShowAbilities, _actor); break; case 13: _functions[13].check = !_functions[13].check; _parent.HandleEvent(true, Backend.Events.ShowMenu); break; default: if (_dragItem != null) { for (int i = 0; i < 10; ++i) { if (_actor.quickList[i] == _dragItem.id) { _actor.quickList[i] = 0; _functions[i].id = 0; _functions[i].enabled = false; } } _functions[cursel] = _dragItem; _actor.quickList[cursel] = _dragItem.id; _parent.HandleEvent(true, Backend.Events.UpdateToolbar, cursel, _dragItem.id); } else { if ((_functions[cursel].id != 0) && (_functions[cursel].enabled) && (_functions[cursel].flash == 0)) { _functions[cursel].flash = 5; _parent.HandleEvent(true, Backend.Events.ActivateAbility, _actor, _functions[cursel].id); } } break; } } _dragItem = null; return base.OnMouseUp(button); }