Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
LevelFactorDialog.cs
浏览该文件的文档.
1using System.Globalization;
2using System.Xml.Linq;
3
4namespace Game {
5 public class LevelFactorDialog : Dialog {
13 public const string fName = "LevelFactorDialog";
14
15 public LevelFactorDialog(string title, string description, IEnumerable<ComponentLevel.Factor> factors, float total) {
16 XElement node = ContentManager.Get<XElement>("Dialogs/LevelFactorDialog");
17 LoadContents(this, node);
18 m_titleWidget = Children.Find<LabelWidget>("LevelFactorDialog.Title");
19 m_descriptionWidget = Children.Find<LabelWidget>("LevelFactorDialog.Description");
20 m_namesWidget = Children.Find<LabelWidget>("LevelFactorDialog.Names");
21 m_valuesWidget = Children.Find<LabelWidget>("LevelFactorDialog.Values");
22 m_totalNameWidget = Children.Find<LabelWidget>("LevelFactorDialog.TotalName");
23 m_totalValueWidget = Children.Find<LabelWidget>("LevelFactorDialog.TotalValue");
24 m_okWidget = Children.Find<ButtonWidget>("LevelFactorDialog.OK");
25 m_titleWidget.Text = title;
26 m_descriptionWidget.Text = description;
27 m_namesWidget.Text = string.Empty;
28 m_valuesWidget.Text = string.Empty;
29 foreach (ComponentLevel.Factor factor in factors) {
30 m_namesWidget.Text += $"{factor.Description,24}\n";
31 string factorValueString = factor.Value switch {
32 float.NegativeInfinity => LanguageControl.Get(fName, "1"),
33 float.PositiveInfinity => LanguageControl.Get(fName, "2"),
34 _ => string.Format(CultureInfo.InvariantCulture, "{0:0.00}", factor.Value)
35 };
36 m_valuesWidget.Text += factor.FactorAdditionType switch {
37 FactorAdditionType.Multiply => $"x {factorValueString}\n",
38 _ => $"+ {factorValueString}\n"
39 };
40 }
41 m_namesWidget.Text = m_namesWidget.Text.TrimEnd();
42 m_valuesWidget.Text = m_valuesWidget.Text.TrimEnd();
43 m_totalNameWidget.Text = $"{LanguageControl.Get(fName, "3"),24}";
44 m_totalValueWidget.Text = string.Format(CultureInfo.InvariantCulture, "x {0:0.00}", total);
45 }
46
47 public override void Update() {
48 if (Input.Cancel
49 || m_okWidget.IsClicked) {
51 }
52 }
53 }
54}
这里的Factor类型从struct改为class,是由于模组在修改Factor的时候,通常是需要修改引用的值。 如果是struct则只能复制并修改值,不能修改引用。
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
LevelFactorDialog(string title, string description, IEnumerable< ComponentLevel.Factor > factors, float total)
virtual void LoadContents(object eventsTarget, XElement node)