/// <summary>The method invoked when the player releases the left mouse button.</summary>
 /// <param name="x">The X-position of the cursor.</param>
 /// <param name="y">The Y-position of the cursor.</param>
 public override void releaseLeftClick(int x, int y)
 {
     // update color pickers
     if (m_lastHeldColorPicker != null)
     {
         m_lastHeldColorPicker.releaseClick();
     }
     m_lastHeldColorPicker = null;
     return;
 }
        /// <summary>Perform the action associated with a component.</summary>
        /// <param name="cpt">The component.</param>
        /// <return>whether the component action is processed</return>
        public override bool handleLeftClick(IAutoComponent cpt)
        {
            AutoColorPicker        p   = null;
            ClickableTextureButton btn = null;

            if (cpt is ClickableTextureButton)
            {
                btn = (ClickableTextureButton)cpt;
            }
            else if (cpt is AutoColorPicker)
            {
                p = (AutoColorPicker)cpt;
            }
            switch (cpt.m_name)
            {
            case "Male":
                m_farmerMakeup.ChangeGender(true);
                m_farmerMakeup.ChangeHairStyle(0);
                m_maleOutlineButton.m_visible   = true;
                m_femaleOutlineButton.m_visible = false;
                refreshLabelAttrs();
                break;

            case "Female":
                m_farmerMakeup.ChangeGender(false);
                m_farmerMakeup.ChangeHairStyle(16);
                m_maleOutlineButton.m_visible   = false;
                m_femaleOutlineButton.m_visible = true;
                refreshLabelAttrs();
                break;

            case "Direction":
                Game1.player.faceDirection((Game1.player.facingDirection - btn.m_par + 4) % 4);
                Game1.player.FarmerSprite.StopAnimation();
                Game1.player.completelyStopAnimatingOrDoingAction();
                Game1.playSound("pickUpItem");
                btn.scale = Math.Max(0.75f, btn.scale - 0.25f);
                return(true);

            case "OK":
                if (m_parent != null)
                {
                    m_parent.exitThisMenuNoSound();
                }
                else
                {
                    exitThisMenuNoSound();
                }
                break;

            case "Random":
                this.randomiseCharacter();
                btn.scale = Game1.pixelZoom - 0.5f;
                this.m_eyeColorPicker.setColor(Game1.player.newEyeColor);
                this.m_hairColorPicker.setColor(Game1.player.hairstyleColor);
                this.m_pantsColorPicker.setColor(Game1.player.pantsColor);
                refreshLabelAttrs();
                return(true);

            case "MultiplayerFix":
                m_farmerMakeup.TougleMultiplayerFix();
                btn.sourceRect.X = btn.sourceRect.X == 227 ? 236 : 227;
                Game1.playSound("drumkit6");
                return(true);

            case "EyeColorPicker":
                m_farmerMakeup.ChangeEyeColor(p.click(Game1.getOldMouseX(), Game1.getOldMouseY()));
                m_lastHeldColorPicker = p;
                return(true);

            case "HairColorPicker":
                m_farmerMakeup.ChangeHairColor(p.click(Game1.getOldMouseX(), Game1.getOldMouseY()));
                m_lastHeldColorPicker = p;
                return(true);

            case "PantsColorPicker":
                m_farmerMakeup.ChangeBottomsColor(p.click(Game1.getOldMouseX(), Game1.getOldMouseY()));
                m_lastHeldColorPicker = p;
                return(true);

            case "Fav":
                int i = btn.m_par;
                if (m_farmerMakeup.LoadFavorite(i + 1))
                {
                    Game1.playSound("yoba");
                    this.m_eyeColorPicker.setColor(Game1.player.newEyeColor);
                    this.m_hairColorPicker.setColor(Game1.player.hairstyleColor);
                    this.m_pantsColorPicker.setColor(Game1.player.pantsColor);
                    refreshLabelAttrs();
                }
                else
                {
                    m_alerts.Add(new Alert(Game1.mouseCursors, new Rectangle(268, 470, 16, 16), Game1.viewport.Width / 2 - (700 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (500 + IClickableMenu.borderWidth * 2) / 2, "Uh oh! No Favorite is Set!", 1000, false));
                    if (m_parent is MenuFarmerMakeup mk)
                    {
                        mk.ShowFavTabArrow = true;
                    }
                }
                return(true);

            default:
                if (btn != null)
                {
                    btn.scale = Math.Max(0.75f, btn.scale - 2.5f);
                    return(this.handleSelectorChange(btn.name, btn.m_par));
                }
                return(false);
            }
            Game1.playSound("coin");
            return(true);
        }
        /// <summary>Update the menu layout for a change in the zoom level or viewport size.</summary>
        public override void updateLayout()
        {
            // reset window position
            this.xPositionOnScreen  = (Game1.viewport.Width - this.width) / 2;
            this.yPositionOnScreen  = (Game1.viewport.Height - this.height) / 2;
            this.yPositionOnScreen += Game1.tileSize / 2;

            int xBase = xPositionOnScreen + IClickableMenu.borderWidth;
            int yBase = yPositionOnScreen + IClickableMenu.borderWidth;

            m_alerts.Clear();
            m_components.Clear();
            m_selectValueLabels.Clear();

            // random button
            m_components.Add(new ClickableTextureButton("Random", new Rectangle(xBase, yBase, Game1.pixelZoom * 10, Game1.pixelZoom * 10), null, "Random", Game1.mouseCursors, new Rectangle(381, 361, 10, 10), Game1.pixelZoom)
            {
                m_hoverScale = 0.25f
            });
            // portrait
            m_components.Add(new PortraitComponent(xBase + Game1.tileSize * 3 / 4, yBase));
            // direction buttons
            int xOffset = xBase + Game1.tileSize / 4;
            int yOffset = yBase + Game1.tileSize / 4 + Game1.tileSize * 2;

            m_components.Add(new ClickableTextureButton("Direction", new Rectangle(xOffset, yOffset, Game1.tileSize, Game1.tileSize), "", "", Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 44), 1f)
            {
                m_par = -1, m_hoverScale = 0.1f
            });
            m_components.Add(new ClickableTextureButton("Direction", new Rectangle(xOffset + Game1.tileSize * 2, yOffset, Game1.tileSize, Game1.tileSize), "", "", Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 33), 1f)
            {
                m_par = 1, m_hoverScale = 0.1f
            });
            // gender buttons
            if (m_globalConfig.CanChangeGender)
            {
                int scale = Game1.pixelZoom / 2;
                m_components.Add(new ClickableTextureButton("Male", new Rectangle(xBase + Game1.tileSize * 3, yBase, Game1.tileSize, Game1.tileSize), null, "Male", Game1.mouseCursors, new Rectangle(128, 192, 16, 16), scale));
                m_components.Add(new ClickableTextureButton("Female", new Rectangle(xBase + Game1.tileSize * 3, yBase + Game1.tileSize, Game1.tileSize, Game1.tileSize), null, "Female", Game1.mouseCursors, new Rectangle(144, 192, 16, 16), scale));
                this.m_maleOutlineButton = new ClickableTextureButton("", new Rectangle(
                                                                          xBase + Game1.tileSize * 3 - 3,
                                                                          yBase - 3,
                                                                          Game1.tileSize, Game1.tileSize), "", "", m_menuTextures, new Rectangle(19, 38, 19, 19), scale)
                {
                    m_visible = Game1.player.isMale
                };
                this.m_femaleOutlineButton = new ClickableTextureButton("", new Rectangle(
                                                                            xBase + Game1.tileSize * 3 - 3,
                                                                            yBase + Game1.tileSize - 3,
                                                                            Game1.tileSize, Game1.tileSize), "", "", m_menuTextures, new Rectangle(19, 38, 19, 19), scale)
                {
                    m_visible = !Game1.player.isMale
                };
                m_components.Add(m_maleOutlineButton);
                m_components.Add(m_femaleOutlineButton);
            }
            // color pickers
            {
                // eye color
                xOffset = xBase + Game1.tileSize * 4 + Game1.tileSize / 4;
                yOffset = yBase;
                int xPickerOffset = Game1.tileSize * 3 - Game1.tileSize / 4;
                int yLabelOffset  = 16;
                m_components.Add(new LabelComponent(new Rectangle(xOffset, yOffset + yLabelOffset, 1, 1), "Eye Color:"));
                this.m_eyeColorPicker = new AutoColorPicker("EyeColorPicker", xOffset + xPickerOffset, yOffset);
                this.m_eyeColorPicker.setColor(Game1.player.newEyeColor);
                m_components.Add(m_eyeColorPicker);
                // hair color
                yOffset += Game1.tileSize + 8;
                m_components.Add(new LabelComponent(new Rectangle(xOffset, yOffset + yLabelOffset, 1, 1), "Hair Color:"));
                this.m_hairColorPicker = new AutoColorPicker("HairColorPicker", xOffset + xPickerOffset, yOffset);
                this.m_hairColorPicker.setColor(Game1.player.hairstyleColor);
                m_components.Add(m_hairColorPicker);
                // pants color
                yOffset += Game1.tileSize + 8;
                m_components.Add(new LabelComponent(new Rectangle(xOffset, yOffset + yLabelOffset, 1, 1), "Pants Color:"));
                this.m_pantsColorPicker = new AutoColorPicker("PantsColorPicker", xOffset + xPickerOffset, yOffset);
                this.m_pantsColorPicker.setColor(Game1.player.pantsColor);
                m_components.Add(m_pantsColorPicker);
            }
            // type selectors
            {
                xOffset = xBase + Game1.tileSize / 4;
                yOffset = yBase + Game1.tileSize * 3 + Game1.tileSize / 2;
                int   xGap                 = xBase + Game1.tileSize * 4 - Game1.tileSize / 4;
                int[] xSelectorOffset      = new int[] { Game1.tileSize / 4, Game1.tileSize, Game1.tileSize * 2 };
                int[] xSelectorRightOffset = new int[] { Game1.tileSize / 4, Game1.tileSize + 8, Game1.tileSize * 3 };
                selectorLayout(xOffset, xSelectorOffset, yOffset, Attr.Hair);
                m_components.Add(new ClickableTextureButton("MultiplayerFix", new Rectangle(
                                                                xGap + xSelectorRightOffset[0] + 5,
                                                                yOffset + Game1.tileSize / 4,
                                                                36, 36), null, null, Game1.mouseCursors, new Rectangle(m_farmerMakeup.m_config.MutiplayerFix ? 236 : 227, 425, 9, 9), 4f, false));
                m_components.Add(new LabelComponent(new Rectangle(xGap + xSelectorRightOffset[1], yOffset + Game1.tileSize / 4, 1, 1), "Multiplayer Fix"));

                yOffset += Game1.tileSize + 4;
                selectorLayout(xOffset, xSelectorOffset, yOffset, Attr.Skin);
                selectorLayout(xGap, xSelectorRightOffset, yOffset, Attr.Face);
                yOffset += Game1.tileSize + 4;
                selectorLayout(xOffset, xSelectorOffset, yOffset, Attr.Shirt);
                selectorLayout(xGap, xSelectorRightOffset, yOffset, Attr.Nose);
                yOffset += Game1.tileSize + 4;
                selectorLayout(xOffset, xSelectorOffset, yOffset, Attr.ShoeColor);
                selectorLayout(xGap, xSelectorRightOffset, yOffset, Attr.Bottoms);
                yOffset += Game1.tileSize + 4;
                selectorLayout(xOffset, xSelectorOffset, yOffset, Attr.Accessory);
                selectorLayout(xGap, xSelectorRightOffset, yOffset, Attr.Shoes);
            }
            // quick favorite star buttons
            {
                xOffset = xBase + Game1.tileSize * 8 + Game1.tileSize / 2;
                yOffset = yBase + Game1.tileSize * 3 + Game1.tileSize / 2;
                // text above quick favorite buttons
                m_components.Add(new LabelComponent(new Rectangle(
                                                        xOffset + 10,
                                                        yOffset,
                                                        1, 1), "Load"));
                m_components.Add(new LabelComponent(new Rectangle(
                                                        xOffset - Game1.tileSize / 4 + 5,
                                                        yOffset + 25,
                                                        1, 1), "Favorite"));

                yOffset += 75;
                int size = Game1.pixelZoom * 10;
                int zoom = Game1.pixelZoom;
                int y1   = m_farmerMakeup.m_config.HasFavSlot(1) ? 26 : 67;
                int y2   = m_farmerMakeup.m_config.HasFavSlot(2) ? 26 : 67;
                int y3   = m_farmerMakeup.m_config.HasFavSlot(3) ? 26 : 67;
                int y4   = m_farmerMakeup.m_config.HasFavSlot(4) ? 26 : 67;
                int y5   = m_farmerMakeup.m_config.HasFavSlot(5) ? 26 : 67;
                int y6   = m_farmerMakeup.m_config.HasFavSlot(6) ? 26 : 67;
                this.m_quickLoadFavButtons = new[] {
                    new ClickableTextureButton("Fav", new Rectangle(xOffset + 0, yOffset + 0, size, size), m_menuTextures, new Rectangle(24, y1, 8, 8), zoom)
                    {
                        m_par = 0, m_hoverScale = 0.2f
                    },
                    new ClickableTextureButton("Fav", new Rectangle(xOffset + 0, yOffset + Game1.tileSize + 4, size, size), m_menuTextures, new Rectangle(8, y2, 8, 8), zoom)
                    {
                        m_par = 1, m_hoverScale = 0.2f
                    },
                    new ClickableTextureButton("Fav", new Rectangle(xOffset + 0, yOffset + (Game1.tileSize + 4) * 2, size, size), m_menuTextures, new Rectangle(0, y3, 8, 8), zoom)
                    {
                        m_par = 2, m_hoverScale = 0.2f
                    },
                    new ClickableTextureButton("Fav", new Rectangle(xOffset + 45, yOffset + 0, size, size), m_menuTextures, new Rectangle(24, y4, 8, 8), zoom)
                    {
                        m_par = 3, m_hoverScale = 0.2f
                    },
                    new ClickableTextureButton("Fav", new Rectangle(xOffset + 45, yOffset + Game1.tileSize + 4, size, size), m_menuTextures, new Rectangle(8, y5, 8, 8), zoom)
                    {
                        m_par = 4, m_hoverScale = 0.2f
                    },
                    new ClickableTextureButton("Fav", new Rectangle(xOffset + 45, yOffset + (Game1.tileSize + 4) * 2, size, size), m_menuTextures, new Rectangle(0, y6, 8, 8), zoom)
                    {
                        m_par = 5, m_hoverScale = 0.2f
                    }
                };
                for (int i = 0; i < m_quickLoadFavButtons.Length; ++i)
                {
                    m_components.Add(m_quickLoadFavButtons[i]);
                }
                m_components.Add(new ClickableTextureButton("OK", new Rectangle(xOffset + 8, yOffset + (Game1.tileSize + 4) * 3 - Game1.tileSize / 4, Game1.tileSize, Game1.tileSize), null, null, Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46), 1f)
                {
                    m_hoverScale = 0.1f
                });
            }
        }