public static void RenderEquipmentView(Point mousePos) { Item item = currentlyViewedItem; string name = item.Name; string pt2 = ""; Color textColor = new Color(Color.AntiqueWhite, 0.99F), bgColor = new Color(color, 0.99F); int viewStartX = width; // split the name into two lines if necessary Tuple <string, string> stringParts = Window.SplitNameIfGreaterThanLength(name, pt2, 18); name = stringParts.Item1; pt2 = stringParts.Item2; if (item.Identified) { textColor = item.ReturnRarityColor(); } // print the name at top GUI.Console.Print(viewStartX + 1, 1, name, textColor); GUI.Console.Print(viewStartX + 1, 2, pt2, textColor); //// print the splash art //bool thisItemHasSplashArt = item.splash != null; //if (thisItemHasSplashArt) // for (int i = 0; i < 18; i++) // for (int j = 0; j < 10; j++) // Program.mapConsole.Set(i, j + 3, item.splash[i, j].color, Swatch.SecondaryDarker, item.splash[i, j].character); textColor = new Color(100, 116, 136, 0.99F); //print the item description Program.Window.Print(GUI.Console, viewStartX + 1, 13, item.Description, 18, textColor); // print the weight, volume, and quality string plural = "."; if (item.Weight > 1) { plural = "s."; } textColor = Color.LightGray; GUI.Console.Print(viewStartX + 1, 21, "Weight: " + Math.Round(item.Weight, 2) + " lb" + plural, textColor); GUI.Console.Print(viewStartX + 1, 23, "Size: " + Math.Round(Convert.FromCubicFeetToCubicInches(item.Volume), 2), textColor); GUI.Console.Print(viewStartX + 7, 24, "cubic inches", textColor); int x = viewStartX + 10 - "[unequip]".Length / 2; bool highlightingAction = false; textColor = Color.Orange; Color highlightingColor = Color.Green; string action = "[unequip]"; if (mousePos.Y == 27 && mousePos.X >= x && mousePos.X < x + action.Length) { highlightingAction = true; } if (highlightingAction) { GUI.Console.Print(x, 27, action, highlightingColor, lighterColor); } else { GUI.Console.Print(x, 27, action, textColor, lighterColor); } }
} // input handling public static bool RenderInventory() // display handling { int heightOfItems = inventoryItems.Count; int itemPortHeight = Program.Console.Height - 8 - (displayingEquipment ? equipmentStartY : 3); itemsPerPage = itemPortHeight / padding; Point mousePos = new Point(SadConsole.Global.MouseState.ScreenPosition.X / SadConsole.Global.FontDefault.Size.X, SadConsole.Global.MouseState.ScreenPosition.Y / SadConsole.Global.FontDefault.Size.Y); float bgAlpha = 0.99F, fgAlpha = 0.99F; Color textColor = new Color(Color.White, fgAlpha); Color highlightedColor = new Color(Color.Green, bgAlpha); Color bgColor = new Color(darkerColor, bgAlpha); // FUNCTIONS void AddEquipment() { if (Program.Player.Body.MainHand != null) { equipment.Add(Program.Player.Body.MainHand); } if (Program.Player.Body.OffHand != null) { equipment.Add(Program.Player.Body.OffHand); } if (Program.Player.Body.Helmet != null) { equipment.Add(Program.Player.Body.Helmet); } if (Program.Player.Body.ChestPiece != null) { equipment.Add(Program.Player.Body.ChestPiece); } if (Program.Player.Body.Shirt != null) { equipment.Add(Program.Player.Body.Shirt); } if (Program.Player.Body.Gauntlets != null) { equipment.Add(Program.Player.Body.Gauntlets); } if (Program.Player.Body.Leggings != null) { equipment.Add(Program.Player.Body.Leggings); } if (Program.Player.Body.Boots != null) { equipment.Add(Program.Player.Body.Boots); } } string AddEquipSlotToName(string name, int index) { if (Program.Player.Body.MainHand != null && name.CompareTo(Program.Player.Body.MainHand.Name) == 0) { name = $"main hand: {name}"; } else if (Program.Player.Body.OffHand != null && name.CompareTo(Program.Player.Body.OffHand.Name) == 0) { name = $"off hand: {name}"; } else if (Program.Player.Body.Helmet != null && name.CompareTo(Program.Player.Body.Helmet.Name) == 0) { name = $"head: {name}"; } else if (Program.Player.Body.ChestPiece != null && name.CompareTo(Program.Player.Body.ChestPiece.Name) == 0) { name = $"chest: {name}"; } else if (Program.Player.Body.Shirt != null && name.CompareTo(Program.Player.Body.Shirt.Name) == 0) { name = $"shirt: {name}"; } else if (Program.Player.Body.Gauntlets != null && name.CompareTo(Program.Player.Body.Gauntlets.Name) == 0) { name = $"hands: {name}"; } else if (Program.Player.Body.Leggings != null && name.CompareTo(Program.Player.Body.Leggings.Name) == 0) { name = $"legs: {name}"; } else if (Program.Player.Body.Boots != null && name.CompareTo(Program.Player.Body.Boots.Name) == 0) { name = $"feet: {name}"; } return(name); } void ConvertInventoryForDisplay() { // items are stored in the inventory on an individual basis. // they are displayed in chunks that have a counter inventoryCount = new Dictionary <string, int>(); inventoryItems = new List <Item>(); bool InventoryItemsContains(Item item) { foreach (Item i in inventoryItems) { if (item.Name == i.Name) { return(true); } } return(false); } Program.Player.Inventory.Sort(); foreach (Item item in Program.Player.Inventory) { if (!InventoryItemsContains(item)) { inventoryCount[item.Name] = 1; inventoryItems.Add(item); } else { inventoryCount[item.Name] += 1; } } } void DetermineInventoryPages() { if (itemPortHeight % padding != 0) { itemsPerPage += 1; } inventoryPages = heightOfItems / itemsPerPage; if (heightOfItems % itemsPerPage != 0) { inventoryPages += 1; } if (invCurrentPage > inventoryPages - 1 & heightOfItems > 2) { invCurrentPage = inventoryPages - 1; } } void DetermineEquipmentPages() { equipmentPages = 1; equipmentPages = equipment.Count / equipmentPerPage; if (equipment.Count % equipmentPerPage != 0) { equipmentPages += 1; } if (equipCurrentPage > equipmentPages - 1 & equipment.Count > 2) { equipCurrentPage = equipmentPages - 1; } } void PrintHeader() { // fill the background for (int i = 0; i < width; i++) { for (int j = 0; j < Program.Console.Height; j++) { GUI.Console.SetGlyph(i, j, ' ', bgColor, bgColor); } } // print the header GUI.Console.Print(width / 2 - "INVENTORY".Length / 2, 1, "INVENTORY", textColor); // print the right page turning button GUI.Console.Print(width - 2, 1, " ", textColor, bgColor); if (mousePos.Equals(new Point((width - 2), 1))) { bgColor = highlightedColor * 0.95F; } if (inventoryPages > 1 && invCurrentPage < inventoryPages - 1) { GUI.Console.Print(width - 2, 1, ">", textColor, bgColor); } bgColor = new Color(darkerColor, bgAlpha); // print the left page turning button GUI.Console.Print(1, 1, " ", textColor, bgColor); if (mousePos.Equals(new Point(1, 1))) { bgColor = highlightedColor * 0.95F; } if (inventoryPages > 1 && invCurrentPage > 0) { GUI.Console.Print(1, 1, "<", textColor, bgColor); } bgColor = new Color(color, bgAlpha); } bool PrintInventory() { ConvertInventoryForDisplay(); DetermineInventoryPages(); bool highlighting = false; bool highlighted = false; for (int i = 0, index = 0 + invCurrentPage * itemsPerPage; i < itemPortHeight; i += padding, index++) { string name = ""; bool indexGreaterThanInventory = index >= inventoryItems.Count; textColor = new Color(Color.AntiqueWhite, fgAlpha); // this is to clear the line GUI.Console.Print(1, 4 + i, " ", new Color(darkerColor, bgAlpha), new Color(darkerColor, bgAlpha)); GUI.Console.Print(1, 4 + i + 1, " ", new Color(darkerColor, bgAlpha), new Color(darkerColor, bgAlpha)); if (inventoryCount.Any() && !indexGreaterThanInventory) { Item item = inventoryItems[index]; name = item.Name; string invCounter = "x" + inventoryCount[item.Name]; string pt2 = ""; Tuple <string, string> nameParts = Window.SplitNameIfGreaterThanLength(name, pt2, width - 3 - invCounter.Length); name = nameParts.Item1; if (nameParts.Item2 != "") { pt2 = nameParts.Item2; } // check if the mouse is on the item that is currently being drawn if (mousePos.Y >= 3 && mousePos.X >= 1 && mousePos.X <= (width - 2)) { if (mousePos.Y - 4 == i || mousePos.Y - 1 - 4 == i) { highlighted = true; } } if (item.Identified) { textColor = item.ReturnRarityColor(); } if (index % 2 == 0) { bgColor = new Color(color, bgAlpha); } else { bgColor = new Color(lighterColor, bgAlpha); } if (item == currentlyViewedItem) { bgColor = highlightedColor * bgAlpha; } string spaces = ""; for (int c = 0; c <= (width - 2) - (1 + name.Length) - invCounter.Length; c++) { spaces += ' '; } if (highlighted) { // print the name's first line GUI.Console.Print(1, 4 + i, name + spaces, highlightedColor, bgColor); // print the count GUI.Console.Print(width - 1 - invCounter.Length, 4 + i, invCounter, textColor, bgColor); // print / clear the name's second line GUI.Console.Print(1, 4 + i + 1, " ", textColor, bgColor); if (pt2 != "") { GUI.Console.Print(1, 4 + i + 1, pt2, highlightedColor, bgColor); } highlighting = true; } else { // print the name's first line GUI.Console.Print(1, 4 + i, name + spaces, textColor, bgColor); // print the count GUI.Console.Print(width - 1 - invCounter.Length, 4 + i, invCounter, textColor, bgColor); // print / clear the name's second line GUI.Console.Print(1, 4 + i + 1, " ", textColor, bgColor); if (pt2 != "") { GUI.Console.Print(1, 4 + i + 1, pt2, textColor, bgColor); } } } highlighted = false; } return(highlighting); } bool PrintEquipment() { string equipmentTitle = " EQUIPMENT "; if (displayingEquipment) { equipmentTitle = (char)31 + equipmentTitle + (char)31; } else { equipmentTitle = (char)30 + equipmentTitle + (char)30; } GUI.Console.Print(width / 2 - " EQUIPMENT ".Length / 2, equipmentStartY - 2, equipmentTitle, textColor); if (!displayingEquipment) { return(false); } DetermineEquipmentPages(); bgColor = new Color(darkerColor, bgAlpha); // print the right page turning button GUI.Console.Print(width - 2, equipmentStartY - 2, " ", textColor, bgColor); if (mousePos.Equals(new Point(width - 2, equipmentStartY - 2))) { bgColor = highlightedColor * 0.95F; } if (equipmentPages > 1 && equipCurrentPage < equipmentPages - 1) { GUI.Console.Print(width - 2, equipmentStartY - 2, ">", textColor, bgColor); } bgColor = new Color(darkerColor, bgAlpha); // print the left page turning button GUI.Console.Print(1, equipmentStartY - 2, " ", textColor, bgColor); if (mousePos.Equals(new Point(1, equipmentStartY - 2))) { bgColor = highlightedColor * 0.95F; } if (equipmentPages > 1 && equipCurrentPage > 0) { GUI.Console.Print(1, equipmentStartY - 2, "<", textColor, bgColor); } bgColor = new Color(color, bgAlpha); bool highlighting = false; bool highlighted = false; for (int i = 0, index = 0 + equipCurrentPage * equipmentPerPage; i < equipmentLen; i += padding, index++) { string name = ""; bool indexGreaterThanPlayersItems = index >= equipment.Count; textColor = new Color(Color.AntiqueWhite, bgAlpha); // this is to clear the line GUI.Console.Print(1, equipmentStartY + i, " ", new Color(darkerColor, bgAlpha), new Color(darkerColor, bgAlpha)); GUI.Console.Print(1, equipmentStartY + i + 1, " ", new Color(darkerColor, bgAlpha), new Color(darkerColor, bgAlpha)); if (equipment.Any() && !indexGreaterThanPlayersItems) { Item item = equipment[index]; name = AddEquipSlotToName(item.Name, index); string pt2 = ""; Tuple <string, string> nameParts = Window.SplitNameIfGreaterThanLength(name, pt2, StatusPanel.Width - 2); name = nameParts.Item1; if (name[name.Length - 1] == ' ') { name = name.Substring(0, name.Length - 1); } if (nameParts.Item2 != "") { pt2 = nameParts.Item2; } // check if the mouse is on the item that is currently being drawn if (mousePos.X >= 1 && mousePos.X <= (width - 1)) { if (mousePos.Y - equipmentStartY == i || mousePos.Y - 1 - equipmentStartY == i) { highlighted = true; } } if (item.Identified) { textColor = new Color(item.ReturnRarityColor(), bgAlpha); } bgColor = index % 2 == 0 ? new Color(color, bgAlpha) : new Color(lighterColor, bgAlpha); if (item == currentlyViewedItem) { bgColor = new Color(highlightedColor * 0.95F, bgAlpha); } string spaces = ""; for (int c = 0; c < (StatusPanel.Width - 2) - name.Length; c++) { spaces += ' '; } if (highlighted) { // print the name's first line GUI.Console.Print(1, equipmentStartY + i, name + spaces, highlightedColor, bgColor); // print / clear the name's second line GUI.Console.Print(1, equipmentStartY + i + 1, " ", bgColor, bgColor); if (pt2 != "") { GUI.Console.Print(1, equipmentStartY + i + 1, pt2, highlightedColor, bgColor); } highlighting = true; } else { // print the name's first line GUI.Console.Print(1, equipmentStartY + i, name + spaces, textColor, bgColor); // print / clear the name's second line GUI.Console.Print(1, equipmentStartY + i + 1, " ", textColor, bgColor); if (pt2 != "") { GUI.Console.Print(1, equipmentStartY + i + 1, pt2, textColor, bgColor); } } } highlighted = false; } return(highlighting); } // START equipment = new List <Item>(); AddEquipment(); PrintHeader(); // print the gold int goldX = width - 1 - $"gold: {Program.Player.Gold}".Length; GUI.Console.Print(goldX, Program.Console.Height - 2, $"gold: {Program.Player.Gold}", textColor); return(PrintInventory() | PrintEquipment()); }
public static void RenderItemView() { if (currentlyViewedItem == null) { return; } // initialize variables Item item = currentlyViewedItem; string name = item.Name; float fgAlpha = 0.99F; Color color = new Color(Color.AntiqueWhite, fgAlpha); string pt2 = ""; // split the name into two lines if necessary Tuple <string, string> stringParts = Window.SplitNameIfGreaterThanLength(name, pt2, 18); name = stringParts.Item1; pt2 = stringParts.Item2; // print the name at top if (item.Identified) { color = item.ReturnRarityColor(); } GUI.Console.Print(width + 1, 1, name, color); GUI.Console.Print(width + 1, 2, pt2, color); Tuple <byte, Color> comparisonArrow = GUI.GetItemArrow(item); if (comparisonArrow.Item1 != 0) { GUI.Console.SetGlyph(width + 1 + (pt2 == "" ? name.Length : pt2.Length), pt2 == "" ? 1 : 2, comparisonArrow.Item1, comparisonArrow.Item2); } //// print the splash art //bool thisItemHasSplashArt = item.splash != null; //if (thisItemHasSplashArt) // for (int i = 0; i < 18; i++) // for (int j = 0; j < 10; j++) // Program.mapConsole.Set(i, j + 3, item.splash[i, j].color, Swatch.SecondaryDarker, item.splash[i, j].character); //print the item description color = new Color(100, 116, 136, 0.99F); int numlines = Program.Window.Print(GUI.Console, width + 1, 13, item.Description, 18, color); // print the weight, volume, and durability color = new Color(Color.LightGray, 0.99F); string plural = "."; if (item.Weight > 1) { plural = "s."; } GUI.Console.Print(width + 1, 14 + numlines, "Weight: " + Math.Round(item.Weight, 2) + " lb" + plural, color); GUI.Console.Print(width + 1, 14 + numlines + 2, "Size: " + Math.Round(Convert.FromCubicFeetToCubicInches(item.Volume), 2), color); GUI.Console.Print(width + 7, 14 + numlines + 3, "cubic inches", color); GUI.Console.Print(width + 1, 14 + numlines + 4, $"Impact Dur.: {item.ImpactDurability / Physics.ImpactFractures[item.Material]*100}%", color); GUI.Console.Print(width + 1, 14 + numlines + 5, $"Shear Dur.: {item.ShearDurability / Physics.ShearFractures[item.Material] * 100}%", color); int actionsStartY = Program.Console.Height - 7; // print the actions for (int x = width + 1; x <= width + 12; x += 11) { color = Color.Orange; Color highlightingColor = Color.Green; bool highlightingAction = false; bool thisIsTheFirstIteration = x == width + 1; string action = thisIsTheFirstIteration ? "[eat]" : "[drink]"; if (Program.Window.MousePos.Y == actionsStartY && Program.Window.MousePos.X >= x && Program.Window.MousePos.X < x + action.Length) { highlightingAction = true; } GUI.Console.Print(x, actionsStartY, action, highlightingAction ? highlightingColor : color, lighterColor); highlightingAction = false; action = thisIsTheFirstIteration ? "[drop]" : "[equip]"; if (Program.Window.MousePos.Y == actionsStartY + 2 && Program.Window.MousePos.X >= x && Program.Window.MousePos.X < x + action.Length) { highlightingAction = true; } GUI.Console.Print(x, actionsStartY + 2, action, highlightingAction ? highlightingColor : color, lighterColor); if (thisIsTheFirstIteration) { highlightingAction = false; action = "[open]"; if (Program.Window.MousePos.Y == actionsStartY + 4 && Program.Window.MousePos.X >= x && Program.Window.MousePos.X < x + action.Length) { highlightingAction = true; } GUI.Console.Print(x, actionsStartY + 4, action, highlightingAction ? highlightingColor : color, lighterColor); } } }
public static void RenderItemView() { if (currentlyViewedItem == null) { return; } // initialize variables Item item = currentlyViewedItem; string name = item.Name; float fgAlpha = 0.99F; Color color = new Color(Color.AntiqueWhite, fgAlpha); if (GUI.Console.GetGlyph(width + 1, 1) != name[0]) { string pt2 = ""; // split the name into two lines if necessary Tuple <string, string> stringParts = Window.SplitNameIfGreaterThanLength(name, pt2, 18); name = stringParts.Item1; pt2 = stringParts.Item2; // print the name at top if (item.Identified) { color = item.ReturnRarityColor(); } GUI.Console.Print(width + 1, 1, name, color); GUI.Console.Print(width + 1, 2, pt2, color); Tuple <byte, Color> comparisonArrow = GUI.GetItemArrow(item); if (comparisonArrow.Item1 != 0) { GUI.Console.SetGlyph(width + 1 + (pt2 == "" ? name.Length : pt2.Length), pt2 == "" ? 1 : 2, comparisonArrow.Item1, comparisonArrow.Item2); } } //// print the splash art //bool thisItemHasSplashArt = item.splash != null; //if (thisItemHasSplashArt) // for (int i = 0; i < 18; i++) // for (int j = 0; j < 10; j++) // Program.mapConsole.Set(i, j + 3, item.splash[i, j].color, Swatch.SecondaryDarker, item.splash[i, j].character); //print the item description if (GUI.Console.GetGlyph(width + 1, 13) != item.Description[0]) { color = new Color(100, 116, 136, 0.99F); Program.Window.Print(GUI.Console, width + 1, 13, item.Description, 18, color); } // print the weight, volume, and quality if (GUI.Console.GetGlyph(width + 1, 21) != 'W') { color = new Color(Color.LightGray, 0.99F); string plural = "."; if (item.Weight > 1) { plural = "s."; } GUI.Console.Print(width + 1, 21, "Weight: " + Math.Round(item.Weight, 2) + " lb" + plural, color); GUI.Console.Print(width + 1, 23, "Size: " + Math.Round(Convert.FromCubicFeetToCubicInches(item.Volume), 2), color); } GUI.Console.Print(width + 7, 24, "cubic inches", color); // print the actions for (int x = width + 1; x <= width + 12; x += 11) { color = Color.Orange; Color highlightingColor = Color.Green; bool highlightingAction = false; string action = ""; bool thisIsTheFirstIteration = x == width + 1; if (thisIsTheFirstIteration) { action = "[drop]"; } else { action = "[throw]"; } if (Program.Window.MousePos.Y == 27 && Program.Window.MousePos.X >= x && Program.Window.MousePos.X < x + action.Length) { highlightingAction = true; } if (highlightingAction) { GUI.Console.Print(x, 27, action, highlightingColor, lighterColor); } else { GUI.Console.Print(x, 27, action, color, lighterColor); } highlightingAction = false; if (thisIsTheFirstIteration) { action = "[drink]"; } else { action = "[equip]"; } if (Program.Window.MousePos.Y == 29 && Program.Window.MousePos.X >= x && Program.Window.MousePos.X < x + action.Length) { highlightingAction = true; } if (highlightingAction) { GUI.Console.Print(x, 29, action, highlightingColor, lighterColor); } else { GUI.Console.Print(x, 29, action, color, lighterColor); } } }