-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchessapp.kv
419 lines (362 loc) · 10.7 KB
/
chessapp.kv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#:kivy 2.0.0
#:import math math
#:import utils kivy.utils
#:import Window kivy.core.window.Window
#:import BoardWidget boardwidget
#:include msgbox.kv
#:include settings.kv
<FontScalingLabel>:
canvas.before:
Color:
rgba: self.background or self.default_background
RoundedRectangle:
pos: [i+j for i,j in zip(self.pos, self.margin)]
size: [i-2*j for i,j in zip(self.size, self.margin)]
radius: 16,
Color:
rgba: 1,1,1,1
background: None
on_text: self.scale_font()
<AwesomeActionButton@ActionButton>:
font_name: app.font_awesome
font_size: sp(20)
background_disabled_normal: self.background_normal
minimum_width: sp(80)
<AwesomeLabel@Label>:
font_size: dp(20)
font_name: app.font_awesome
markup: True
halign: 'left'
text_size: self.width, None
height: self.texture_size[1]
padding: [5, 0, 5, 0] # for captured pieces
<MenuButton@Button>:
on_release: app.menu.dismiss()
height: sp(60)
font_size: sp(20)
size_hint_y: None
background_disabled_normal: self.background_normal
<Menu>:
auto_width: False
width: min(sp(250), Window.size[0] / 2)
canvas.before:
Color:
rgba: utils.get_color_from_hex('#303030d0')
Rectangle:
pos: self.pos
size: self.size
MenuButton:
text: 'New Game'
id: new_button
on_release: app.new_game()
MenuButton:
text: 'Auto Open'
id: auto_open_button
on_release: app.auto_open()
MenuButton:
text: 'Edit Board'
id: edit_button
on_release: app.edit_start()
MenuButton:
text: 'Puzzles'
id: puzzles_button
on_release: app.puzzles()
MenuButton:
text: 'Settings'
id: settings_menu_button
on_release: app.settings()
MenuButton:
text: 'About'
on_release: app.about()
MenuButton:
text: 'Exit'
id: exit_button
on_release: app.exit()
<Root>:
cols: 1
canvas.before:
Color:
rgb: utils.get_color_from_hex('#000505')
Rectangle:
pos: self.pos
size: self.size
# Labels for moves, status
BoxLayout:
id: status
orientation: 'horizontal'
size_hint: 1, 0.075
spacing: 3
padding: 5
canvas.before:
Color:
rgb: utils.get_color_from_hex('#303030')
Rectangle:
pos: self.pos
size: self.size
FontScalingLabel:
id: w_move_label
size_hint: 0.35, 1
markup: True
text_size: self.width, None
halign: 'left'
padding: [10,0,10,0]
background: 0,0,0,0
FontScalingLabel:
id: status_label
size_hint: 1, 0.85
pos_hint: {'center_x':.5, 'center_y':.5}
markup: True
halign: 'center'
FontScalingLabel:
id: b_move_label
size_hint: 0.3, 1
markup: True
text_size: self.width, None
halign: 'right'
padding: [10,0,10,0]
background: 0,0,0,0
ProgressBar:
id: progress
max: 20
size_hint: 1, 0
canvas:
Color:
rgb: (1 - .5/(1+math.exp(-self.value+20)), .5 + .5/(1+math.exp(-self.value+18)), 0)
BorderImage:
# Border information in the format (bottom, right, top, left).
border: [1,0,1,0]
pos: self.x, self.center_y - 1
size: self.width * (self.value / float(self.max)) if self.max else 0, 4
RelativeLayout:
orientation: 'vertical'
Label:
background: 0,0,0,0
x: 0
size_hint: None, 0.1
id: hash_label
halign: 'left'
valign: 'top'
font_name: 'DejaVuSans'
font_size: 0
FontScalingLabel:
background: 0,0,0,0
x: root.width - self.width
size_hint: None, 0.1
id: nps_label
halign: 'right'
valign: 'top'
font_name: 'DejaVuSans'
AwesomeLabel:
pos_hint: { 'y': 0.912 }
size_hint: 1, 0.1
id: captures_theirs
halign: 'right'
BoardWidget:
id: board_widget
y_size_hint: 0.7
# label that shows name of opening (e.g. Sicilian Defense)
FontScalingLabel:
id: opening
color: utils.get_color_from_hex('#FFD700')
background: 0,0,0,0
markup: True
on_ref_press:
import webbrowser
webbrowser.open(args[1])
max_font_size: sp(16)
pos_hint: { 'y': 0.0075 }
size_hint: 1, 0.1
text_size: self.width, None
height: self.texture_size[1]
halign: 'center'
valign: 'top'
AwesomeLabel:
size_hint: 1, 0.055
id: captures_ours
ActionBar:
id: action
size_hint: 1, 0.085
ActionView:
use_separator: True
RotatingActionPrevious:
id: menu_button
app_icon:'images/logo_50.png'
previous_image:'images/menu-bar.png'
previous_image_width: sp(32)
previous_image_height: sp(32)
on_release: app.on_menu_button(self)
AwesomeActionButton:
text: ' \uF130 '
id: voice_button
disabled: not app._use_voice
on_release: app.speech_input()
ActionSeparator:
AwesomeActionButton:
text: ' \uF2EA '
id: undo_button
on_press: app.undo_move(self)
AwesomeActionButton:
text: ' \uF2F9 '
id: redo_button
on_press: app.redo_move(self)
AwesomeActionButton:
text: ' \uF021 '
id: switch_button
on_release: app.flip_board()
# Share (export game transcript)
AwesomeActionButton:
text: ' \uF1E0 ' if utils.platform == 'android' else ' \uF0CB '
id: share_button
on_release: app.share()
# Turn AI on/off
AwesomeActionButton:
text: ' \uF205 '
id: play_button
on_release: app.set_study_mode(not app.study_mode)
AwesomeActionButton:
text: ' \uF013 '
id: settings_button
on_release: app.settings()
<EditButton@Button>:
markup: True
font_name: 'fonts/Font Awesome 5 Free Solid.ttf'
font_size: min(sp(24), Window.size[0] / 24)
background_normal: 'atlas://data/images/defaulttheme/action_item'
background_disabled_normal: 'atlas://data/images/defaulttheme/action_item'
<EditControls>:
canvas.before:
Color:
rgba: 0.85,0.9,0.75,0.45
Rectangle:
pos: self.pos
size: self.size
rows: 2
cols: 12
col_default_width: self.size[0] / 12
col_force_default: True
EditButton:
text: '\uF468'
on_press: app.edit_start_drag(1, True)
EditButton:
text: '\uF469'
on_press: app.edit_start_drag(2, True)
EditButton:
text: '\uF46A'
on_press: app.edit_start_drag(3, True)
EditButton:
text: '\uF46B'
on_press: app.edit_start_drag(4, True)
EditButton:
text: '\uF46C'
on_press: app.edit_start_drag(5, True)
EditButton:
text: '\uF46D'
on_press: app.edit_start_drag(6, True)
Widget:
# placeholder
EditButton:
text: '\uF021'
on_release: app.edit_flip_board()
EditButton:
text: '\uF1F8'
on_release: app.edit_clear()
EditButton:
text: '\uF042'
on_release: app.edit_flip_turn()
EditButton:
text: '\uF058'
on_release: app.edit_stop(True)
id: apply_and_stop
disabled: True
EditButton:
text: '\uF057'
on_release: app.edit_stop(False)
EditButton:
text: '[color=000000]\uF468[/color]'
on_press: app.edit_start_drag(1, False)
EditButton:
text: '[color=000000]\uF469[/color]'
on_press: app.edit_start_drag(2, False)
EditButton:
text: '[color=000000]\uF46A[/color]'
on_press: app.edit_start_drag(3, False)
EditButton:
text: '[color=000000]\uF46B[/color]'
on_press: app.edit_start_drag(4, False)
EditButton:
text: '[color=000000]\uF46C[/color]'
on_press: app.edit_start_drag(5, False)
EditButton:
text: '[color=000000]\uF46D[/color]'
on_press: app.edit_start_drag(6, False)
<PuzzleView>:
_container: container
_info: info
_scroll: scroll
cols: 1
Label:
id: info
size_hint_y: 0.1
ScrollView:
id: scroll
GridLayout:
cols: 1
id: container
height: root._board_size * root._page_size
size_hint_y: None
padding: [(root.width - root._board_size) / 2, 0, 0, 0]
spacing: sp(12)
GridLayout:
cols: 5
size_hint: 1, None
height: dp(48)
AwesomeActionButton:
text: '\uF100'
disabled: root.prev_page_size == 0
on_release: root.prev_page()
Widget:
AwesomeActionButton:
text: 'Play'
disabled: root.selection is None
on_release: root.play(root.selection.puzzle)
Widget:
AwesomeActionButton:
text: '\uF101'
disabled: root.next_page_size == 0
on_release: root.next_page()
<Selection>:
selected: False
canvas:
Color:
rgba: [47 / 255., 167 / 255., 212 / 255., 1.] if self.selected else [0,0,0,0]
Rectangle:
pos: sp(-2), sp(-2)
size: self.width + sp(4), self.height + sp(4)
#
# Layout for Natural Language input box
#
<LanguageInput>:
cols: 1
rows: 2
TextInput:
id: text
multiline: True
use_handles: False
size_hint_y: 0.5
#:import ScrollEffect kivy.effects.scroll.ScrollEffect
<ScrolledPad>:
ScrollView:
id: scroll
do_scroll_x: False
do_scroll_y: True
effect_cls: ScrollEffect
Notepad:
id: text
width: root.width
text: root.text
font_name: root.font_name
font_size: root.font_size
readonly: root.readonly
use_bubble: root.use_bubble
background_color: root.background_color
lined: root.lined