Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
CreativeInventoryWidget.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
4
5namespace Game {
7 public class Category {
8 public string Name;
9
10 public Color Color = Color.White;
11
13 }
14
15 public List<Category> m_categories = [];
16
17 public int m_activeCategoryIndex = -1;
18
20
22
24
26
28
30 public static string fName = "CreativeInventoryWidget";
31
33
35
37
39
41
43
46 XElement node = ContentManager.Get<XElement>("Widgets/CreativeInventoryWidget");
47 LoadContents(this, node);
48 m_categoryLeftButton = Children.Find<ButtonWidget>("CategoryLeftButton");
49 m_categoryRightButton = Children.Find<ButtonWidget>("CategoryRightButton");
50 m_categoryButton = Children.Find<ButtonWidget>("CategoryButton");
51 m_pageUpButton = Children.Find<ButtonWidget>("PageUpButton");
52 m_pageDownButton = Children.Find<ButtonWidget>("PageDownButton");
53 m_pageLabel = Children.Find<LabelWidget>("PageLabel");
54 m_panelContainer = Children.Find<ContainerWidget>("PanelContainer");
55 CreativeInventoryPanel creativeInventoryPanel = new(this) { IsVisible = false };
56 m_panelContainer.Children.Add(creativeInventoryPanel);
57 FurnitureInventoryPanel furnitureInventoryPanel = new(this) { IsVisible = false };
58 m_panelContainer.Children.Add(furnitureInventoryPanel);
59 foreach (string category in BlocksManager.Categories) {
60 m_categories.Add(new Category { Name = category, Panel = creativeInventoryPanel });
61 }
62 m_categories.Add(new Category { Name = LanguageControl.Get(fName, 1), Panel = furnitureInventoryPanel });
63 m_categories.Add(new Category { Name = LanguageControl.Get(fName, 2), Panel = creativeInventoryPanel });
64 foreach (Category category in m_categories) {
65 category.Color = category.Name switch {
66 "Minerals" => new Color(128, 128, 128),
67 "Electrics" => new Color(128, 140, 255),
68 "Plants" => new Color(64, 160, 64),
69 "Weapons" => new Color(255, 128, 112),
70 _ => category.Color
71 };
72 }
73 }
74
75 public string GetCategoryName(int index) => m_categories[index].Name;
76
77 public override void Update() {
78 if (Input.Scroll.HasValue) {
79 Widget widget = HitTestGlobal(Input.Scroll.Value.XY);
80 if (widget != null
82 m_componentCreativeInventory.CategoryIndex -= (int)Input.Scroll.Value.Z;
83 }
84 }
85 if (m_categoryLeftButton.IsClicked
86 || Input.Left) {
87 --m_componentCreativeInventory.CategoryIndex;
88 }
89 if (m_categoryRightButton.IsClicked
90 || Input.Right) {
91 ++m_componentCreativeInventory.CategoryIndex;
92 }
93 if (m_categoryButton.IsClicked) {
94 ComponentPlayer componentPlayer = Entity.FindComponent<ComponentPlayer>();
95 if (componentPlayer != null) {
97 componentPlayer.GuiWidget,
99 string.Empty,
101 56f,
102 c => new LabelWidget {
103 Text = LanguageControl.Get("BlocksManager", ((Category)c).Name),
104 Color = ((Category)c).Color,
107 },
108 delegate(object c) {
109 if (c != null) {
110 m_componentCreativeInventory.CategoryIndex = m_categories.IndexOf((Category)c);
111 }
112 }
113 )
114 );
115 }
116 }
117 m_componentCreativeInventory.CategoryIndex = Math.Clamp(m_componentCreativeInventory.CategoryIndex, 0, m_categories.Count - 1);
118 m_categoryButton.Text = LanguageControl.Get("BlocksManager", m_categories[m_componentCreativeInventory.CategoryIndex].Name);
119 m_categoryLeftButton.IsEnabled = m_componentCreativeInventory.CategoryIndex > 0;
120 m_categoryRightButton.IsEnabled = m_componentCreativeInventory.CategoryIndex < m_categories.Count - 1;
122 foreach (Category category in m_categories) {
123 category.Panel.IsVisible = false;
124 }
125 m_categories[m_componentCreativeInventory.CategoryIndex].Panel.IsVisible = true;
127 }
128 }
129 }
130}
Engine.Color Color
static ReadOnlyList< string > Categories
readonly WidgetsList Children
static object Get(Type type, string name)
ComponentCreativeInventory m_componentCreativeInventory
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
virtual string Name
virtual Widget HitTestGlobal(Vector2 point, Func< Widget, bool > predicate=null)
virtual bool IsVisible
WidgetInput Input
virtual WidgetAlignment VerticalAlignment
virtual WidgetAlignment HorizontalAlignment
virtual void LoadContents(object eventsTarget, XElement node)
virtual bool IsChildWidgetOf(ContainerWidget containerWidget)
Component FindComponent(Type type, string name, bool throwOnError)