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