Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
CreativeInventoryPanel.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
7
9
10 public List<int> m_slotIndices = [];
11
13
14 public int m_pagesCount;
15
16 public int m_assignedCategoryIndex = -1;
17
18 public int m_assignedPageIndex = -1;
19
20 public CreativeInventoryPanel(CreativeInventoryWidget creativeInventoryWidget) {
21 m_creativeInventoryWidget = creativeInventoryWidget;
22 m_componentCreativeInventory = creativeInventoryWidget.Entity.FindComponent<ComponentCreativeInventory>(true);
23 XElement node = ContentManager.Get<XElement>("Widgets/CreativeInventoryPanel");
24 LoadContents(this, node);
25 m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
26 for (int i = 0; i < m_inventoryGrid.RowsCount; i++) {
27 for (int j = 0; j < m_inventoryGrid.ColumnsCount; j++) {
28 InventorySlotWidget widget = new() { HideEditOverlay = true, HideInteractiveOverlay = true, HideFoodOverlay = true };
29 m_inventoryGrid.Children.Add(widget);
30 m_inventoryGrid.SetWidgetCell(widget, new Point2(j, i));
31 }
32 }
33 }
34
35 public override void Update() {
36 if (m_assignedCategoryIndex >= 0) {
37 if (Input.Scroll.HasValue) {
38 Widget widget = HitTestGlobal(Input.Scroll.Value.XY);
39 if (widget != null
41 m_componentCreativeInventory.PageIndex -= (int)Input.Scroll.Value.Z;
42 }
43 }
44 if (m_creativeInventoryWidget.PageDownButton.IsClicked) {
46 }
47 if (m_creativeInventoryWidget.PageUpButton.IsClicked) {
49 }
50 m_componentCreativeInventory.PageIndex = m_pagesCount > 0
51 ? Math.Clamp(m_componentCreativeInventory.PageIndex, 0, m_pagesCount - 1)
52 : 0;
53 }
55 if (m_creativeInventoryWidget.GetCategoryName(m_componentCreativeInventory.CategoryIndex)
56 == LanguageControl.Get("CreativeInventoryWidget", 2)) {
57 m_slotIndices = new List<int>(Enumerable.Range(10, m_componentCreativeInventory.OpenSlotsCount - 10));
58 }
59 else {
60 m_slotIndices.Clear();
61 for (int i = m_componentCreativeInventory.OpenSlotsCount; i < m_componentCreativeInventory.SlotsCount; i++) {
62 int slotValue = m_componentCreativeInventory.GetSlotValue(i);
63 int num2 = Terrain.ExtractContents(slotValue);
64 if (BlocksManager.Blocks[num2].GetCategory(slotValue)
65 == m_creativeInventoryWidget.GetCategoryName(m_componentCreativeInventory.CategoryIndex)) {
66 m_slotIndices.Add(i);
67 }
68 }
69 }
70 int num3 = m_inventoryGrid.ColumnsCount * m_inventoryGrid.RowsCount;
71 m_pagesCount = (m_slotIndices.Count + num3 - 1) / num3;
74 m_componentCreativeInventory.PageIndex = 0;
75 }
77 int num4 = m_inventoryGrid.ColumnsCount * m_inventoryGrid.RowsCount;
78 int num5 = m_componentCreativeInventory.PageIndex * num4;
79 foreach (Widget child in m_inventoryGrid.Children) {
80 if (child is InventorySlotWidget inventorySlotWidget) {
81 if (num5 < m_slotIndices.Count) {
82 inventorySlotWidget.AssignInventorySlot(m_componentCreativeInventory, m_slotIndices[num5++]);
83 }
84 else {
85 inventorySlotWidget.AssignInventorySlot(null, 0);
86 }
87 }
88 }
90 }
91 m_creativeInventoryWidget.PageLabel.Text = m_pagesCount > 0
92 ? $"{m_componentCreativeInventory.PageIndex + 1}/{m_pagesCount}"
93 : string.Empty;
94 m_creativeInventoryWidget.PageDownButton.IsEnabled = m_componentCreativeInventory.PageIndex < m_pagesCount - 1;
95 m_creativeInventoryWidget.PageUpButton.IsEnabled = m_componentCreativeInventory.PageIndex > 0;
96 }
97 }
98}
virtual string GetCategory(int value)
readonly WidgetsList Children
static object Get(Type type, string name)
CreativeInventoryPanel(CreativeInventoryWidget creativeInventoryWidget)
ComponentCreativeInventory m_componentCreativeInventory
CreativeInventoryWidget m_creativeInventoryWidget
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static int ExtractContents(int value)
virtual Widget HitTestGlobal(Vector2 point, Func< Widget, bool > predicate=null)
WidgetInput Input
virtual void LoadContents(object eventsTarget, XElement node)
virtual bool IsChildWidgetOf(ContainerWidget containerWidget)