private void drawGridLayout() { var forSale = Helper.Reflection.GetField <List <ISalable> >(shop, "forSale").GetValue(); var itemPriceAndStock = Helper.Reflection.GetField <Dictionary <ISalable, int[]> >(shop, "itemPriceAndStock").GetValue(); var currency = Helper.Reflection.GetField <int>(shop, "currency").GetValue(); var animations = Helper.Reflection.GetField <List <TemporaryAnimatedSprite> >(shop, "animations").GetValue(); var poof = Helper.Reflection.GetField <TemporaryAnimatedSprite>(shop, "poof").GetValue(); var heldItem = Helper.Reflection.GetField <Item>(shop, "heldItem").GetValue(); var currentItemIndex = Helper.Reflection.GetField <int>(shop, "currentItemIndex").GetValue(); var scrollBar = Helper.Reflection.GetField <ClickableTextureComponent>(shop, "scrollBar").GetValue(); var scrollBarRunner = Helper.Reflection.GetField <Rectangle>(shop, "scrollBarRunner").GetValue(); const int UNIT_WIDTH = 160; const int UNIT_HEIGHT = 144; int unitsWide = (shop.width - 32) / UNIT_WIDTH; ISalable hover = null; Texture2D purchase_texture = Game1.mouseCursors; Rectangle purchase_window_border = new Rectangle(384, 373, 18, 18); Rectangle purchase_item_rect = new Rectangle(384, 396, 15, 15); int purchase_item_text_color = -1; bool purchase_draw_item_background = true; Rectangle purchase_item_background = new Rectangle(296, 363, 18, 18); Color purchase_selected_color = Color.Wheat; if (shop.storeContext == "QiGemShop") { purchase_texture = Game1.mouseCursors2; purchase_window_border = new Rectangle(0, 256, 18, 18); purchase_item_rect = new Rectangle(18, 256, 15, 15); purchase_item_text_color = 4; purchase_selected_color = Color.Blue; purchase_draw_item_background = true; purchase_item_background = new Rectangle(33, 256, 18, 18); } //IClickableMenu.drawTextureBox(Game1.spriteBatch, Game1.mouseCursors, new Rectangle(384, 373, 18, 18), shop.xPositionOnScreen + shop.width - shop.inventory.width - 32 - 24, shop.yPositionOnScreen + shop.height - 256 + 40, shop.inventory.width + 56, shop.height - 448 + 20, Color.White, 4f, true); //IClickableMenu.drawTextureBox(Game1.spriteBatch, Game1.mouseCursors, new Rectangle(384, 373, 18, 18), shop.xPositionOnScreen, shop.yPositionOnScreen, shop.width, shop.height - 256 + 32 + 4, Color.White, 4f, true); IClickableMenu.drawTextureBox(Game1.spriteBatch, purchase_texture, purchase_window_border, shop.xPositionOnScreen, shop.yPositionOnScreen, shop.width, shop.height - 256 + 32 + 4, Color.White, 4f); for (int i = currentItemIndex * unitsWide; i < forSale.Count && i < currentItemIndex * unitsWide + unitsWide * 3; ++i) { bool failedCanPurchaseCheck = false; if (shop.canPurchaseCheck != null && !shop.canPurchaseCheck(i)) { failedCanPurchaseCheck = true; } int ix = i % unitsWide; int iy = i / unitsWide; Rectangle rect = new Rectangle(shop.xPositionOnScreen + 16 + ix * UNIT_WIDTH, shop.yPositionOnScreen + 16 + iy * UNIT_HEIGHT - currentItemIndex * UNIT_HEIGHT, UNIT_WIDTH, UNIT_HEIGHT); IClickableMenu.drawTextureBox(Game1.spriteBatch, purchase_texture, purchase_item_rect, rect.X, rect.Y, rect.Width, rect.Height, rect.Contains(Game1.getOldMouseX(), Game1.getOldMouseY()) ? purchase_selected_color : Color.White, 4f, false); ISalable item = forSale[i]; bool buyInStacks = item.Stack > 1 && item.Stack != int.MaxValue && itemPriceAndStock[item][1] == int.MaxValue; StackDrawType stackDrawType; if (shop.storeContext == "QiGemShop") { stackDrawType = StackDrawType.HideButShowQuality; buyInStacks = (item.Stack > 1); } else if (shop.itemPriceAndStock[item][1] == int.MaxValue) { stackDrawType = StackDrawType.HideButShowQuality; } else { stackDrawType = StackDrawType.Draw_OneInclusive; if (Helper.Reflection.GetField <bool>(shop, "_isStorageShop").GetValue()) { stackDrawType = StackDrawType.Draw; } } if (forSale[i].ShouldDrawIcon()) { if (purchase_draw_item_background) { //Game1.spriteBatch.Draw( purchase_texture, new Vector2( rect.X + 48 + 4, rect.Y + 16 ), purchase_item_background, Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 1f ); } item.drawInMenu(Game1.spriteBatch, new Vector2(rect.X + 48, rect.Y + 16), 1f, 1, 1, stackDrawType, Color.White, true); } int price = itemPriceAndStock[forSale[i]][0]; var priceStr = price.ToString(); if (price > 0) { SpriteText.drawString(Game1.spriteBatch, priceStr, rect.Right - SpriteText.getWidthOfString(priceStr) - 16, rect.Y + 80, alpha: ShopMenu.getPlayerCurrencyAmount(Game1.player, currency) >= price && !failedCanPurchaseCheck ? 1f : 0.5f, color: purchase_item_text_color); //Utility.drawWithShadow(Game1.spriteBatch, Game1.mouseCursors, new Vector2(rect.Right - 16, rect.Y + 80), new Rectangle(193 + currency * 9, 373, 9, 10), Color.White, 0, Vector2.Zero, 1, layerDepth: 1); } else if (itemPriceAndStock[forSale[i]].Length > 2) { int required_item_count = 5; int requiredItem = itemPriceAndStock[forSale[i]][2]; if (itemPriceAndStock[forSale[i]].Length > 3) { required_item_count = itemPriceAndStock[forSale[i]][3]; } bool hasEnoughToTrade = Game1.player.hasItemInInventory(requiredItem, required_item_count); if (shop.canPurchaseCheck != null && !shop.canPurchaseCheck(i)) { hasEnoughToTrade = false; } float textWidth = SpriteText.getWidthOfString("x" + required_item_count); Utility.drawWithShadow(Game1.spriteBatch, Game1.objectSpriteSheet, new Vector2(( float )(rect.Right - 64) - textWidth, rect.Y + 80 - 4), Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, requiredItem, 16, 16), Color.White * (hasEnoughToTrade ? 1f : 0.25f), 0f, Vector2.Zero, 3, flipped: false, -1f, -1, -1, hasEnoughToTrade ? 0.35f : 0f); SpriteText.drawString(Game1.spriteBatch, "x" + required_item_count, rect.Right - ( int )textWidth - 16, rect.Y + 80, 999999, -1, 999999, hasEnoughToTrade ? 1f : 0.5f, 0.88f, junimoText: false, -1, "", purchase_item_text_color); } if (rect.Contains(Game1.getOldMouseX(), Game1.getOldMouseY())) { hover = forSale[i]; } } if (forSale.Count == 0) { SpriteText.drawString(Game1.spriteBatch, Game1.content.LoadString("Strings\\StringsFromCSFiles:ShopMenu.cs.11583"), shop.xPositionOnScreen + shop.width / 2 - SpriteText.getWidthOfString(Game1.content.LoadString("Strings\\StringsFromCSFiles:ShopMenu.cs.11583"), 999999) / 2, shop.yPositionOnScreen + shop.height / 2 - 128, 999999, -1, 999999, 1f, 0.88f, false, -1, "", -1); } //shop.inventory.draw(Game1.spriteBatch); // Moved currency here so above doesn't draw over it //if (currency == 0) // Game1.dayTimeMoneyBox.drawMoneyBox(Game1.spriteBatch, shop.xPositionOnScreen - 36, shop.yPositionOnScreen + shop.height - shop.inventory.height + 48); for (int index = animations.Count - 1; index >= 0; --index) { if (animations[index].update(Game1.currentGameTime)) { animations.RemoveAt(index); } else { animations[index].draw(Game1.spriteBatch, true, 0, 0, 1f); } } if (poof != null) { poof.draw(Game1.spriteBatch, false, 0, 0, 1f); } // arrows already drawn if (forSale.Count > 18) { IClickableMenu.drawTextureBox(Game1.spriteBatch, Game1.mouseCursors, new Rectangle(403, 383, 6, 6), scrollBarRunner.X, scrollBarRunner.Y, scrollBarRunner.Width, scrollBarRunner.Height, Color.White, 4f, true); scrollBar.draw(Game1.spriteBatch); } if (hover != null) { string hoverText = hover.getDescription(); string boldTitleText = hover.DisplayName; int hoverPrice = itemPriceAndStock == null || !itemPriceAndStock.ContainsKey(hover) ? hover.salePrice() : itemPriceAndStock[hover][0]; int getHoveredItemExtraItemIndex = -1; if (itemPriceAndStock != null && hover != null && (itemPriceAndStock.ContainsKey(hover) && itemPriceAndStock[hover].Length > 2)) { getHoveredItemExtraItemIndex = itemPriceAndStock[hover][2]; } int getHoveredItemExtraItemAmount = 5; if (itemPriceAndStock != null && hover != null && itemPriceAndStock.ContainsKey(hover) && itemPriceAndStock[hover].Length > 3) { getHoveredItemExtraItemAmount = itemPriceAndStock[hover][3]; } IClickableMenu.drawToolTip(Game1.spriteBatch, hoverText, boldTitleText, hover as Item, heldItem != null, -1, currency, getHoveredItemExtraItemIndex, getHoveredItemExtraItemAmount, (CraftingRecipe)null, hoverPrice); } if (heldItem != null) { heldItem.drawInMenu(Game1.spriteBatch, new Vector2((float)(Game1.getOldMouseX() + 8), (float)(Game1.getOldMouseY() + 8)), 1f); } // some other stuff I don't think matters? }
public override void draw(SpriteBatch b) { // Fade the area b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f); // Draw the main box, along with the money box Game1.drawDialogueBox(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, speaker: false, drawOnlyBox: true, r: 80, g: 123, b: 186); Game1.dayTimeMoneyBox.drawMoneyBox(b); // See if we're checking out if (isCheckingOut) { b.Draw(JojaResources.GetJojaCheckoutBackground(), new Rectangle(this.xPositionOnScreen + IClickableMenu.borderWidth - 8, this.yPositionOnScreen + IClickableMenu.borderWidth + 56, this.width - (IClickableMenu.borderWidth * 2) + 16, this.height - 128), new Rectangle(0, 0, 150, 200), Color.White); // Draw cancel button cancelButton.draw(b); // Draw item icon, name and quantity int subTotal = 0; int stackCount = 0; int uniqueItemCount = 1; int rowStart = scale == 1f ? 120 : 140; int rowSpacing = scale == 1f ? 45 : 40; float textScale = scale == 1f ? 1f : 0.5f; float itemScaling = scale == 1f ? 0.5f : 0.4f; foreach (ISalable item in itemsInCart.Keys) { // Draw item item.Stack = itemsInCart[item][1]; item.drawInMenu(b, GetScaledVector(80, rowStart + (rowSpacing * uniqueItemCount)), itemScaling, 1f, 0.9f, StackDrawType.Hide, Color.White, drawShadow: false); // Draw name / quantity and price Utility.drawTextWithShadow(b, $"{item.DisplayName} x{item.Stack}", Game1.dialogueFont, new Vector2(this.xPositionOnScreen + this.width / 4, GetScaledYCoordinate(rowStart + 10 + (rowSpacing * uniqueItemCount))), Color.White, textScale, 0.5f, numShadows: 0, shadowIntensity: 0); int stackCost = item.Stack * itemsInCart[item][0]; Utility.drawTextWithShadow(b, stackCost + "g", Game1.dialogueFont, new Vector2((int)(this.xPositionOnScreen + this.width - this.width / 6 - IClickableMenu.borderWidth), GetScaledYCoordinate(rowStart + 10 + (rowSpacing * uniqueItemCount))), item == randomSaleItem ? Color.Cyan : Color.White, textScale, 0.5f, numShadows: 0, shadowIntensity: 0); stackCount += item.Stack; subTotal += stackCost; uniqueItemCount++; } // Check if purchased item(s) contain Joja Prime, if so offer free shipping bool isPurchasingPrimeShipping = itemsInCart.Any(i => (i.Key as Item).ParentSheetIndex == JojaItems.GetJojaPrimeMembershipID()) ? true : false; // Draw the shipping options (free 2 day or next day with fee) Utility.drawTextWithShadow(b, "Options", Game1.dialogueFont, new Vector2(this.xPositionOnScreen + 85 * scale, (this.yPositionOnScreen + this.height - this.height / 3) - 20 * scale), Color.White, scale, 0.6f, numShadows: 0, shadowIntensity: 0); IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 373, 9, 9), this.twoDayShippingButton.bounds.X, this.twoDayShippingButton.bounds.Y, this.twoDayShippingButton.bounds.Width, this.twoDayShippingButton.bounds.Height, isNextDayShipping ? Color.White : Color.Gray, scale * 4f * twoDayShippingButton.scale, false); Utility.drawTextWithShadow(b, "Two Day (Free)", Game1.dialogueFont, new Vector2(this.twoDayShippingButton.bounds.X + 12 * scale, this.twoDayShippingButton.bounds.Y + (LocalizedContentManager.CurrentLanguageLatin ? 16 : 12) * scale), Game1.textColor * (isNextDayShipping ? 1f : 0.25f), textScale, -1f, 0, 0, 0, 0); string nextDayShippingText = hasPrimeShipping || isPurchasingPrimeShipping ? $"Next Day (Free)" : $"Next Day (+{nextDayShippingFee}%)"; IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 373, 9, 9), this.nextDayShippingButton.bounds.X, this.nextDayShippingButton.bounds.Y, this.nextDayShippingButton.bounds.Width, this.nextDayShippingButton.bounds.Height, isNextDayShipping ? Color.Gray : Color.White, scale * 4f * nextDayShippingButton.scale, false); Utility.drawTextWithShadow(b, nextDayShippingText, Game1.dialogueFont, new Vector2(this.nextDayShippingButton.bounds.X + 12 * scale, this.nextDayShippingButton.bounds.Y + (LocalizedContentManager.CurrentLanguageLatin ? 16 : 12) * scale), Game1.textColor * (isNextDayShipping ? 0.25f : 1f), textScale, -1f, 0, 0, 0, 0); // Draw the subtotal //Utility.drawTextWithShadow(b, $"Subtotal:", Game1.dialogueFont, GetScaledVector(this.width - SpriteText.getWidthOfString($"Subtotal:{subTotal}g") - 50, this.height - 320), Color.LightGray, scale, 0.6f, numShadows: 0, shadowIntensity: 0); //Utility.drawTextWithShadow(b, $"{subTotal}g", Game1.dialogueFont, GetScaledVector(this.width - SpriteText.getWidthOfString($"{subTotal}g") - 75, this.height - 320), Color.LightGray, scale, 0.6f, numShadows: 0, shadowIntensity: 0); // Draw the shipping costs int shippingCosts = isNextDayShipping && !hasPrimeShipping && !isPurchasingPrimeShipping ? subTotal / nextDayShippingFee : 0; string shippingCostText = shippingCosts == 0 ? "FREE" : $"{shippingCosts}g"; Utility.drawTextWithShadow(b, $"Shipping:", Game1.dialogueFont, new Vector2(this.xPositionOnScreen + this.width / 2 + 20 * scale, (this.yPositionOnScreen + this.height - this.height / 3) - 20 * scale), Color.White, scale, 0.6f, numShadows: 0, shadowIntensity: 0); Utility.drawTextWithShadow(b, shippingCostText, Game1.dialogueFont, new Vector2(this.xPositionOnScreen + this.width - SpriteText.getWidthOfString(shippingCostText) * scale - (shippingCostText == "FREE" ? 75 * scale : 25), (this.yPositionOnScreen + this.height - this.height / 3) - 20 * scale), Color.White, scale, 0.6f, numShadows: 0, shadowIntensity: 0); // Draw the total int total = subTotal + shippingCosts; Utility.drawTextWithShadow(b, $"Total:", Game1.dialogueFont, new Vector2(this.xPositionOnScreen + 85 * scale, this.purchaseButton.bounds.Y + (LocalizedContentManager.CurrentLanguageLatin ? 16 : 12) * scale), Color.Gold, scale, 0.6f, numShadows: 0, shadowIntensity: 0); Utility.drawTextWithShadow(b, $"{total}g", Game1.dialogueFont, new Vector2(this.xPositionOnScreen + (85 * scale + SpriteText.getWidthOfString($"Total:") * scale), this.purchaseButton.bounds.Y + (LocalizedContentManager.CurrentLanguageLatin ? 16 : 12) * scale), Color.Gold, scale, 0.6f, numShadows: 0, shadowIntensity: 0); // Draw the purchase button canAffordOrder = total <= Game1.player.Money ? true : false; IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 373, 9, 9), this.purchaseButton.bounds.X, this.purchaseButton.bounds.Y, this.purchaseButton.bounds.Width, this.purchaseButton.bounds.Height, canAffordOrder ? Color.White : Color.Gray, scale * 4f * purchaseButton.scale, false); Utility.drawTextWithShadow(b, $"Purchase Order", Game1.dialogueFont, new Vector2(this.purchaseButton.bounds.X + 12 * scale, this.purchaseButton.bounds.Y + (LocalizedContentManager.CurrentLanguageLatin ? 16 : 12) * scale), Game1.textColor * (canAffordOrder ? 1f : 0.25f), textScale, -1f, 0, 0, 0, 0); // Draw the mouse this.drawMouse(b); return; } // Draw the custom store BG // this.width - (IClickableMenu.borderWidth * 2) - 12 to account for width shift, this.height - 128 due to drawDialogueBox method adding 128 to height b.Draw(JojaResources.GetJojaSiteBackground(), new Rectangle(this.xPositionOnScreen + IClickableMenu.borderWidth - 8, this.yPositionOnScreen + IClickableMenu.borderWidth + 56, this.width - (IClickableMenu.borderWidth * 2) + 16, this.height - 128), new Rectangle(0, 0, 150, 200), Color.White); IClickableMenu.drawTextureBox(b, sourceSheet, new Rectangle(13, 64, 3, 3), this.xPositionOnScreen + IClickableMenu.borderWidth - 8, this.yPositionOnScreen + IClickableMenu.borderWidth + 56, this.width - (IClickableMenu.borderWidth * 2) + 16, (int)(70 * scale), Color.White, 1f, drawShadow: false); // Draw the current unique amount of items in cart cartQuantity = drawCartQuantity(sourceSheet, new Rectangle(0, 41, 5, 7)); cartQuantity.draw(b); // Draw the usage instructions //IClickableMenu.drawTextureBox(b, sourceSheet, new Rectangle(144, 576, 76, 64), this.xPositionOnScreen + 100, this.yPositionOnScreen + 600, 76, 64, Color.White, scale, drawShadow: false); //SpriteText.drawString(b, "to order", this.xPositionOnScreen + 100, this.yPositionOnScreen + 600, 999999, -1, 999999, 1f, 0.88f, junimoText: false, -1, "", 4); //SpriteText.drawString(b, "to remove", (this.xPositionOnScreen + this.width) - SpriteText.getWidthOfString("Right Click to remove"), this.yPositionOnScreen + 600, 999999, -1, 999999, 1f, 0.88f, junimoText: false, -1, "", 4); // Draw the general clickables foreach (ClickableTextureComponent clickable in clickables) { clickable.draw(b); } // Draw the checkout button checkoutButton.draw(b, itemsInCart.Count > 0 ? Color.White : Color.Black, 0.99f); // Draw the scroll bar IClickableMenu.drawTextureBox(b, sourceSheet, new Rectangle(0, 74, 6, 6), scrollBarRunner.X, scrollBarRunner.Y, scrollBarRunner.Width, scrollBarRunner.Height, Color.White, 4f, drawShadow: false); scrollBar.draw(b); // Draw the sale button randomSaleButton.draw(b); if (randomSaleItem is Furniture) { (randomSaleItem as Furniture).drawInMenu(b, new Vector2(randomSaleButton.bounds.Center.X - (25 * scale) + (scale == 1f ? -7 : -13), randomSaleButton.bounds.Center.Y - (25 * scale) + (scale == 1f ? -8 : -19)), 0.75f, 1f, 0.9f, StackDrawType.Hide, Color.White, drawShadow: false); } else if (randomSaleItem is Wallpaper) { if ((randomSaleItem as Wallpaper).isFloor) { (randomSaleItem as Wallpaper).drawInMenu(b, new Vector2(randomSaleButton.bounds.Center.X - (25 * scale) + (scale == 1f ? -7 : -11), randomSaleButton.bounds.Center.Y - (25 * scale) + (scale == 1f ? -8 : -2)), 0.6f, 1f, 0.9f, StackDrawType.Hide, Color.White, drawShadow: false); } else { (randomSaleItem as Wallpaper).drawInMenu(b, new Vector2(randomSaleButton.bounds.Center.X - (25 * scale) + (scale == 1f ? -7 : -14), randomSaleButton.bounds.Center.Y - (25 * scale) + (scale == 1f ? -8 : -7)), 0.6f, 1f, 0.9f, StackDrawType.Hide, Color.White, drawShadow: false); } } else { randomSaleItem.drawInMenu(b, new Vector2(randomSaleButton.bounds.Center.X - (25 * scale) + (scale == 1f ? -2 : -8), randomSaleButton.bounds.Center.Y - (25 * scale) + (scale == 1f ? -2 : -9)), 0.6f, 1f, 0.9f, StackDrawType.Hide, Color.White, drawShadow: false); } //randomSaleItem.drawInMenu(b, new Vector2(randomSaleButton.bounds.Center.X - 25 * scale, randomSaleButton.bounds.Center.Y - 25 * scale), scale * 0.5f, 1f, 0.9f, StackDrawType.Hide, Color.White, drawShadow: false); // Draw the individual store buttons foreach (ClickableComponent button in forSaleButtons) { int buttonPosition = forSaleButtons.IndexOf(button) + (currentItemIndex * 2); if (buttonPosition >= forSale.Count) { continue; } // Draw the button grid IClickableMenu.drawTextureBox(b, sourceSheet, new Rectangle(0, 48, 15, 15), button.bounds.X, button.bounds.Y, button.bounds.Width, button.bounds.Height, Color.White, scale * 4f, drawShadow: false); // Get the quantity that is in the cart (if any) int currentlyInCart = 0; if (itemsInCart.ContainsKey(forSale[buttonPosition])) { currentlyInCart = itemsInCart[forSale[buttonPosition]][1]; } // Draw the item for sale float itemScale = scale == 1f ? 1f : 0.6f; Item itemForSale = forSale[buttonPosition] as Item; if (itemForSale is Furniture) { (itemForSale as Furniture).drawInMenu(b, new Vector2(button.bounds.X + (button.bounds.Width / 12 * itemScale) + (itemScale == 1f ? 0 : -5), button.bounds.Y + (button.bounds.Height / 8 * itemScale) + (itemScale == 1f ? 2 : -5)), itemScale, 1f, 0.9f, StackDrawType.Hide, Color.White * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.25f), drawShadow: false); } else if (itemForSale is Wallpaper) { (itemForSale as Wallpaper).drawInMenu(b, new Vector2(button.bounds.X + (button.bounds.Width / 12 * itemScale) + (itemScale == 1f ? 0 : -5), button.bounds.Y + (button.bounds.Height / 8 * itemScale) + (itemScale == 1f ? 2 : -5)), itemScale, 1f, 0.9f, StackDrawType.Hide, Color.White * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.25f), drawShadow: false); } else { itemForSale.drawInMenu(b, new Vector2(button.bounds.X + (button.bounds.Width / 12 * itemScale), button.bounds.Y + (button.bounds.Height / 8 * itemScale) + (itemScale == 1f ? 2 : -2)), itemScale, 1f, 0.9f, StackDrawType.Hide, Color.White * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.25f), drawShadow: false); } // Draw the quantity in the cart Utility.drawTextWithShadow(b, $"In Cart: {currentlyInCart}", Game1.dialogueFont, new Vector2(button.bounds.X + (button.bounds.Width / 4) + 15 * scale, button.bounds.Y + 10), Color.White * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.5f), scale == 1f ? 0.9f : 0.5f, 0.88f, numShadows: 0, shadowIntensity: 0); // Check if item is on sale, if so then add visual marker float coinScale = scale == 1f ? 3.75f : 2f; float textScale = scale == 1f ? 0.9f : 0.5f; if (itemForSale == randomSaleItem) { // Draw the (discounted) price string price = ((int)(itemPriceAndStock[itemForSale][0] - (itemPriceAndStock[itemForSale][0] * randomSalePercentageOff))).ToString(); Utility.drawTextWithShadow(b, "-" + (randomSalePercentageOff * 100) + "%", Game1.dialogueFont, new Vector2(button.bounds.X + (button.bounds.Width / 4) + 15 * scale, button.bounds.Y + button.bounds.Height - (SpriteText.getHeightOfString("-" + (randomSalePercentageOff * 100) + "%") * textScale) - (6 * scale)), Color.Cyan * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.5f), textScale, 0.6f, numShadows: 0, shadowIntensity: 0); Utility.drawTextWithShadow(b, price, Game1.dialogueFont, new Vector2(button.bounds.X + button.bounds.Width - (SpriteText.getWidthOfString(price) * textScale) - (9 * coinScale) - (6 * scale), button.bounds.Y + button.bounds.Height - (SpriteText.getHeightOfString(price) * textScale) - (6 * scale)), Color.Cyan * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.5f), textScale, 0.6f, numShadows: 0, shadowIntensity: 0); Utility.drawWithShadow(b, Game1.mouseCursors, new Vector2(button.bounds.X + button.bounds.Width - (9 * coinScale) - (10 * scale), button.bounds.Y + button.bounds.Height - (10 * coinScale) - (7 * scale)), new Rectangle(193, 373, 9, 10), Color.White * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.25f), 0f, Vector2.Zero, coinScale, flipped: false, 1f, -1, -1, 0f); // Draw sale marker Utility.drawWithShadow(b, sourceSheet, new Vector2(button.bounds.Right - (14 * scale * 3f) - (12 * scale), button.bounds.Y + (12 * scale)), new Rectangle(0, 80, 14, 7), Color.White, 0f, Vector2.Zero, scale * 3f, flipped: false, 1f, -1, -1, 0f); } else { // Draw the price string price = itemPriceAndStock[itemForSale][0].ToString(); Utility.drawTextWithShadow(b, price, Game1.dialogueFont, new Vector2(button.bounds.X + button.bounds.Width - (SpriteText.getWidthOfString(price) * textScale) - (9 * coinScale) - (6 * scale), button.bounds.Y + button.bounds.Height - (SpriteText.getHeightOfString(price) * textScale) - (6 * scale)), new Color(251, 249, 78) * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.5f), textScale, 0.6f, numShadows: 0, shadowIntensity: 0); Utility.drawWithShadow(b, Game1.mouseCursors, new Vector2(button.bounds.X + button.bounds.Width - (9 * coinScale) - (10 * scale), button.bounds.Y + button.bounds.Height - (10 * coinScale) - (7 * scale)), new Rectangle(193, 373, 9, 10), Color.White * (itemsInCart.Count < maxUniqueCartItems || currentlyInCart > 0 ? 1f : 0.25f), 0f, Vector2.Zero, coinScale, flipped: false, 1f, -1, -1, 0f); } } // Draw the tooltip if (!this.hoverText.Equals("")) { if (this.hoveredItem is StardewValley.Object && (bool)(this.hoveredItem as StardewValley.Object).isRecipe) { IClickableMenu.drawToolTip(b, " ", this.boldTitleText, this.hoveredItem as Item, false, -1, 0, -1, -1, new CraftingRecipe(this.hoveredItem.Name.Replace(" Recipe", "")), (this.hoverPrice > 0) ? this.hoverPrice : (-1)); } else { IClickableMenu.drawToolTip(b, this.hoverText, this.boldTitleText, this.hoveredItem as Item, false, -1, 0, -1, -1, null, (this.hoverPrice > 0) ? this.hoverPrice : (-1)); } } this.upperRightCloseButton.draw(b); this.drawMouse(b); }
private void DrawGridLayout() { var forSale = this.Shop.forSale; var itemPriceAndStock = this.Shop.itemPriceAndStock; int currency = this.Shop.currency; var animations = this.Helper.Reflection.GetField <List <TemporaryAnimatedSprite> >(this.Shop, "animations").GetValue(); var poof = this.Helper.Reflection.GetField <TemporaryAnimatedSprite>(this.Shop, "poof").GetValue(); var heldItem = this.Shop.heldItem; int currentItemIndex = this.Shop.currentItemIndex; var scrollBar = this.Shop.scrollBar; var scrollBarRunner = this.Helper.Reflection.GetField <Rectangle>(this.Shop, "scrollBarRunner").GetValue(); const int unitWidth = 160; const int unitHeight = 144; int unitsWide = (this.Shop.width - 32) / unitWidth; ISalable hover = null; Texture2D purchaseTexture = Game1.mouseCursors; Rectangle purchaseWindowBorder = new Rectangle(384, 373, 18, 18); Rectangle purchaseItemRect = new Rectangle(384, 396, 15, 15); int purchaseItemTextColor = -1; Color purchaseSelectedColor = Color.Wheat; if (this.Shop.storeContext == "QiGemShop") { purchaseTexture = Game1.mouseCursors2; purchaseWindowBorder = new Rectangle(0, 256, 18, 18); purchaseItemRect = new Rectangle(18, 256, 15, 15); purchaseItemTextColor = 4; purchaseSelectedColor = Color.Blue; } //IClickableMenu.drawTextureBox(Game1.spriteBatch, Game1.mouseCursors, new Rectangle(384, 373, 18, 18), shop.xPositionOnScreen + shop.width - shop.inventory.width - 32 - 24, shop.yPositionOnScreen + shop.height - 256 + 40, shop.inventory.width + 56, shop.height - 448 + 20, Color.White, 4f, true); //IClickableMenu.drawTextureBox(Game1.spriteBatch, Game1.mouseCursors, new Rectangle(384, 373, 18, 18), shop.xPositionOnScreen, shop.yPositionOnScreen, shop.width, shop.height - 256 + 32 + 4, Color.White, 4f, true); IClickableMenu.drawTextureBox(Game1.spriteBatch, purchaseTexture, purchaseWindowBorder, this.Shop.xPositionOnScreen, this.Shop.yPositionOnScreen, this.Shop.width, this.Shop.height - 256 + 32 + 4, Color.White, 4f); for (int i = currentItemIndex * unitsWide; i < forSale.Count && i < currentItemIndex * unitsWide + unitsWide * 3; ++i) { bool failedCanPurchaseCheck = this.Shop.canPurchaseCheck != null && !this.Shop.canPurchaseCheck(i); int ix = i % unitsWide; int iy = i / unitsWide; Rectangle rect = new Rectangle(this.Shop.xPositionOnScreen + 16 + ix * unitWidth, this.Shop.yPositionOnScreen + 16 + iy * unitHeight - currentItemIndex * unitHeight, unitWidth, unitHeight); IClickableMenu.drawTextureBox(Game1.spriteBatch, purchaseTexture, purchaseItemRect, rect.X, rect.Y, rect.Width, rect.Height, rect.Contains(Game1.getOldMouseX(), Game1.getOldMouseY()) ? purchaseSelectedColor : Color.White, 4f, false); ISalable item = forSale[i]; StackDrawType stackDrawType; if (this.Shop.storeContext == "QiGemShop") { stackDrawType = StackDrawType.HideButShowQuality; } else if (this.Shop.itemPriceAndStock[item][1] == int.MaxValue) { stackDrawType = StackDrawType.HideButShowQuality; } else { stackDrawType = StackDrawType.Draw_OneInclusive; if (this.Helper.Reflection.GetField <bool>(this.Shop, "_isStorageShop").GetValue()) { stackDrawType = StackDrawType.Draw; } } if (forSale[i].ShouldDrawIcon()) { item.drawInMenu(Game1.spriteBatch, new Vector2(rect.X + 48, rect.Y + 16), 1f, 1, 1, stackDrawType, Color.White, true); } int price = itemPriceAndStock[forSale[i]][0]; string priceStr = price.ToString(); if (price > 0) { SpriteText.drawString(Game1.spriteBatch, priceStr, rect.Right - SpriteText.getWidthOfString(priceStr) - 16, rect.Y + 80, alpha: ShopMenu.getPlayerCurrencyAmount(Game1.player, currency) >= price && !failedCanPurchaseCheck ? 1f : 0.5f, color: purchaseItemTextColor); //Utility.drawWithShadow(Game1.spriteBatch, Game1.mouseCursors, new Vector2(rect.Right - 16, rect.Y + 80), new Rectangle(193 + currency * 9, 373, 9, 10), Color.White, 0, Vector2.Zero, 1, layerDepth: 1); } else if (itemPriceAndStock[forSale[i]].Length > 2) { int requiredItemCount = 5; int requiredItem = itemPriceAndStock[forSale[i]][2]; if (itemPriceAndStock[forSale[i]].Length > 3) { requiredItemCount = itemPriceAndStock[forSale[i]][3]; } bool hasEnoughToTrade = Game1.player.hasItemInInventory(requiredItem, requiredItemCount); if (this.Shop.canPurchaseCheck != null && !this.Shop.canPurchaseCheck(i)) { hasEnoughToTrade = false; } float textWidth = SpriteText.getWidthOfString("x" + requiredItemCount); Utility.drawWithShadow(Game1.spriteBatch, Game1.objectSpriteSheet, new Vector2(rect.Right - 64 - textWidth, rect.Y + 80 - 4), Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, requiredItem, 16, 16), Color.White * (hasEnoughToTrade ? 1f : 0.25f), 0f, Vector2.Zero, 3, flipped: false, -1f, -1, -1, hasEnoughToTrade ? 0.35f : 0f); SpriteText.drawString(Game1.spriteBatch, "x" + requiredItemCount, rect.Right - (int)textWidth - 16, rect.Y + 80, 999999, -1, 999999, hasEnoughToTrade ? 1f : 0.5f, 0.88f, junimoText: false, -1, "", purchaseItemTextColor); } if (rect.Contains(Game1.getOldMouseX(), Game1.getOldMouseY())) { hover = forSale[i]; } } if (forSale.Count == 0) { SpriteText.drawString(Game1.spriteBatch, Game1.content.LoadString("Strings\\StringsFromCSFiles:ShopMenu.cs.11583"), this.Shop.xPositionOnScreen + this.Shop.width / 2 - SpriteText.getWidthOfString(Game1.content.LoadString("Strings\\StringsFromCSFiles:ShopMenu.cs.11583")) / 2, this.Shop.yPositionOnScreen + this.Shop.height / 2 - 128); } //shop.inventory.draw(Game1.spriteBatch); // Moved currency here so above doesn't draw over it //if (currency == 0) // Game1.dayTimeMoneyBox.drawMoneyBox(Game1.spriteBatch, shop.xPositionOnScreen - 36, shop.yPositionOnScreen + shop.height - shop.inventory.height + 48); for (int index = animations.Count - 1; index >= 0; --index) { if (animations[index].update(Game1.currentGameTime)) { animations.RemoveAt(index); } else { animations[index].draw(Game1.spriteBatch, true); } } poof?.draw(Game1.spriteBatch); // arrows already drawn if (forSale.Count > 18) { IClickableMenu.drawTextureBox(Game1.spriteBatch, Game1.mouseCursors, new Rectangle(403, 383, 6, 6), scrollBarRunner.X, scrollBarRunner.Y, scrollBarRunner.Width, scrollBarRunner.Height, Color.White, 4f); scrollBar.draw(Game1.spriteBatch); } if (hover != null) { // get hover price & stock if (itemPriceAndStock == null || !itemPriceAndStock.TryGetValue(hover, out int[] hoverPriceAndStock))