public SlotInventory(BinderItem itemBinder, string[] comboBoxList) { this.itemBinder = itemBinder; list = comboBoxList; selectedItem = itemBinder.name; CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; Width = 230; Height = 160; itemType = new ComboBox(); itemType.Width = 180; itemType.DataSource = new string[] { itemBinder.name }; itemType.DropDownStyle = ComboBoxStyle.DropDown; itemType.AutoCompleteMode = AutoCompleteMode.SuggestAppend; itemType.KeyDown += (sender, e) => { if (e.KeyCode == Keys.Enter) { nonKeyEvent(sender, e); } }; itemType.DropDownClosed += new EventHandler(nonKeyEvent); itemType.LostFocus += new EventHandler(nonKeyEvent); EventHandler handler = null; handler = (sender, e) => populateComboBox(sender, e, list, selectedItem, handler); itemType.DropDown += handler; Controls.Add(itemType, 0, 0); generateSlot(); }
public TabInventory(PlayerDataFile playerDataFile) { this.playerDataFile = playerDataFile; Text = "Inventory"; panel = new TableLayoutPanel(); panel.Dock = DockStyle.Fill; panel.AutoSize = true; panel.RowCount = 5; panel.ColumnCount = 8; for (int i = 0; i < 4; i++) { for (int j = 0; j < 8; j++) { ItemStack itemStack = playerDataFile.bag[i * 8 + j]; BinderItem itemBinder = new BinderItem(itemStack); SlotInventory slot = new SlotInventory(itemBinder, DataItem.getNameList()); panel.Controls.Add(slot, j, i); } } for (int i = 0; i < 8; i++) { ItemStack itemStack = playerDataFile.inventory[i]; BinderItem itemBinder = new BinderItem(itemStack); SlotInventory slot = new SlotInventory(itemBinder, DataItem.getNameList()); panel.Controls.Add(slot, i, 4); } Controls.Add(panel); }
public WindowParts(BinderItem parent, SlotInventory slotInventory) { Height = 600; Width = 500; FormClosed += (sender, e) => { bool empty = true; for (int i = 0; i < 4; i++) { if (parent.parts[i].type.get() != 0) { empty = false; } } if (empty) { slotInventory.selectedItem = "air"; slotInventory.resetSlot(); } else { int quality = parent.getQuality(); if (quality == 0) { slotInventory.qualityBox.Text = ""; } else { slotInventory.qualityBox.Text = quality.ToString(); } parent.itemValue.quality.set(quality); } }; TableLayoutPanel mainPanel = new TableLayoutPanel(); mainPanel.Dock = DockStyle.Fill; mainPanel.BackColor = System.Drawing.Color.Yellow; mainPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; TableLayoutPanel parts = new TableLayoutPanel(); parts.Dock = DockStyle.Fill; parts.Height = 340; Label partsLabel = new Label(); partsLabel.Text = "Parts"; parts.Controls.Add(partsLabel, 0, 0); partList = new BinderItem[4]; for (int i = 0; i < 4; i++) { partList[i] = new BinderItem(parent.itemValue.parts[i]); } partList = sortList(partList, parent.partNames); int k = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { string[] list = new string[2] { "air", parent.partNames[k] }; parts.Controls.Add(new SlotInventory(partList[k++], list), i, j + 1); } } mainPanel.Controls.Add(parts, 0, 1); if (parent.attachmentNames != null) { TableLayoutPanel attachments = new TableLayoutPanel(); attachments.Dock = DockStyle.Fill; Label attachmentsLabel = new Label(); attachmentsLabel.Text = "Attachments"; attachments.Controls.Add(attachmentsLabel, 0, 0); attachmentList = new List<BinderItem>(); for (int i = 0; i < parent.attachmentNames.Length; i++) { if ((i < parent.attachments.Count) && (parent.attachments[i] != null)) { attachmentList.Add(new BinderItem(parent.attachments[i])); } else { if (i < parent.attachments.Count) { attachmentList[i] = new BinderItem(DataItem.getItemDataByName("air")); parent.attachments[i] = attachmentList[i].itemValue; } else { attachmentList.Add(new BinderItem(DataItem.getItemDataByName("air"))); parent.attachments.Add(attachmentList[i].itemValue); } } } k = 0; for (int i = 0; i < (parent.attachmentNames.Length / 2) + 1; i++) { for (int j = 0; j < 2; j++) { if (k < attachmentList.Count) { string[] nameList = new string[2] { "air", parent.attachmentNames[k] }; attachments.Controls.Add(new SlotInventory(attachmentList[k++], nameList), j, i + 1); } } } mainPanel.Controls.Add(attachments, 0, 3); } Controls.Add(mainPanel); ShowDialog(); }
private BinderItem[] sortList(BinderItem[] list, string[] nameList) { BinderItem[] sortedList = new BinderItem[nameList.Length]; int airSpacesAlreadyIn = 0; for (int i = 0; i < nameList.Length; i++) { bool filled = false; foreach (BinderItem itemBinder in list) { if ((itemBinder != null) && (itemBinder.name.Equals(nameList[i]))) { sortedList[i] = itemBinder; filled = true; } } if (!filled) { int airSpaces = 0; foreach (BinderItem itemBinder in list) { if ((itemBinder != null) && (itemBinder.name.Equals("air"))) { airSpaces++; if (airSpaces > airSpacesAlreadyIn) { sortedList[i] = itemBinder; airSpacesAlreadyIn++; break; } } } } } return sortedList; }
public TextBoxDegradation(Value<int> value, int min, int max, BinderItem itemBinder) : base(value, min, max) { Text = (max - value.get()).ToString(); this.itemBinder = itemBinder; }