Exemplo n.º 1
0
        /// <summary>
        /// Display context menu related to the object mousePos is hovering
        /// </summary>
        /// <param name="screenPos">Screen position</param>
        /// <param name="worldPos">World position</param>
        private void DisplayContextMenu(Vector2 screenPos, Vector2 worldPos)
        {
            if (ActiveContextMenu != null)
            {
                return;
            }

            if (SelectedGameObjects.Length == 0)
            {
                // No objects found, display context menu for World
                WorldContextMenu.Update(screenPos, Game);
                ActiveContextMenu = WorldContextMenu;
            }
            else if (SelectedGameObjects.Length == 1)
            {
                var character = SelectedGameObjects[0] as Character;
                if (character != null)
                {
                    CharacterContextMenu.Update(screenPos, SelectedGameObjects[0], _world.Player.Link);
                    ActiveContextMenu = CharacterContextMenu;
                }

                var equipment = SelectedGameObjects[0] as IEquipment;
                if (equipment != null)
                {
                    EquipmentContextMenu.Update(screenPos, SelectedGameObjects[0], _world.Player.Link);
                    ActiveContextMenu = EquipmentContextMenu;
                }

                // No derived game objects context menu found, use default
                if (ActiveContextMenu == null)
                {
                    GameObjectContextMenu.Update(screenPos, SelectedGameObjects[0], _world.Player.Link);
                    ActiveContextMenu = GameObjectContextMenu;
                }
            }
            else
            {
                GameObjectsContextMenu.Update(screenPos, SelectedGameObjects, _world.Player.Link);
                ActiveContextMenu = GameObjectsContextMenu;
            }

            if (ActiveContextMenu != null)
            {
                _gui.Screen.Desktop.Children.Add(ActiveContextMenu);

                // Subscribe to command executed event
                ActiveContextMenu.CommandExecuted += ContextCommandExecuted;
            }
        }
Exemplo n.º 2
0
        public override void Initialize()
        {
            base.Initialize();

            SelectionBounds     = Rectangle.Empty;
            SelectedGameObjects = new GameObject[0];

            SetupOverlays();

            // Setup context menus
            WorldContextMenu       = new WorldContextMenu();
            GameObjectContextMenu  = new GameObjectContextMenu();
            GameObjectsContextMenu = new GameObjectsContextMenu();
            EquipmentContextMenu   = new EquipmentContextMenu();
            CharacterContextMenu   = new CharacterContextMenu();
        }