Ejemplo n.º 1
0
        public SearchMenu(Farmer who, string appearanceFilter, HandMirrorMenu callbackMenu) : base(0, 0, 832, 576, showUpperRightCloseButton: true)
        {
            // Set up menu structure
            if (LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko || LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.fr)
            {
                base.height += 64;
            }

            Vector2 topLeft = Utility.getTopLeftPositionForCenteringOnScreen(base.width, base.height);

            base.xPositionOnScreen = (int)topLeft.X;
            base.yPositionOnScreen = (int)topLeft.Y;

            // Populate the texture selection components
            var appearancePacks = FashionSense.textureManager.GetAllAppearanceModels();

            switch (appearanceFilter)
            {
            case HandMirrorMenu.HAIR_FILTER_BUTTON:
                appearancePacks = FashionSense.textureManager.GetAllAppearanceModels().Where(m => m is HairContentPack).ToList();
                break;

            case HandMirrorMenu.ACCESSORY_FILTER_BUTTON:
                appearancePacks = FashionSense.textureManager.GetAllAppearanceModels().Where(m => m is AccessoryContentPack).ToList();
                break;

            case HandMirrorMenu.HAT_FILTER_BUTTON:
                appearancePacks = FashionSense.textureManager.GetAllAppearanceModels().Where(m => m is HatContentPack).ToList();
                break;

            case HandMirrorMenu.SHIRT_FILTER_BUTTON:
                appearancePacks = FashionSense.textureManager.GetAllAppearanceModels().Where(m => m is ShirtContentPack).ToList();
                break;

            case HandMirrorMenu.PANTS_FILTER_BUTTON:
                appearancePacks = FashionSense.textureManager.GetAllAppearanceModels().Where(m => m is PantsContentPack).ToList();
                break;

            case HandMirrorMenu.SLEEVES_FILTER_BUTTON:
                appearancePacks = FashionSense.textureManager.GetAllAppearanceModels().Where(m => m is SleevesContentPack).ToList();

                if (callbackMenu.GetCurrentFeatureSlotKey() == ModDataKeys.CUSTOM_SHOES_ID)
                {
                    appearancePacks = FashionSense.textureManager.GetAllAppearanceModels().Where(m => m is ShoesContentPack).ToList();
                }
                break;
            }

            for (int m = 0; m < appearancePacks.Count; m++)
            {
                filteredTextureOptions.Add(appearancePacks[m]);
                cachedTextureOptions.Add(appearancePacks[m]);
            }

            _displayFarmer    = who;
            _appearanceFilter = appearanceFilter;
            _callbackMenu     = callbackMenu;

            var drawingScale     = 4f;
            var widthOffsetScale = 3;
            var sourceRect       = new Rectangle(0, 0, Game1.daybg.Width, Game1.daybg.Height);

            for (int r = 0; r < _maxRows; r++)
            {
                for (int c = 0; c < _texturesPerRow; c++)
                {
                    var componentId = c + r * _texturesPerRow;
                    availableTextures.Add(new ClickableTextureComponent(new Rectangle(32 + base.xPositionOnScreen + IClickableMenu.borderWidth + componentId % _texturesPerRow * 64 * widthOffsetScale, base.yPositionOnScreen + sourceRect.Height / 2 + componentId + (r * sourceRect.Height) + (r > 0 ? 64 : 0) - 32, sourceRect.Width, sourceRect.Height), null, new Rectangle(), drawingScale, false)
                    {
                        myID            = componentId,
                        downNeighborID  = componentId + _texturesPerRow,
                        upNeighborID    = r >= _texturesPerRow ? componentId - _texturesPerRow : -1,
                        rightNeighborID = c == 5 ? 9997 : componentId + 1,
                        leftNeighborID  = c > 0 ? componentId - 1 : 9998
                    });

                    var fakeFarmer = _displayFarmer.CreateFakeEventFarmer();
                    fakeFarmer.faceDirection(who.facingDirection);
                    foreach (var key in _displayFarmer.modData.Keys)
                    {
                        fakeFarmer.modData[key] = _displayFarmer.modData[key];
                    }
                    fakeFarmers.Add(fakeFarmer);
                }
            }
            UpdateDisplayFarmers();

            backButton = new ClickableTextureComponent(new Rectangle(base.xPositionOnScreen - 64, base.yPositionOnScreen + 8, 48, 44), Game1.mouseCursors, new Rectangle(352, 495, 12, 11), 4f)
            {
                myID            = 9998,
                rightNeighborID = 0
            };
            forwardButton = new ClickableTextureComponent(new Rectangle(base.xPositionOnScreen + base.width + 64 - 48, base.yPositionOnScreen + base.height - 48, 48, 44), Game1.mouseCursors, new Rectangle(365, 495, 12, 11), 4f)
            {
                myID = 9997
            };

            // Textbox related
            var xTextbox = base.xPositionOnScreen + 64 + IClickableMenu.spaceToClearSideBorder + IClickableMenu.borderWidth + 320;
            var yTextbox = base.yPositionOnScreen - 58;

            _searchBox = new TextBox(Game1.content.Load <Texture2D>("LooseSprites\\textBox"), null, Game1.smallFont, Game1.textColor)
            {
                X          = xTextbox,
                Y          = yTextbox,
                Width      = 384,
                limitWidth = false,
                Text       = String.Empty
            };

            _searchBoxCC = new ClickableComponent(new Rectangle(xTextbox, yTextbox, 192, 48), "")
            {
                myID            = 9999,
                upNeighborID    = -99998,
                leftNeighborID  = -99998,
                rightNeighborID = -99998,
                downNeighborID  = -99998
            };
            Game1.keyboardDispatcher.Subscriber = _searchBox;
            _searchBox.Selected = true;

            queryButton = new ClickableTextureComponent(new Rectangle(xTextbox - 32, base.yPositionOnScreen - 48, 48, 44), Game1.mouseCursors, new Rectangle(208, 320, 16, 16), 2f)
            {
                myID = -1
            };

            // Call snap functions
            if (Game1.options.SnappyMenus)
            {
                base.populateClickableComponentList();
                snapToDefaultClickableComponent();
            }
        }