public ContextMenu(Entity entity, Vector2f creationPos, IResourceManager resourceManager, IUserInterfaceManager userInterfaceManager, bool showExamine = true) { _owningEntity = entity; _resourceManager = resourceManager; _userInterfaceManager = userInterfaceManager; var entries = new List<ContextMenuEntry>(); var replies = new List<ComponentReplyMessage>(); entity.SendMessage(this, ComponentMessageType.ContextGetEntries, replies); if (replies.Any()) entries = (List<ContextMenuEntry>) replies.First(x => x.MessageType == ComponentMessageType.ContextGetEntries).ParamsList[0]; if (showExamine) { var examineButton = new ContextMenuButton( new ContextMenuEntry {ComponentMessage = "examine", EntryName = "Examine", IconName = "context_eye"}, _buttonSize, _resourceManager); examineButton.Selected += ContextSelected; _buttons.Add(examineButton); examineButton.Update(0); } var sVarButton = new ContextMenuButton( new ContextMenuEntry {ComponentMessage = "svars", EntryName = "SVars", IconName = "context_eye"}, _buttonSize, _resourceManager); sVarButton.Selected += ContextSelected; _buttons.Add(sVarButton); sVarButton.Update(0); foreach (ContextMenuEntry entry in entries) { var newButton = new ContextMenuButton(entry, _buttonSize, _resourceManager); newButton.Selected += ContextSelected; _buttons.Add(newButton); newButton.Update(0); } float currY = creationPos.Y; foreach (ContextMenuButton button in _buttons) { button.Position = new Vector2i((int) creationPos.X, (int) currY); currY += _buttonSize.Y; } ClientArea = new IntRect((int) creationPos.X, (int) creationPos.Y, (int) _buttonSize.X, _buttons.Count()*(int) _buttonSize.Y); }
private void ContextSelected(ContextMenuButton sender) { if ((string) sender.UserData == "examine") { var newExamine = new ExamineWindow(new Size(300, 200), _owningEntity, _resourceManager); _userInterfaceManager.AddComponent(newExamine); newExamine.Position = new Point(ClientArea.X, ClientArea.Y); } else if ((string) sender.UserData == "svars") { var newSVars = new SVarEditWindow(new Size(350, 400), _owningEntity); _userInterfaceManager.AddComponent(newSVars); newSVars.Position = new Point(ClientArea.X, ClientArea.Y); _owningEntity.GetComponent<ISVarsComponent>(ComponentFamily.SVars).GetSVarsCallback += newSVars.GetSVarsCallback; _owningEntity.GetComponent<ISVarsComponent>(ComponentFamily.SVars).DoGetSVars(); } else _owningEntity.SendMessage(this, ComponentMessageType.ContextMessage, (string) sender.UserData); }