Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ShortInventoryWidget.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
7
9
10 public int MinVisibleSlotsCount = 7;
11
12 public int MaxVisibleSlotsCount = 7;
13
15
17 XElement node = ContentManager.Get<XElement>("Widgets/ShortInventoryWidget");
18 LoadContents(this, node);
19 m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
20 }
21
22 public void AssignComponents(IInventory inventory) {
23 if (inventory != m_inventory) {
24 m_inventory = inventory;
25 m_inventoryGrid.Children.Clear();
26 }
27 }
28
29 public override void MeasureOverride(Vector2 parentAvailableSize) {
30 if (m_inventory == null) return;
32 m_inventory.VisibleSlotsCount = Math.Clamp((int)((parentAvailableSize.X - 320f - 25f) / 72f), MinVisibleSlotsCount, max);
33 if (m_inventory.VisibleSlotsCount != m_inventoryGrid.Children.Count) {
34 m_inventoryGrid.Children.Clear();
35 m_inventoryGrid.RowsCount = 1;
36 m_inventoryGrid.ColumnsCount = m_inventory.VisibleSlotsCount;
37 for (int i = 0; i < m_inventoryGrid.ColumnsCount; i++) {
38 InventorySlotWidget inventorySlotWidget = new();
39 inventorySlotWidget.AssignInventorySlot(m_inventory, i);
40 inventorySlotWidget.BevelColor = new Color(181, 172, 154) * 0.6f;
41 inventorySlotWidget.CenterColor = new Color(181, 172, 154) * 0.33f;
42 m_inventoryGrid.Children.Add(inventorySlotWidget);
43 m_inventoryGrid.SetWidgetCell(inventorySlotWidget, new Point2(i, 0));
44 }
45 }
46 base.MeasureOverride(parentAvailableSize);
47 }
48 }
49}
Engine.Color Color
readonly WidgetsList Children
static object Get(Type type, string name)
virtual void AssignInventorySlot(IInventory inventory, int slotIndex)
override void MeasureOverride(Vector2 parentAvailableSize)
void AssignComponents(IInventory inventory)
virtual void LoadContents(object eventsTarget, XElement node)