private void ItemSheet(Rect _rectOut, ESItem[] _aItems, GameFont _fontSize) { // Shape item sheet float floViewWidth = _rectOut.width - 16f; // Scrollbar has 16f hard number float floColumnTexWidth = floViewWidth * .1f; float floColumnNameWidth = floViewWidth * .6f; float floColumnQuantityWidth = floViewWidth * .12f; float floColumnCostWidth = floViewWidth * .18f; Text.Font = _fontSize; float TotalHeight = 0f; // Create strings for headers string strItemNameHeader = "Item"; string strItemAmountHeader = "#"; string strItemPriceHeader = "Cost"; // Calculate header heights float floHeaderHeight = Text.CalcHeight(strItemNameHeader, floColumnNameWidth); // Shape the headers Rect rectItemNameHeader = new Rect(_rectOut.x + floColumnTexWidth, _rectOut.y, floColumnNameWidth, floHeaderHeight); Rect rectItemAmountHeader = new Rect(_rectOut.x + floColumnTexWidth + floColumnNameWidth, _rectOut.y, floColumnQuantityWidth, floHeaderHeight); Rect rectItemPriceHeader = new Rect(_rectOut.x + floColumnTexWidth + floColumnNameWidth + floColumnQuantityWidth, _rectOut.y, floColumnCostWidth, floHeaderHeight); // Draw the headers GUI.Label(KrozzyUtilities.RectAddition(rectItemNameHeader, rectCard), strItemNameHeader, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.White, FontStyle.Bold)); GUI.Label(KrozzyUtilities.RectAddition(rectItemAmountHeader, rectCard), strItemAmountHeader, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.White, FontStyle.Bold)); GUI.Label(KrozzyUtilities.RectAddition(rectItemPriceHeader, rectCard), strItemPriceHeader, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.White, FontStyle.Bold)); // Draw the buttons if (Widgets.ButtonInvisible(KrozzyUtilities.RectAddition(rectItemNameHeader, rectCard))) { ES.SortItemsTool(ProEquipmentShop.ESSortList.Items, ProEquipmentShop.ESSortType.DefName); } if (Widgets.ButtonInvisible(KrozzyUtilities.RectAddition(rectItemAmountHeader, rectCard))) { ES.SortItemsTool(ProEquipmentShop.ESSortList.Items, ProEquipmentShop.ESSortType.ThingAmount); } if (Widgets.ButtonInvisible(KrozzyUtilities.RectAddition(rectItemPriceHeader, rectCard))) { ES.SortItemsTool(ProEquipmentShop.ESSortList.Items, ProEquipmentShop.ESSortType.Price); } // Reshape the _rectOut _rectOut = new Rect(_rectOut.x, _rectOut.y + floHeaderHeight, _rectOut.width, _rectOut.height - floHeaderHeight); // Calculate total item list height foreach (ESItem item in _aItems) { TotalHeight += Text.CalcHeight(item.strNameLabel, floColumnNameWidth); } // Calculate rectView based on if the scroll bar will need to be shown Rect rectView = new Rect(); if (TotalHeight > _rectOut.height) { rectView = new Rect(_rectOut.x, _rectOut.y, floViewWidth, TotalHeight); } else { rectView = new Rect(_rectOut.x, _rectOut.y, _rectOut.width, TotalHeight); } // Calculate rects for GUI group and tooltip Rect rectGroup = KrozzyUtilities.RectAddition(rectView, rectCard); Rect rectScrollingTooltip = KrozzyUtilities.RectAddition(_rectOut, rectCard); // Begin scroll view and group Widgets.BeginScrollView(KrozzyUtilities.RectAddition(_rectOut, rectCard), ref v2FoodsScrollPosition1, KrozzyUtilities.RectAddition(rectView, rectCard)); GUI.BeginGroup(rectGroup); // Create list of items from array float floYPos = 0f; for (int i = 0; i < _aItems.Length; i++) { string strNameLabel = _aItems[i].strNameLabel; string strQauntityLabel = _aItems[i].thingAmount.ToString(); string strCostLabel = String.Format("{0:0}", ES.GetPrice(_aItems[i])); string strDescToolTip = _aItems[i].thingDef.description; // Shape idividual item Rect rectWholeItem = new Rect(0f, floYPos, rectView.width, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectMiniTex = new Rect(0f, floYPos, floColumnTexWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectNameLabel = new Rect(floColumnTexWidth, floYPos, floColumnNameWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectQauntityLabel = new Rect(floColumnTexWidth + floColumnNameWidth, floYPos, floColumnQuantityWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectCostLabel = new Rect(floColumnTexWidth + floColumnNameWidth + floColumnQuantityWidth, floYPos, floColumnCostWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); // update y position for next label floYPos += Text.CalcHeight(strNameLabel, floColumnNameWidth); // Draw label based upon if it's currently selected if (i == intCurSelectedToEquip) { GUI.Label(rectNameLabel, strNameLabel, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.Yellow)); GUI.Label(rectQauntityLabel, strQauntityLabel, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.Yellow)); GUI.Label(rectCostLabel, strCostLabel, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.Yellow)); _aItems[i].DrawIcon(rectMiniTex); // Prime variable for equip button esItemCurSelectedToEquip = _aItems[i]; } else { Widgets.Label(rectNameLabel, strNameLabel); Widgets.Label(rectQauntityLabel, strQauntityLabel); Widgets.Label(rectCostLabel, strCostLabel); _aItems[i].DrawIcon(rectMiniTex); } // Highlight is mouse is hovering over if (Mouse.IsOver(rectWholeItem)) { KrozzyUtilities.Tooltip(KrozzyUtilities.RectAddition(rectScrollingTooltip, Find.WindowStack.currentlyDrawnWindow.windowRect), strDescToolTip); Widgets.DrawHighlight(rectWholeItem); } // Draw invisible button for item selecting if (Widgets.ButtonInvisible(rectWholeItem, true)) { intCurSelectedToEquip = i; } } // End group and scroll view GUI.EndGroup(); Widgets.EndScrollView(); Text.Font = GameFont.Small; // Ensure font size is back to default }
private void DoStartingItems() { // Calculate variables float floMenuHeight = rectCard.height * .8f; ESItem[] esiStartingItems = ESStartingItems.aStartingItems; // Shape the menu section Rect rectMenuSection = new Rect(rectCard.width * .625f, rectCard.height * .1f, rectCard.width * .3f, floMenuHeight); Rect rectOut = KrozzyUtilities.RectAddition(rectMenuSection, rectCard); // Draw the menu section GUI.DrawTexture(rectOut, ProTBin.texVellum, ScaleMode.ScaleAndCrop); GUI.color = cintBorder.ToColor; Widgets.DrawBox(rectOut, 1); GUI.color = Color.white; // set GUI color back to default // Shape item sheet float floViewWidth = rectMenuSection.width - 16f; // Scrollbar has 16f hard number float floColumnTexWidth = floViewWidth * .1f; float floColumnNameWidth = floViewWidth * .6f; float floColumnQuantityWidth = floViewWidth * .12f; float floColumnCostWidth = floViewWidth * .18f; Text.Font = GameFont.Small; // Make sure the font is default for size calculation float TotalHeight = 0f; // Create strings for headers string strItemNameHeader = "Item"; string strItemAmountHeader = "#"; string strItemPriceHeader = "Cost"; // Calculate header heights float floHeaderHeight = Text.CalcHeight(strItemNameHeader, floColumnNameWidth); // Shape the headers Rect rectItemNameHeader = new Rect(rectOut.x + floColumnTexWidth, rectOut.y, floColumnNameWidth, floHeaderHeight); Rect rectItemAmountHeader = new Rect(rectOut.x + floColumnTexWidth + floColumnNameWidth, rectOut.y, floColumnQuantityWidth, floHeaderHeight); Rect rectItemPriceHeader = new Rect(rectOut.x + floColumnTexWidth + floColumnNameWidth + floColumnQuantityWidth, rectOut.y, floColumnCostWidth, floHeaderHeight); // Draw the headers GUI.Label(rectItemNameHeader, strItemNameHeader, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.White, FontStyle.Bold)); GUI.Label(rectItemAmountHeader, strItemAmountHeader, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.White, FontStyle.Bold)); GUI.Label(rectItemPriceHeader, strItemPriceHeader, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.White, FontStyle.Bold)); // Draw the buttons if (Widgets.ButtonInvisible(rectItemNameHeader)) { ES.SortItemsTool(ProEquipmentShop.ESSortList.StartingItems, ProEquipmentShop.ESSortType.DefName); } if (Widgets.ButtonInvisible(rectItemAmountHeader)) { ES.SortItemsTool(ProEquipmentShop.ESSortList.StartingItems, ProEquipmentShop.ESSortType.ThingAmount); } if (Widgets.ButtonInvisible(rectItemPriceHeader)) { ES.SortItemsTool(ProEquipmentShop.ESSortList.StartingItems, ProEquipmentShop.ESSortType.Price); } // Reshape the rectOut rectOut = new Rect(rectOut.x, rectOut.y + floHeaderHeight, rectOut.width, rectOut.height - floHeaderHeight); // Calculate total height of items foreach (ESItem item in esiStartingItems) { TotalHeight += Text.CalcHeight(item.strNameLabel, floColumnNameWidth); } // If the total height of items in more than the menu section height, make scroll view fit inside the menu // Else make the scroll view wide enough so the highlighted item is not clipped Rect rectView = new Rect(); if (TotalHeight > rectOut.height) { rectView = new Rect(rectOut.x, rectOut.y, floViewWidth, TotalHeight); } else { rectView = new Rect(rectOut.x, rectOut.y, rectOut.width, TotalHeight); } // Shape the group and shape the tooltip so that it does not scroll inside the scroll view Rect rectGroup = KrozzyUtilities.RectAddition(rectView, rectCard); Rect rectScrollingTooltip = KrozzyUtilities.RectAddition(rectOut, rectCard); // Begin scroll view and group Widgets.BeginScrollView(rectOut, ref v2FoodsScrollPosition2, KrozzyUtilities.RectAddition(rectView, rectCard)); GUI.BeginGroup(rectGroup); // Create list of items from array float floYPos = 0f; for (int i = 0; i < esiStartingItems.Length; i++) { // Build strings string strNameLabel = esiStartingItems[i].strNameLabel; string strQauntityLabel = esiStartingItems[i].thingAmountTotal.ToString(); string strCostLabel = String.Format("{0:0}", esiStartingItems[i].subtotal); string strDescToolTip = string.Concat(esiStartingItems[i].thingDef.description, " price: ", esiStartingItems[i].price.ToString(), ", itemAmount: ", esiStartingItems[i].itemAmount.ToString()); // Shape idividual item Rect rectWholeItem = new Rect(0f, floYPos, rectView.width, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectMiniTex = new Rect(0f, floYPos, floColumnTexWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectNameLabel = new Rect(floColumnTexWidth, floYPos, floColumnNameWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectQauntityLabel = new Rect(floColumnTexWidth + floColumnNameWidth, floYPos, floColumnQuantityWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); Rect rectCostLabel = new Rect(floColumnTexWidth + floColumnNameWidth + floColumnQuantityWidth, floYPos, floColumnCostWidth, Text.CalcHeight(strNameLabel, floColumnNameWidth)); // update y position for next label floYPos += Text.CalcHeight(strNameLabel, floColumnNameWidth); // Draw label based upon if it's currently selected if (i == intCurSelectedToUnequip) { // Using custom font if selected esiStartingItems[i].DrawIcon(rectMiniTex); GUI.Label(rectNameLabel, strNameLabel, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.Yellow)); GUI.Label(rectQauntityLabel, strQauntityLabel, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.Yellow)); GUI.Label(rectCostLabel, strCostLabel, KrozzyUtilities.BuildStyle(Fonts.Arial_small, Colors.Yellow)); // Prime variable for unequip button esItemCurSelectedToUnequip = esiStartingItems[i]; //intCurSelectedAmountToUnequip = esiStartingItems[i].amount; //intCurSelectedPriceToUnequip = ES.GetPrice(esiStartingItems[i]); } else { // Using default font if not selected esiStartingItems[i].DrawIcon(rectMiniTex); Widgets.Label(rectNameLabel, strNameLabel); Widgets.Label(rectQauntityLabel, strQauntityLabel); Widgets.Label(rectCostLabel, strCostLabel); } // Highlight is mouse is hovering over if (Mouse.IsOver(rectWholeItem)) { KrozzyUtilities.Tooltip(KrozzyUtilities.RectAddition(rectScrollingTooltip, Find.WindowStack.currentlyDrawnWindow.windowRect), strDescToolTip); Widgets.DrawHighlight(rectWholeItem); } // Draw invisible button for item selecting if (Widgets.ButtonInvisible(rectWholeItem, true)) { intCurSelectedToUnequip = i; } } // End group and scroll view GUI.EndGroup(); Widgets.EndScrollView(); Text.Font = GameFont.Small; // Ensure font size is back to default }
private void DoTabs() { // Calculate variables float floMenuHeight = rectCard.height * .8f; float floYAdjust = floMenuHeight * .1f; // Do unfocused tabs for (int x = 5; x > -1; x--) { if (aboolCurTab[x] == false) { // Shape the tab Rect rectTabUnfocused = new Rect(rectCard.width * .025f + 1f, (rectCard.height * .1f) + (floMenuHeight * .1f) + (floYAdjust * (float)x), rectCard.width * .05f, rectCard.width * .075f); // Draw the tab Widgets.DrawTextureFitted(KrozzyUtilities.RectAddition(rectTabUnfocused, rectCard), atexTabs[x], 1f); // Shape the tab button Rect rectTabUnfocusedButton = new Rect(rectTabUnfocused.x, rectTabUnfocused.y + (rectTabUnfocused.height * .34f), rectTabUnfocused.width, rectTabUnfocused.height - (rectTabUnfocused.height * .34f)); // Draw the tab button if (Widgets.ButtonInvisible(KrozzyUtilities.RectAddition(rectTabUnfocusedButton, rectCard), true)) { for (int i = 0; i < 6; i++) { aboolCurTab[i] = false; } aboolCurTab[x] = true; } // Do tooltip if (Mouse.IsOver(KrozzyUtilities.RectAddition(rectTabUnfocusedButton, rectCard))) { KrozzyUtilities.Tooltip(Find.WindowStack.currentlyDrawnWindow.windowRect, astrTabTooltip[x]); } } } // Shape the menu section Rect rectMenuSection = new Rect(rectCard.width * .075f, rectCard.height * .1f, rectCard.width * .3f, floMenuHeight); // Draw the menu section GUI.DrawTexture(KrozzyUtilities.RectAddition(rectMenuSection, rectCard), ProTBin.texVellum, ScaleMode.ScaleAndCrop); GUI.color = cintBorder.ToColor; Widgets.DrawBox(KrozzyUtilities.RectAddition(rectMenuSection, rectCard), 1); GUI.color = Color.white; // Do focused tab for (int x = 0; x < 6; x++) { if (aboolCurTab[x] == true) { // Shape the tab Rect rectTabFocused = new Rect(rectCard.width * .025f + 1f, (rectCard.height * .1f) + (floMenuHeight * .1f) + (floYAdjust * (float)x), rectCard.width * .05f, rectCard.width * .075f); // Draw the tab Widgets.DrawTextureFitted(KrozzyUtilities.RectAddition(rectTabFocused, rectCard), atexTabs[x], 1f); // Shape the tab button Rect rectTabfocusedButton = new Rect(rectTabFocused.x, rectTabFocused.y + (rectTabFocused.height * .34f), rectTabFocused.width, rectTabFocused.height - (rectTabFocused.height * .34f)); // Do tooltip if (Mouse.IsOver(KrozzyUtilities.RectAddition(rectTabfocusedButton, rectCard))) { KrozzyUtilities.Tooltip(Find.WindowStack.currentlyDrawnWindow.windowRect, astrTabTooltip[x]); } // Do the sheet switch (astrTabTooltip[x]) { case "Foods": ItemSheet(rectMenuSection, ES.Foods.aFoods, GameFont.Small); break; case "Apparel": ItemSheet(rectMenuSection, ES.Apparel.aApparel, GameFont.Small); break; case "Weapons": ItemSheet(rectMenuSection, ES.Weapons.aWeapons, GameFont.Small); break; case "Drugs": ItemSheet(rectMenuSection, ES.Drugs.aDrugs, GameFont.Small); break; case "Resources": ItemSheet(rectMenuSection, ES.Resources.aResources, GameFont.Small); break; case "Items": ItemSheet(rectMenuSection, ES.Items.aItems, GameFont.Small); break; } } } }