コード例 #1
0
        private void Display_RenderedWorld(object sender, StardewModdingAPI.Events.RenderedWorldEventArgs e)
        {
            if (Game1.currentLocation == null)
            {
                return;
            }

            if (_showGrid)
            {
                TileInfoMenu.DrawGrid(e.SpriteBatch, colour: _gridColour, width: _gridWidth, opacity: 1f);
            }

            Point mouse          = Game1.getMousePosition();
            bool  isChildHovered = Desktop.Taskbar.IsExpanded && Desktop.Children.Any(child => child.isWithinBounds(mouse.X, mouse.Y) ||
                                                                                      ((child.GetParentMenu() is WindowBar windowBar) && windowBar.isWithinBounds(mouse.X, mouse.Y)));

            if (_showTileHighlight && !isChildHovered)
            {
                TileInfoMenu.DrawTileHighlight(e.SpriteBatch, colour: _tileHighlightColour);
            }
        }
コード例 #2
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            // Clicking show/hide button
            if (ExpandButton.containsPoint(x, y))
            {
                this.SetActiveState(!IsExpanded);
                return;
            }

            // Clicking main icon
            if (AvatarButton.containsPoint(x, y))
            {
                IClickableMenu menu = Desktop.Children.FirstOrDefault(child => nameof(ModInfoMenu) == child.GetType().Name);
                if (menu == null)
                {
                    Point position = new Point(width + (75 * MenuScale), 15 * MenuScale);
                    menu = new ModInfoMenu(position);
                    ((ModInfoMenu)menu).WindowBar.RealignElements();
                    Desktop.Children.Insert(0, menu);
                }
                else
                {
                    // Redirect to existing menu windows if they exist
                    if (menu.GetParentMenu() is WindowBar windowBar)
                    {
                        windowBar.IsMinimised = false;
                    }
                }
                return;
            }

            // Clicking mute icon
            if (MuteButton.containsPoint(x, y))
            {
                Desktop.IsMuted         = !Desktop.IsMuted;
                MuteButton.sourceRect.X = MuteButtonSource.X + (Desktop.IsMuted ? MuteButtonSource.Width : 0);
                return;
            }

            // Clicking taskbar icons
            if (Icons.FirstOrDefault(i => i.containsPoint(x, y)) is ClickableTextureComponent icon && icon != null)
            {
                IClickableMenu menu = Desktop.Children.FirstOrDefault(child => icon.name == child.GetType().Name);
                if (menu == null)
                {
                    // Add a new menu window to the desktop if no instance currently exists
                    IClickableMenu lastChild = Desktop.Children.LastOrDefault();
                    Point          position  = lastChild != null
                                                ? new Point(lastChild.xPositionOnScreen + (25 * MenuScale), lastChild.yPositionOnScreen + (25 * MenuScale))
                                                : new Point(width + (50 * MenuScale), 50 * MenuScale);

                    if (icon.name == nameof(CharacterListMenu))
                    {
                        menu = new CharacterListMenu(position: position);
                    }
                    else if (icon.name == nameof(TileInfoMenu))
                    {
                        menu = new TileInfoMenu(position: position);
                    }
                    else if (icon.name == nameof(MapViewMenu))
                    {
                        menu = new MapViewMenu(position: position);
                    }

                    if (menu != null)
                    {
                        // Resize the window bar once content has been loaded
                        menu.xPositionOnScreen -= Math.Max(0, Game1.viewport.Width - (menu.xPositionOnScreen + menu.width));
                        menu.yPositionOnScreen -= Math.Max(0, Game1.viewport.Height - (menu.yPositionOnScreen + menu.height));
                        ((WindowPage)menu).WindowBar.RealignElements();

                        // Register our new menu to the desktop
                        Desktop.Children.Add(menu);
                    }
                }
                else
                {
                    // Redirect to existing menu windows if they exist
                    if (menu.GetParentMenu() is WindowBar windowBar)
                    {
                        windowBar.IsMinimised = false;
                    }
                }
                return;
            }

            base.receiveLeftClick(x, y, playSound);
        }