Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
RecipaediaScreen.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
5 public class RecipaediaScreen : Screen {
6 internal class Order {
7 public Block block;
8 public int order;
9 public int value;
10
11 public Order(Block b, int o, int v) {
12 block = b;
13 order = o;
14 value = v;
15 }
16 }
17
25
26 public List<string> m_categories = [];
27 public int m_categoryIndex;
28 public int m_listCategoryIndex = -1;
29 public const string fName = "RecipaediaScreen";
30
36 public virtual void OnBlocksListItemClicked(object item) {
37 if (m_blocksList.SelectedItem == item
38 && item is int) {
39 int value = (int)item;
41 ScreensManager.m_screens["RecipaediaDescription"] = block.GetBlockDescriptionScreen(value);
42 ScreensManager.SwitchScreen("RecipaediaDescription", item, m_blocksList.Items.Cast<int>().ToList());
43 }
44 }
45
47 XElement node = ContentManager.Get<XElement>("Screens/RecipaediaScreen");
48 LoadContents(this, node);
49 m_blocksList = Children.Find<ListPanelWidget>("BlocksList");
50 m_categoryLabel = Children.Find<LabelWidget>("Category");
51 m_prevCategoryButton = Children.Find<ButtonWidget>("PreviousCategory");
52 m_nextCategoryButton = Children.Find<ButtonWidget>("NextCategory");
53 m_detailsButton = Children.Find<ButtonWidget>("DetailsButton");
54 m_recipesButton = Children.Find<ButtonWidget>("RecipesButton");
55 m_categories.Add(null);
57 m_blocksList.ItemWidgetFactory = delegate(object item) {
58 int value = (int)item;
59 int num = Terrain.ExtractContents(value);
60 Block block = BlocksManager.Blocks[num];
61 XElement node2 = ContentManager.Get<XElement>("Widgets/RecipaediaItem");
62 ContainerWidget obj = (ContainerWidget)LoadWidget(this, node2, null);
63 obj.Children.Find<BlockIconWidget>("RecipaediaItem.Icon").Value = value;
64 obj.Children.Find<LabelWidget>("RecipaediaItem.Text").Text = block.GetDisplayName(null, value);
65 string description = block.GetDescription(value);
66 description = description.Replace("\n", " ");
67 obj.Children.Find<LabelWidget>("RecipaediaItem.Details").Text = description;
68 return obj;
69 };
70 m_blocksList.ItemClicked += OnBlocksListItemClicked;
71 }
72
73 public override void Enter(object[] parameters) {
74 if (ScreensManager.PreviousScreen != ScreensManager.FindScreen<Screen>("RecipaediaRecipes")
75 && ScreensManager.PreviousScreen != ScreensManager.FindScreen<Screen>("RecipaediaDescription")) {
77 }
78 }
79
80 public override void Update() {
83 }
84 string arg = m_categories[m_categoryIndex] == null
85 ? LanguageControl.Get("BlocksManager", "All Blocks")
87 m_categoryLabel.Text = $"{arg} ({m_blocksList.Items.Count})";
88 m_prevCategoryButton.IsEnabled = m_categoryIndex > 0;
89 m_nextCategoryButton.IsEnabled = m_categoryIndex < m_categories.Count - 1;
90 int? value = null;
91 int num = 0;
92 if (m_blocksList.SelectedItem is int) {
93 value = (int)m_blocksList.SelectedItem;
94 num = CraftingRecipesManager.Recipes.Count(r => r.ResultValue == value);
95 }
96 if (num > 0) {
97 m_recipesButton.Text = $"{num} {(num == 1 ? LanguageControl.Get(fName, 1) : LanguageControl.Get(fName, 2))}";
98 m_recipesButton.IsEnabled = true;
99 }
100 else {
101 m_recipesButton.Text = LanguageControl.Get(fName, 3);
102 m_recipesButton.IsEnabled = false;
103 }
104 m_detailsButton.IsEnabled = value.HasValue;
105 if (m_prevCategoryButton.IsClicked
106 || Input.Left) {
108 }
109 if (m_nextCategoryButton.IsClicked
110 || Input.Right) {
112 }
113 if (value.HasValue
114 && m_detailsButton.IsClicked) {
115 Block block = BlocksManager.Blocks[Terrain.ExtractContents(value.Value)];
116 ScreensManager.m_screens["RecipaediaDescription"] = block.GetBlockDescriptionScreen(value.Value);
117 ScreensManager.SwitchScreen("RecipaediaDescription", value.Value, m_blocksList.Items.Cast<int>().ToList());
118 }
119 if (value.HasValue
120 && m_recipesButton.IsClicked) {
121 Block block = BlocksManager.Blocks[Terrain.ExtractContents(value.Value)];
122 ScreensManager.m_screens["RecipaediaRecipes"] = block.GetBlockRecipeScreen(value.Value);
123 ScreensManager.SwitchScreen("RecipaediaRecipes", value.Value);
124 }
125 if (Input.Back
126 || Input.Cancel
127 || Children.Find<ButtonWidget>("TopBar.Back").IsClicked) {
129 }
130 }
131
132 public void PopulateBlocksList() {
134 string text = m_categories[m_categoryIndex];
135 m_blocksList.ScrollPosition = 0f;
136 m_blocksList.ClearItems();
137 List<Order> orders = [];
138 foreach (Block item in BlocksManager.Blocks) {
139 foreach (int creativeValue in item.GetCreativeValues()) {
140 if (string.IsNullOrEmpty(text)
141 || item.GetCategory(creativeValue) == text) {
142 orders.Add(new Order(item, item.GetDisplayOrder(creativeValue), creativeValue));
143 }
144 }
145 }
146 IOrderedEnumerable<Order> orderList = orders.OrderBy(o => o.order);
147 foreach (Order c in orderList) {
148 m_blocksList.AddItem(c.value);
149 }
150 }
151 }
152}
static int Min(int x1, int x2)
static int Max(int x1, int x2)
virtual string GetCategory(int value)
virtual RecipaediaRecipesScreen GetBlockRecipeScreen(int value)
virtual string GetDescription(int value)
virtual int GetDisplayOrder(int value)
virtual string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
virtual RecipaediaDescriptionScreen GetBlockDescriptionScreen(int value)
virtual IEnumerable< int > GetCreativeValues()
static ReadOnlyList< string > Categories
readonly WidgetsList Children
static object Get(Type type, string name)
static List< CraftingRecipe > Recipes
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
virtual void OnBlocksListItemClicked(object item)
在方块项目被点击时执行 改用实名方法,便于模组删除或禁用
override void Enter(object[] parameters)
static Screen PreviousScreen
上一个Screen
static void SwitchScreen(string name, params object[] parameters)
static Dictionary< string, Screen > m_screens
static int ExtractContents(int value)
static Widget LoadWidget(object eventsTarget, XElement node, ContainerWidget parentWidget)
virtual void LoadContents(object eventsTarget, XElement node)