Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
EditPaletteDialog.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
5 public class EditPaletteDialog : Dialog {
9 public LinkWidget[] m_labels = new LinkWidget[16];
12
15 public const string fName = "EditPaletteDialog";
16
18 XElement node = ContentManager.Get<XElement>("Dialogs/EditPaletteDialog");
19 LoadContents(this, node);
20 m_listPanel = Children.Find<ContainerWidget>("EditPaletteDialog.ListPanel");
21 m_okButton = Children.Find<ButtonWidget>("EditPaletteDialog.OK");
22 m_cancelButton = Children.Find<ButtonWidget>("EditPaletteDialog.Cancel");
23 for (int i = 0; i < 16; i++) {
24 StackPanelWidget obj = new() {
25 Direction = LayoutDirection.Horizontal,
26 Children = {
27 new CanvasWidget {
28 Size = new Vector2(32f, 60f),
29 Children = {
30 new LabelWidget {
31 Text = $"{i + 1}.",
35 }
36 }
37 },
38 new CanvasWidget { Size = new Vector2(10f, 0f) }
39 }
40 };
42 obj.Children.Add(new CanvasWidget { Size = new Vector2(10f, 0f) });
43 obj.Children.Add(
45 Size = new Vector2(1f / 0f, 60f),
46 BevelSize = 1f,
47 AmbientLight = 1f,
48 DirectionalLight = 0.4f,
50 }
51 );
52 obj.Children.Add(new CanvasWidget { Size = new Vector2(10f, 0f) });
53 obj.Children.Add(
55 Size = new Vector2(160f, 60f), VerticalAlignment = WidgetAlignment.Center, Text = LanguageControl.Get(fName, 1)
56 }
57 );
58 obj.Children.Add(new CanvasWidget { Size = new Vector2(10f, 0f) });
59 StackPanelWidget widget = obj;
60 m_listPanel.Children.Add(widget);
61 }
62 m_palette = palette;
64 m_palette.CopyTo(m_tmpPalette);
65 }
66
67 public override void Update() {
68 for (int j = 0; j < 16; j++) {
69 m_labels[j].Text = m_tmpPalette.Names[j];
70 m_rectangles[j].CenterColor = m_tmpPalette.Colors[j];
71 m_resetButtons[j].IsEnabled = m_tmpPalette.Colors[j] != WorldPalette.DefaultColors[j]
73 }
74 for (int k = 0; k < 16; k++) {
75 int i = k;
76 if (m_labels[k].IsClicked) {
78 this,
79 new TextBoxDialog(
81 m_labels[k].Text,
82 16,
83 delegate(string s) {
84 if (s != null) {
86 m_tmpPalette.Names[i] = s;
87 }
88 else {
90 this,
91 new MessageDialog(LanguageControl.Get(fName, 3), null, LanguageControl.Ok, null, null)
92 );
93 }
94 }
95 }
96 )
97 );
98 }
99 if (m_rectangles[k].IsClicked) {
101 this,
102 new EditColorDialog(
103 m_tmpPalette.Colors[k],
104 delegate(Color? color) {
105 if (color.HasValue) {
106 m_tmpPalette.Colors[i] = color.Value;
107 }
108 }
109 )
110 );
111 }
112 if (m_resetButtons[k].IsClicked) {
115 }
116 }
117 if (m_okButton.IsClicked) {
118 m_tmpPalette.CopyTo(m_palette);
119 Dismiss();
120 }
121 if (Input.Cancel
122 || m_cancelButton.IsClicked) {
123 Dismiss();
124 }
125 }
126
127 public void Dismiss() {
129 }
130 }
131}
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
BevelledButtonWidget[] m_rectangles
EditPaletteDialog(WorldPalette palette)
static string GetWorldPalette(int index)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
virtual WidgetAlignment VerticalAlignment
virtual WidgetAlignment HorizontalAlignment
virtual void LoadContents(object eventsTarget, XElement node)
void Add(Widget widget)
static bool VerifyColorName(string name)
static readonly Color[] DefaultColors
static Color Gray