Ejemplo n.º 1
0
        public virtual bool OnOpen(IClickableMenu menu)
        {
            currentGiftInfo = null;
            isOpen          = true;

            return(true);
        }
Ejemplo n.º 2
0
        public virtual void Init(IClickableMenu menu)
        {
            if (isInitialized)
            {
                Utils.DebugLog("BaseGiftHelper already initialized; skipping");
                return;
            }

            npcGiftInfo = new Dictionary <string, NPCGiftInfo>();

            // TODO: filter out names that will never be used
            Dictionary <string, string> npcGiftTastes = Game1.NPCGiftTastes;

            foreach (KeyValuePair <string, string> giftTaste in npcGiftTastes)
            {
                // The first few elements are universal_tastes and we only want names.
                // None of the names contain an underscore so we can check that way.
                string npcName = giftTaste.Key;
                if (npcName.IndexOf('_') != -1)
                {
                    continue;
                }

                string[] giftTastes = giftTaste.Value.Split(new char[] { '/' });
                if (giftTastes.Length > 0)
                {
                    string[] favouriteGifts = giftTastes[1].Split(new char[] { ' ' });
                    npcGiftInfo[npcName] = new NPCGiftInfo(npcName, favouriteGifts, maxItemsToDisplay);
                }
            }

            isInitialized = true;
        }
Ejemplo n.º 3
0
        private void DrawGiftCalTooltip(NPCGiftInfo giftInfo, string title)
        {
            // Approximate where the original tooltip will be positioned
            SVector2 origHoverTextSize = SVector2.MeasureString(calendar.GetCurrentHoverText(), Game1.dialogueFont);

            // Draw the tooltip
            DrawGiftTooltip(giftInfo, title, origHoverTextSize, "cal");
        }
Ejemplo n.º 4
0
        private void DrawGiftSocTooltip(NPCGiftInfo giftInfo, string title)
        {
            // Approximate where the original tooltip will be positioned
            SVector2 origHoverTextSize = SVector2.MeasureString("", Game1.dialogueFont);

            // Draw the tooltip
            DrawGiftTooltip(giftInfo, title, origHoverTextSize, "");
        }
Ejemplo n.º 5
0
        public void DrawGiftTooltip(NPCGiftInfo giftInfo, string title, string originalTooltipText = "")
        {
            int numItems = giftInfo.FavouriteGifts.Length;

            if (numItems == 0)
            {
                return;
            }

            float     spriteScale      = 2.0f * ZoomLevel;                               // 16x16 is pretty small
            Rectangle spriteRect       = giftInfo.FavouriteGifts[0].tileSheetSourceRect; // We just need the dimensions which we assume are all the same
            SVector2  scaledSpriteSize = new SVector2(spriteRect.Width * spriteScale, spriteRect.Height * spriteScale);

            // The longest length of text will help us determine how wide the tooltip box should be
            SVector2 titleSize   = SVector2.MeasureString(title, Game1.smallFont);
            SVector2 maxTextSize = (titleSize.x - scaledSpriteSize.x > giftInfo.MaxGiftNameSize.x) ? titleSize : giftInfo.MaxGiftNameSize;

            SVector2 mouse = new SVector2(Game1.getOldMouseX(), Game1.getOldMouseY());

            int padding   = 4; // Chosen by fair dice roll
            int rowHeight = (int)Math.Max(maxTextSize.y * ZoomLevel, scaledSpriteSize.yi) + padding;
            int width     = AdjustForTileSize((maxTextSize.x * ZoomLevel) + scaledSpriteSize.xi) + padding;
            int height    = AdjustForTileSize(rowHeight * (numItems + 1), 0.5f); // Add one to make room for the title
            int x         = AdjustForTileSize(mouse.x, 0.5f, ZoomLevel);
            int y         = AdjustForTileSize(mouse.y, 0.5f, ZoomLevel);

            int viewportW = Game1.viewport.Width;
            int viewportH = Game1.viewport.Height;

            // Let derived classes adjust the positioning
            AdjustTooltipPosition(ref x, ref y, width, height, viewportW, viewportH);

            // Approximate where the original tooltip will be positioned if there is an existing one we need to account for
            origHoverTextSize = SVector2.MeasureString(originalTooltipText, Game1.dialogueFont);
            int origTToffsetX = 0;

            if (origHoverTextSize.x > 0)
            {
                origTToffsetX = Math.Max(0, AdjustForTileSize(origHoverTextSize.x + mouse.x, 1.0f) - viewportW) + width;
            }

            // Consider the position of the original tooltip and ensure we don't cover it up
            SVector2 tooltipPos = ClampToViewport(x - origTToffsetX, y, width, height, viewportW, viewportH, mouse);

            // Reduce the number items shown if it will go off screen.
            // TODO: add a scrollbar or second column
            if (height > viewportH)
            {
                numItems = (viewportH / rowHeight) - 1; // Remove an item to make space for the title
                height   = AdjustForTileSize(rowHeight * numItems);
            }

            // Draw the background of the tooltip
            SpriteBatch spriteBatch = Game1.spriteBatch;

            // Part of the spritesheet containing the texture we want to draw
            Rectangle menuTextureSourceRect = new Rectangle(0, 256, 60, 60);

            IClickableMenu.drawTextureBox(spriteBatch, Game1.menuTexture, menuTextureSourceRect, tooltipPos.xi, tooltipPos.yi, width, height, Color.White, ZoomLevel);

            // Offset the sprite from the corner of the bg, and the text to the right and centered vertically of the sprite
            SVector2 spriteOffset = new SVector2(AdjustForTileSize(tooltipPos.x, 0.25f), AdjustForTileSize(tooltipPos.y, 0.25f));
            SVector2 textOffset   = new SVector2(spriteOffset.x, spriteOffset.y + (spriteRect.Height / 2));

            // Draw the title then set up the offset for the remaining text
            DrawText(title, textOffset);
            textOffset.x   += scaledSpriteSize.x + padding;
            textOffset.y   += rowHeight;
            spriteOffset.y += rowHeight;

            for (int i = 0; i < numItems; ++i)
            {
                NPCGiftInfo.ItemData item = giftInfo.FavouriteGifts[i];

                // Draw the sprite for the item then the item text
                DrawText(item.name, textOffset);
                DrawTexture(Game1.objectSpriteSheet, spriteOffset, item.tileSheetSourceRect, spriteScale);

                // Move to the next row
                spriteOffset.y += rowHeight;
                textOffset.y   += rowHeight;
            }
        }
Ejemplo n.º 6
0
 public virtual void OnClose()
 {
     currentGiftInfo  = null;
     drawCurrentFrame = false;
     isOpen           = false;
 }