/// <summary> /// Generates a panel holding all attachment info. /// </summary> /// <returns>Panel holding all attachment info</returns> private TableLayoutPanel GenerateAttachments() { if (itemBinder.itemData.attachmentNames != null) { TableLayoutPanel attachments = new TableLayoutPanel() { CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset, AutoSize = true }; string[] addedAttachments = new string[itemBinder.itemValue.attachments.Count]; for (int i = 0; i < itemBinder.itemValue.attachments.Count; ++i) { ItemBinder attachment = new ItemBinder(itemBinder.itemValue.attachments[i]); InventorySlotAttachment slotAttachment = new InventorySlotAttachment(attachment, this, i, 80, 180); attachments.Controls.Add(slotAttachment, i / 2, i % 2); } return(attachments); } return(null); }
/// <summary> /// Default constructor. /// </summary> /// <param name="itemBinder">The part</param> /// <param name="parent">GUI parent of the part</param> /// <param name="partIndex">Index of the part</param> /// <param name="textBoxWidth">Width of the textBox</param> /// <param name="labeledControlWidth">Width of the labeledBox</param> public InventorySlotPart(ItemBinder itemBinder, InventorySlotItem parent, int partIndex, int textBoxWidth, int labeledControlWidth) : base(itemBinder, textBoxWidth, labeledControlWidth) { this.parent = parent; Size = new Size(326, 104); imageLabel = new Label(); imageLabel.Anchor = AnchorStyles.Left; imageLabel.Size = new Size(IconData.ICON_WIDTH, IconData.ICON_HEIGHT); SetImage(); Controls.Add(imageLabel, 0, 0); itemCore = new TableLayoutPanel(); itemCore.Anchor = AnchorStyles.Right; itemCore.Size = new Size(200, 100); CreateSelector(new string[] { parent.itemBinder.itemData.partNames[partIndex], "air" }); selector.DropDownStyle = ComboBoxStyle.DropDownList; itemCore.Controls.Add(selector, 0, 0); basicInfo = GenerateBasicInfo(); itemCore.Controls.Add(basicInfo, 0, 1); Controls.Add(itemCore, 1, 0); }
/// <summary> /// Sets up inventory for editing. Adds air items to any potential attachment slots. /// </summary> /// <param name="itemStacks">Inventory to be set up</param> private void SetUpInventory(ItemStack[] itemStacks) { for (int i = 0; i < itemStacks.Length; i++) { ItemData itemData = ItemData.GetItemDataByItemValue(itemStacks[i].itemValue); string[] attachmentNames = itemData.attachmentNames; if (attachmentNames != null) { List <ItemValue> attachments = new List <ItemValue>(); foreach (string attachmentName in attachmentNames) { bool added = false; foreach (ItemValue attachment in itemStacks[i].itemValue.attachments) { if (attachmentName.Equals(ItemData.GetItemDataByItemValue(attachment).name)) { attachments.Add(attachment); added = true; } } if (!added) { attachments.Add(ItemBinder.GetAir().itemValue); } } itemStacks[i].itemValue.attachments = attachments; } } }
/// <summary> /// Default constructor. /// </summary> /// <param name="itemBinder">ItemBinder associated with this inventory slot</param> /// <param name="textBoxWidth">Width of the textBox</param> /// <param name="labeledControlWidth">Width of the labeled control</param> public InventorySlotBase(ItemBinder itemBinder, int textBoxWidth, int labeledControlWidth) { this.itemBinder = itemBinder; this.textBoxWidth = textBoxWidth; this.labeledControlWidth = labeledControlWidth; selectedItem = itemBinder.itemData.name; }
/// <summary> /// Resets itemBinder to specified itemData. /// </summary> /// <param name="itemData">ItemData to reset the itemBinder to</param> public void ResetItemBinder(ItemData itemData) { if (itemStack != null) { itemStack.count.Set(itemData.stackNumber); } ItemBinder.ResetItemValue(itemData, itemValue); ReferenceValueAndData(itemValue); }
/// <summary> /// Resets itemValue to speficied itemData. /// </summary> /// <param name="itemData">ItemData to reset to</param> /// <param name="itemValue">ItemValue to reset</param> private static void ResetItemValue(ItemData itemData, ItemValue itemValue) { itemValue.type = new Value <int>(itemData.id); itemValue.useTimes = new Value <int>(0); itemValue.quality = new Value <int>(0); itemValue.meta = new Value <int>(0); itemValue.selectedAmmoTypeIndex = new Value <byte>(0); itemValue.activated = new Value <bool>(false); itemValue.parts = new ItemValue[4]; itemValue.attachments = new List <ItemValue>(); if (itemData.name != "air") { if (itemData.hasQuality) { itemValue.quality.Set(ItemData.MAX_QUALITY); if (itemData.partNames != null) { itemValue.parts = new ItemValue[4]; int quality = 0; for (int i = 0; i < 4; i++) { itemValue.parts[i] = new ItemValue(); itemValue.parts[i].itemValueVersion = new Value <byte>(3); ItemBinder.ResetItemValue(ItemData.GetItemDataByName(itemData.partNames[i]), itemValue.parts[i]); quality += itemValue.parts[i].quality.Get(); } itemValue.quality.Set(quality / 4); } if (itemData.attachmentNames != null) { itemValue.attachments = new List <ItemValue>(); for (int i = 0; i < itemData.attachmentNames.Length; i++) { itemValue.attachments.Add(new ItemValue()); itemValue.attachments[i].itemValueVersion = new Value <byte>(3); ItemBinder.ResetItemValue(ItemData.GetItemDataByName(itemData.attachmentNames[i]), itemValue.attachments[i]); } } } } }
/// <summary> /// Default constructor. /// </summary> /// <param name="itemBinder">An item to show</param> /// <param name="viewPanel">Panel that holds the image of the item</param> /// <param name="textBoxWidth">Width of the textBox</param> /// <param name="labeledControlWidth">Width of the labeled control</param> public InventorySlotItem(ItemBinder itemBinder, ViewPanel viewPanel, int textBoxWidth, int labeledControlWidth) : base(itemBinder, textBoxWidth, labeledControlWidth) { this.viewPanel = viewPanel; Size = new Size(956, 268); CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset; itemCore = new TableLayoutPanel(); itemCore.Size = new Size(262, 248); CreateSelector(ItemData.GetNameList()); selector.DropDownStyle = ComboBoxStyle.DropDown; selector.AutoCompleteMode = AutoCompleteMode.SuggestAppend; itemCore.Controls.Add(selector, 0, 0); imageLabel = new Label(); imageLabel.Size = new Size(IconData.ICON_WIDTH, IconData.ICON_HEIGHT); SetImage(); itemCore.Controls.Add(imageLabel, 0, 1); basicInfo = GenerateBasicInfo(); basicInfo.Anchor = AnchorStyles.Top; itemCore.Controls.Add(basicInfo, 0, 2); Controls.Add(itemCore, 0, 0); parts = GenerateParts(); attachments = GenerateAttachments(); if (parts != null || attachments != null) { scrollPanel = new ScrollPanel(); scrollPanel.Size = new Size(676, 248); if (parts != null) { scrollPanel.Controls.Add(parts, 0, 0); } if (attachments != null) { scrollPanel.Controls.Add(attachments, 1, 0); } Controls.Add(scrollPanel, 1, 0); } }
/// <summary> /// Sets the image of specified itemBinder /// </summary> /// <param name="itemBinder"></param> public void SetImage(ItemBinder itemBinder) { Text = ""; BackgroundImage = null; Bitmap image = itemBinder.GetImage(IconData.ICON_WIDTH, IconData.ICON_HEIGHT); if (image != null) { BackgroundImage = image; } else { Text = string.Format("({0})", itemBinder.itemData.name); TextAlign = ContentAlignment.MiddleCenter; } }
/// <summary> /// Generates a panel holding all parts info. /// </summary> /// <returns>Panel holding all parts info</returns> private TableLayoutPanel GenerateParts() { if (itemBinder.itemData.partNames != null) { TableLayoutPanel parts = new TableLayoutPanel(); parts.Size = new Size(670, 226); parts.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset; for (int i = 0; i < 4; i++) { ItemBinder part = new ItemBinder(itemBinder.itemValue.parts[i]); InventorySlotPart slotPart = new InventorySlotPart(part, this, i, 80, 180); parts.Controls.Add(slotPart, i / 2, i % 2); } return(parts); } return(null); }
/// <summary> /// Default constructor. /// </summary> /// <param name="playerDataFile">PlayerDataFile which inventory is to be used</param> public InventoryTab(PlayerDataFile playerDataFile) { Text = "Inventory"; this.playerDataFile = playerDataFile; SetUpInventory(playerDataFile.bag); SetUpInventory(playerDataFile.inventory); itemBinders = new ItemBinder[40]; itemSlots = new InventorySlotItem[40]; viewPanels = new ViewPanel[40]; for (int i = 0; i < 32; i++) { itemBinders[i] = new ItemBinder(playerDataFile.bag[i]); viewPanels[i] = new ViewPanel(i, this); itemSlots[i] = new InventorySlotItem(itemBinders[i], viewPanels[i], 140, 250); } for (int i = 32; i < 40; i++) { itemBinders[i] = new ItemBinder(playerDataFile.inventory[i - 32]); viewPanels[i] = new ViewPanel(i, this); itemSlots[i] = new InventorySlotItem(itemBinders[i], viewPanels[i], 140, 250); } TableLayoutPanel basicPanel = new TableLayoutPanel() { Dock = DockStyle.Fill, AutoSize = true }; itemView = new TableLayoutPanel(); itemView.Dock = DockStyle.Top; itemView.AutoSize = true; itemView.MinimumSize = new Size(0, 260); activeIndex = 0; viewPanels[activeIndex].BackColor = COLOR_SELECT; itemView.Controls.Add(itemSlots[activeIndex]); basicPanel.Controls.Add(itemView); TableLayoutPanel inventoryDisplay = new TableLayoutPanel() { CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset, Anchor = AnchorStyles.Bottom, Size = new Size(946, 412) }; inventoryDisplay.MouseLeave += (sender, e) => { itemView.Controls.RemoveAt(0); itemView.Controls.Add(itemSlots[activeIndex]); itemSlots[activeIndex].OverrideBug(); }; for (int i = 0; i < 40; i++) { inventoryDisplay.Controls.Add(viewPanels[i], i % 8, i / 8); } basicPanel.Controls.Add(inventoryDisplay); Controls.Add(basicPanel); }