Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SmeltingRecipeWidget.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
7
9
11
13
15
17
18 public string m_nameSuffix;
19
20 public bool m_dirty = true;
21
22 public string NameSuffix {
23 get => m_nameSuffix;
24 set {
25 if (value != m_nameSuffix) {
26 m_nameSuffix = value;
27 m_dirty = true;
28 }
29 }
30 }
31
33 get => m_recipe;
34 set {
35 if (value != m_recipe) {
36 m_recipe = value;
37 m_dirty = true;
38 }
39 }
40 }
41
43 XElement node = ContentManager.Get<XElement>("Widgets/SmeltingRecipe");
44 LoadContents(this, node);
45 m_nameWidget = Children.Find<LabelWidget>("SmeltingRecipeWidget.Name");
46 m_descriptionWidget = Children.Find<LabelWidget>("SmeltingRecipeWidget.Description");
47 m_gridWidget = Children.Find<GridPanelWidget>("SmeltingRecipeWidget.Ingredients");
48 m_fireWidget = Children.Find<FireWidget>("SmeltingRecipeWidget.Fire");
49 m_resultWidget = Children.Find<CraftingRecipeSlotWidget>("SmeltingRecipeWidget.Result");
50 for (int i = 0; i < m_gridWidget.RowsCount; i++) {
51 for (int j = 0; j < m_gridWidget.ColumnsCount; j++) {
52 CraftingRecipeSlotWidget widget = new();
53 m_gridWidget.Children.Add(widget);
54 m_gridWidget.SetWidgetCell(widget, new Point2(j, i));
55 }
56 }
57 }
58
59 public override void MeasureOverride(Vector2 parentAvailableSize) {
60 if (m_dirty) {
62 }
63 base.MeasureOverride(parentAvailableSize);
64 }
65
66 public virtual void UpdateWidgets() {
67 m_dirty = false;
68 if (m_recipe != null) {
70 m_nameWidget.Text = block.GetDisplayName(null, m_recipe.ResultValue)
71 + (!string.IsNullOrEmpty(NameSuffix) ? NameSuffix : string.Empty);
72 m_descriptionWidget.Text = m_recipe.Description;
73 m_nameWidget.IsVisible = true;
74 m_descriptionWidget.IsVisible = true;
75 foreach (Widget widget in m_gridWidget.Children) {
76 if (widget is CraftingRecipeSlotWidget child) {
77 Point2 widgetCell = m_gridWidget.GetWidgetCell(child);
78 child.SetIngredient(m_recipe.Ingredients[widgetCell.X + widgetCell.Y * 3]);
79 }
80 }
81 m_resultWidget.SetResult(m_recipe.ResultValue, m_recipe.ResultCount);
82 m_fireWidget.ParticlesPerSecond = 40f;
83 }
84 else {
85 m_nameWidget.IsVisible = false;
86 m_descriptionWidget.IsVisible = false;
87 foreach (Widget widget in m_gridWidget.Children) {
88 (widget as CraftingRecipeSlotWidget)?.SetIngredient(null);
89 }
90 m_resultWidget.SetResult(0, 0);
91 m_fireWidget.ParticlesPerSecond = 0f;
92 }
93 }
94 }
95}
virtual string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
readonly WidgetsList Children
static object Get(Type type, string name)
CraftingRecipeSlotWidget m_resultWidget
override void MeasureOverride(Vector2 parentAvailableSize)
static int ExtractContents(int value)
virtual void LoadContents(object eventsTarget, XElement node)