Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
EditColorDialog.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
4
5namespace Game {
6 public class EditColorDialog : Dialog {
14
15 public Action<Color?> m_handler;
16 public Color m_color;
17 public const string fName = "EditColorDialog";
18
19 public EditColorDialog(Color color, Action<Color?> handler) {
20 WidgetsList children = Children;
21 CanvasWidget obj = new() {
22 Size = new Vector2(660f, 420f),
25 Children = { new BevelledRectangleWidget { Style = ContentManager.Get<XElement>("Styles/DialogArea") } }
26 };
27 WidgetsList children2 = obj.Children;
28 StackPanelWidget obj2 = new() {
29 Direction = LayoutDirection.Vertical,
30 Margin = new Vector2(15f),
32 Children = {
34 new CanvasWidget { Size = new Vector2(0f, 1f / 0f) }
35 }
36 };
37 WidgetsList children3 = obj2.Children;
38 StackPanelWidget obj3 = new() { Direction = LayoutDirection.Horizontal };
39 WidgetsList children4 = obj3.Children;
40 StackPanelWidget obj4 = new() { Direction = LayoutDirection.Vertical, VerticalAlignment = WidgetAlignment.Center };
41 WidgetsList children5 = obj4.Children;
42 StackPanelWidget obj5 = new() {
43 Direction = LayoutDirection.Horizontal,
45 Margin = new Vector2(0f, 10f),
46 Children = {
48 new CanvasWidget { Size = new Vector2(10f, 0f) }
49 }
50 };
51 WidgetsList children6 = obj5.Children;
52 SliderWidget obj6 = new() {
53 Size = new Vector2(300f, 50f), IsLabelVisible = false, MinValue = 0f, MaxValue = 255f, Granularity = 1f, SoundName = ""
54 };
55 SliderWidget widget = obj6;
56 m_sliderR = obj6;
57 children6.Add(widget);
58 children5.Add(obj5);
59 WidgetsList children7 = obj4.Children;
60 StackPanelWidget obj7 = new() {
61 Direction = LayoutDirection.Horizontal,
63 Margin = new Vector2(0f, 10f),
64 Children = {
66 new CanvasWidget { Size = new Vector2(10f, 0f) }
67 }
68 };
69 WidgetsList children8 = obj7.Children;
70 SliderWidget obj8 = new() {
71 Size = new Vector2(300f, 50f), IsLabelVisible = false, MinValue = 0f, MaxValue = 255f, Granularity = 1f, SoundName = ""
72 };
73 widget = obj8;
74 m_sliderG = obj8;
75 children8.Add(widget);
76 children7.Add(obj7);
77 WidgetsList children9 = obj4.Children;
78 StackPanelWidget obj9 = new() {
79 Direction = LayoutDirection.Horizontal,
81 Margin = new Vector2(0f, 10f),
82 Children = {
84 new CanvasWidget { Size = new Vector2(10f, 0f) }
85 }
86 };
87 WidgetsList children10 = obj9.Children;
88 SliderWidget obj10 = new() {
89 Size = new Vector2(300f, 50f), IsLabelVisible = false, MinValue = 0f, MaxValue = 255f, Granularity = 1f, SoundName = ""
90 };
91 widget = obj10;
92 m_sliderB = obj10;
93 children10.Add(widget);
94 children9.Add(obj9);
95 children4.Add(obj4);
96 obj3.Children.Add(new CanvasWidget { Size = new Vector2(20f, 0f) });
97 WidgetsList children11 = obj3.Children;
98 CanvasWidget canvasWidget = new();
99 WidgetsList children12 = canvasWidget.Children;
100 BevelledButtonWidget obj11 = new() {
101 Size = new Vector2(200f, 240f),
102 AmbientLight = 1f,
105 };
106 BevelledButtonWidget widget2 = obj11;
107 m_rectangle = obj11;
108 children12.Add(widget2);
109 WidgetsList children13 = canvasWidget.Children;
111 LabelWidget widget3 = obj12;
112 m_label = obj12;
113 children13.Add(widget3);
114 children11.Add(canvasWidget);
115 children3.Add(obj3);
116 obj2.Children.Add(new CanvasWidget { Size = new Vector2(0f, 1f / 0f) });
117 WidgetsList children14 = obj2.Children;
118 StackPanelWidget obj13 = new() { Direction = LayoutDirection.Horizontal, HorizontalAlignment = WidgetAlignment.Center };
119 WidgetsList children15 = obj13.Children;
120 BevelledButtonWidget obj14 = new() { Size = new Vector2(160f, 60f), Text = LanguageControl.Ok };
121 ButtonWidget widget4 = obj14;
122 m_okButton = obj14;
123 children15.Add(widget4);
124 obj13.Children.Add(new CanvasWidget { Size = new Vector2(50f, 0f) });
125 WidgetsList children16 = obj13.Children;
126 BevelledButtonWidget obj15 = new() { Size = new Vector2(160f, 60f), Text = LanguageControl.Cancel };
127 widget4 = obj15;
128 m_cancelButton = obj15;
129 children16.Add(widget4);
130 children14.Add(obj13);
131 children2.Add(obj2);
132 children.Add(obj);
133 m_handler = handler;
134 m_color = color;
136 }
137
138 public override void Update() {
139 if (m_rectangle.IsClicked) {
141 this,
142 new TextBoxDialog(
145 20,
146 delegate(string s) {
147 if (s != null) {
148 try {
150 }
151 catch {
153 this,
154 new MessageDialog(
158 null,
159 null
160 )
161 );
162 }
163 }
164 }
165 )
166 );
167 }
168 if (m_sliderR.IsSliding) {
169 m_color.R = (byte)m_sliderR.Value;
170 }
171 if (m_sliderG.IsSliding) {
172 m_color.G = (byte)m_sliderG.Value;
173 }
174 if (m_sliderB.IsSliding) {
175 m_color.B = (byte)m_sliderB.Value;
176 }
177 if (m_okButton.IsClicked) {
179 }
180 if (Input.Cancel
181 || m_cancelButton.IsClicked) {
182 Dismiss(null);
183 }
185 }
186
187 public virtual void UpdateControls() {
188 m_rectangle.CenterColor = m_color;
189 m_sliderR.Value = m_color.R;
190 m_sliderG.Value = m_color.G;
191 m_sliderB.Value = m_color.B;
192 m_label.Text = GetColorString();
193 }
194
195 public string GetColorString() => $"#{m_color.R:X2}{m_color.G:X2}{m_color.B:X2}";
196
197 public void Dismiss(Color? result) {
199 m_handler?.Invoke(result);
200 }
201 }
202}
static object ConvertFromString(Type type, string data)
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
BevelledButtonWidget m_rectangle
void Dismiss(Color? result)
EditColorDialog(Color color, Action< Color?> handler)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
virtual WidgetAlignment VerticalAlignment
virtual Vector2 Margin
virtual WidgetAlignment HorizontalAlignment
XElement Style
void Add(Widget widget)
static Color Gray