Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SelectClassSubstituteDialog.cs
浏览该文件的文档.
1using System.Xml.Linq;
2
3namespace Game {
5 public string m_guid;
6 public XElement m_element;
7 public Action m_handler;
8
10
11 public const string fName = "SelectClassSubstituteDialog";
12
13 public SelectClassSubstituteDialog(string guid, XElement element, Action handler) {
14 m_guid = guid;
15 m_element = element;
16 m_handler = handler;
17 LoadContents(this, ContentManager.Get<XElement>("Dialogs/SelectClassSubstituteDialog"));
18 m_listPanel = Children.Find<ListPanelWidget>("SelectClassSubstituteDialog.ListPanel");
19 m_listPanel.ItemWidgetFactory = o => {
20 if (o is not ModsManager.ClassSubstitute substitute) {
21 return null;
22 }
23 if (substitute.PackageName == "survivalcraft") {
24 return new LabelWidget() {
25 Text = $"{LanguageControl.Get(fName, "1")} - {substitute.ClassName}", VerticalAlignment = WidgetAlignment.Center
26 };
27 }
28 if (ModsManager.PackageNameToModEntity.TryGetValue(substitute.PackageName, out ModEntity modEntity)) {
29 return new ScrollPanelWidget() {
30 Direction = LayoutDirection.Horizontal,
31 Children = {
32 new LabelWidget() {
33 Text = $"{modEntity.modInfo.Name} - {substitute.ClassName}", VerticalAlignment = WidgetAlignment.Center
34 }
35 }
36 };
37 }
38 return null;
39 };
40 m_listPanel.ItemClicked = o => {
41 if (o is not ModsManager.ClassSubstitute substitute) {
42 return;
43 }
45 m_element.SetAttributeValue("Value", substitute.ClassName);
47 m_handler?.Invoke();
48 };
49 if (ModsManager.ClassSubstitutes.TryGetValue(guid, out List<ModsManager.ClassSubstitute> substitutes)
50 && substitutes.Count > 0) {
51 string description = element.Parent?.Attribute("Description")?.Value ?? LanguageControl.Unknown;
52 if (description.StartsWith('[')
53 && description.EndsWith(']')) {
54 string[] array = description.Substring(1, description.Length - 2).Split(':');
55 if (array.Length == 2) {
56 description = LanguageControl.GetDatabase(array[0], array[1]);
57 }
58 }
59 Children.Find<LabelWidget>("SelectClassSubstituteDialog.Description")?.Text = string.Format(
61 substitutes.Count - 1,
62 substitutes[0].ClassName,
63 description
64 );
65 m_listPanel.AddItems(substitutes);
66 if (ModsManager.SelectedClassSubstitutes.TryGetValue(guid, out ModsManager.ClassSubstitute selected)) {
67 m_listPanel.SelectedItem = selected;
68 }
69 }
70 }
71
72 public override void Update() {
73 if (Input.Back
74 || Input.Cancel
75 || (Input.Tap.HasValue && !HitTest(Input.Tap.Value))) {
76 // 直接关闭将保持原版
78 m_handler?.Invoke();
79 }
80 }
81 }
82}
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static string GetDatabase(string name, string prop)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
SelectClassSubstituteDialog(string guid, XElement element, Action handler)
virtual bool HitTest(Vector2 point)
virtual WidgetAlignment VerticalAlignment
virtual void LoadContents(object eventsTarget, XElement node)
static Dictionary< string, ModEntity > PackageNameToModEntity
含所有已启用的模组
static Dictionary< string, List< ClassSubstitute > > ClassSubstitutes
static Dictionary< string, ClassSubstitute > SelectedClassSubstitutes