-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.qml
More file actions
1414 lines (1327 loc) · 68 KB
/
Copy pathPanel.qml
File metadata and controls
1414 lines (1327 loc) · 68 KB
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls as Controls
import QtQuick.Layouts
import Quickshell
import qs.Commons
import "components" as ChessUi
Item {
id: root
property string omarchyPath: ""
property var shell: null
property var manifest: null
property var service: null
property bool closingFromHost: false
property string requestedView: "home"
property string currentView: "home"
property string payloadNotice: ""
property string actionNotice: ""
property string selectedSquare: ""
property string cursorSquare: "e2"
property var legalTargets: []
property string manualOrientation: ""
property string confirmAction: ""
property var pendingNewGameOptions: null
property bool drawActionsOpen: false
property bool resultDialogDismissed: false
property int replayPly: 0
property string replayOrientation: "white"
property string pendingHistoryId: ""
property size preferredWindowSize: Qt.size(960, 720)
property real measuredGameViewportWidth: 0
property real measuredGameViewportHeight: 0
property real measuredBoardSize: 0
property real measuredRailHeight: 0
property real measuredRailImplicitHeight: 0
readonly property var game: service && service.snapshot
? service.snapshot : ({ status: "idle", board: [], moves: [] })
readonly property string gameStatus: String(game.status || "idle")
readonly property bool hasPlayableGame: gameStatus !== "idle"
&& gameStatus !== "completed" && gameStatus !== "abandoned"
readonly property bool gameInputEnabled: gameStatus === "active-human"
&& game.persistence_healthy !== false
readonly property bool wideLayout: gameWindow.width >= 900
readonly property bool mediumLayout: gameWindow.width >= 720
&& gameWindow.width < 900
readonly property bool sideBySideGameLayout: gameWindow.width >= 720
readonly property bool compactLayout: gameWindow.width < 720
readonly property var latestMove: game.moves && game.moves.length > 0
? game.moves[game.moves.length - 1] : null
readonly property string checkedKingSquare: checkedKing()
readonly property string boardOrientation: effectiveOrientation()
readonly property string boardTheme: effectiveBoardTheme()
readonly property bool showLegalMoveHints: effectiveLegalMoveHints()
readonly property bool modalOpen: newGameDialog.opened || promotionDialog.opened
|| confirmDialog.opened
readonly property bool aiError: game.save_error
&& game.save_error.category === "ai"
readonly property bool gameClockEnabled: game.clock
&& game.clock.enabled === true
readonly property var replayData: service && service.replaySnapshot
? service.replaySnapshot : null
readonly property var replayFrame: replayData && replayData.frames
&& replayData.frames.length > replayPly ? replayData.frames[replayPly] : null
readonly property string pluginId: manifest && manifest.id
? String(manifest.id) : "io.github.rodrix2000.chess"
readonly property bool opened: gameWindow.visible
readonly property var responsiveMetrics: ({
window_width: gameWindow.width,
window_height: gameWindow.height,
viewport_width: measuredGameViewportWidth,
viewport_height: measuredGameViewportHeight,
board_size: measuredBoardSize,
rail_height: measuredRailHeight,
rail_implicit_height: measuredRailImplicitHeight,
board_theme: boardTheme,
show_legal_moves: showLegalMoveHints,
side_by_side: sideBySideGameLayout,
compact: compactLayout
})
signal gameFocusRequested()
function validView(value) {
var name = String(value || "home")
var supported = ["home", "game", "history", "help", "settings",
"setup-local", "setup-computer"]
return supported.indexOf(name) >= 0 ? name : "home"
}
function parsePayload(payloadJson) {
requestedView = "home"
payloadNotice = ""
if (!payloadJson) return ({})
try {
var payload = JSON.parse(String(payloadJson))
if (!payload || typeof payload !== "object" || Array.isArray(payload))
return ({})
if (typeof payload.view === "string") requestedView = validView(payload.view)
return payload
} catch (error) {
payloadNotice = "The launch request was invalid, so Home was opened."
return ({})
}
}
function open(payloadJson) {
closingFromHost = false
var payload = parsePayload(payloadJson)
currentView = requestedView
if (payload.action === "resume" && service
&& typeof service.resumeGame === "function") {
invoke(service.resumeGame())
currentView = "game"
} else if (payload.action === "new") {
var setupMode = payload.mode === "local" ? "local" : "computer"
currentView = "home"
openNewGameDialog(setupMode, payload)
} else if (currentView === "game" && gameStatus === "idle") {
currentView = "home"
}
gameWindow.visible = true
focusScope.focus = true
Qt.callLater(root.focusCurrentView)
}
function focusCurrentView() {
if (!gameWindow.visible || root.modalOpen) return
if (root.currentView === "game") {
root.gameFocusRequested()
return
}
keyCatcher.forceActiveFocus()
}
function pauseCurrentGame(reason) {
if (gameWindow.visible)
keyCatcher.forceActiveFocus()
return service.pauseGame(reason)
}
function close() {
closingFromHost = true
clearSelection()
closeTransientLayers()
if (service && hasPlayableGame && gameStatus !== "paused"
&& gameStatus !== "paused-error"
&& typeof service.pauseGame === "function")
pauseCurrentGame("panel-closed")
keyCatcher.focus = false
focusScope.focus = false
gameWindow.visible = false
closingFromHost = false
}
function requestClose() {
if (shell && typeof shell.hide === "function") shell.hide(pluginId)
else close()
}
function closeTransientLayers() {
newGameDialog.opened = false
confirmDialog.opened = false
drawActionsOpen = false
}
function invoke(commandResult, successMessage) {
if (!commandResult) {
actionNotice = "That action is unavailable."
return false
}
if (commandResult.ok === true) {
actionNotice = successMessage || ""
return true
}
if (commandResult.code === "PERSISTENCE_BUSY")
actionNotice = "Saving… try again in a moment."
else if (commandResult.code === "INVALID_MOVE")
actionNotice = "That move is not legal in this position."
else if (commandResult.code === "COMPUTER_THINKING")
actionNotice = "The computer is thinking."
else if (commandResult.code === "DRAW_CLAIM_NOT_AVAILABLE")
actionNotice = "A draw cannot be claimed yet."
else if (commandResult.code === "UNDO_NOT_AVAILABLE")
actionNotice = "There is no move to take back."
else if (commandResult.code === "ACTIVE_GAME_CONFLICT")
actionNotice = "Finish or abandon the current game first."
else
actionNotice = commandResult.detail || "That action could not be completed."
return false
}
function updateSetting(patch) {
if (invoke(service.updateSettings(patch), "Saving settings…"))
return true
return false
}
function openReplay(gameId) {
actionNotice = "Loading saved game…"
invoke(service.openHistoryGame(gameId))
}
function openNewGameDialog(mode, seed) {
var data = seed || ({})
var settings = service && service.settingsSnapshot ? service.settingsSnapshot : ({})
var gameplay = settings.gameplay || ({})
var appearance = settings.appearance || ({})
newGameDialog.mode = mode === "local" ? "local" : "computer"
newGameDialog.humanColor = data.color || data.human_color
|| gameplay.human_color || "white"
newGameDialog.difficulty = data.difficulty || gameplay.computer_level || "casual"
newGameDialog.timePreset = presetForControl(data.time_control || gameplay.time_control)
newGameDialog.orientation = data.orientation || appearance.orientation || "white"
newGameDialog.opened = true
}
function presetForControl(control) {
if (!control || control.base_ms === null || control.base_ms === undefined)
return "untimed"
if (Number(control.base_ms) === 300000 && Number(control.increment_ms) === 0)
return "5+0"
if (Number(control.base_ms) === 600000 && Number(control.increment_ms) === 5000)
return "10+5"
if (Number(control.base_ms) === 900000 && Number(control.increment_ms) === 10000)
return "15+10"
return "untimed"
}
function normalizeStartOptions(options) {
var source = options || ({})
var control = source.time_control || source.timeControl
if (!control) {
if (source.timePreset === "5+0" || source.time_preset === "5+0")
control = { base_ms: 300000, increment_ms: 0 }
else if (source.timePreset === "10+5" || source.time_preset === "10+5")
control = { base_ms: 600000, increment_ms: 5000 }
else if (source.timePreset === "15+10" || source.time_preset === "15+10")
control = { base_ms: 900000, increment_ms: 10000 }
else
control = { base_ms: null, increment_ms: 0 }
}
return {
mode: source.mode === "local" ? "local" : "computer",
human_color: source.human_color || source.humanColor || "white",
difficulty: source.difficulty || "casual",
time_control: control,
orientation: source.orientation || "white",
players: source.players || {
white: { name: source.whiteName || source.white_name || "White" },
black: { name: source.blackName || source.black_name || "Black" }
}
}
}
function beginGame(options) {
var normalized = normalizeStartOptions(options)
newGameDialog.opened = false
if (hasPlayableGame) {
pendingNewGameOptions = normalized
openConfirmation("replace")
return
}
if (invoke(service.newGame(normalized))) {
currentView = "game"
manualOrientation = ""
resultDialogDismissed = false
clearSelection()
Qt.callLater(root.focusCurrentView)
}
}
function openConfirmation(action) {
confirmAction = action
if (action === "replace") {
confirmDialog.title = "Start a new game?"
confirmDialog.message = "The current game will be archived as abandoned before the new game starts."
confirmDialog.confirmText = "Abandon and start new"
confirmDialog.destructive = true
} else if (action === "undo") {
confirmDialog.title = "Take back the last move?"
confirmDialog.message = game.mode === "computer"
? "Your move and the computer reply will be removed when available."
: "The last move will be removed and the previous turn restored."
confirmDialog.confirmText = "Take back"
confirmDialog.destructive = false
} else if (action === "resign") {
confirmDialog.title = "Resign this game?"
confirmDialog.message = titleCase(game.turn || "The current player")
+ " will lose the game immediately."
confirmDialog.confirmText = "Resign"
confirmDialog.destructive = true
} else if (action === "delete-history") {
confirmDialog.title = "Delete this saved game?"
confirmDialog.message = "Its local JSON record and PGN file will be removed. This cannot be undone."
confirmDialog.confirmText = "Delete saved game"
confirmDialog.destructive = true
} else if (action === "clear-history") {
confirmDialog.title = "Clear all game history?"
confirmDialog.message = "Every completed-game record and PGN in History will be removed. Your active game and settings will stay untouched. This cannot be undone."
confirmDialog.confirmText = "Clear history"
confirmDialog.destructive = true
} else if (action === "reset-settings") {
confirmDialog.title = "Reset all chess settings?"
confirmDialog.message = "Gameplay and accessibility defaults will reset. Active games and history stay untouched."
confirmDialog.confirmText = "Reset settings"
confirmDialog.destructive = false
} else {
confirmDialog.title = "End this game?"
confirmDialog.message = "The unfinished game will be archived as abandoned."
confirmDialog.confirmText = "End game"
confirmDialog.destructive = true
}
confirmDialog.opened = true
}
function performConfirmedAction() {
confirmDialog.opened = false
if (confirmAction === "replace") {
var options = pendingNewGameOptions || ({})
options.conflict = "abandon"
pendingNewGameOptions = null
if (invoke(service.newGame(options), "Archiving the old game…")) {
currentView = "game"
manualOrientation = ""
resultDialogDismissed = false
}
} else if (confirmAction === "undo") {
invoke(service.requestUndo(true))
clearSelection()
} else if (confirmAction === "resign") {
invoke(service.resign(game.turn))
clearSelection()
} else if (confirmAction === "abandon") {
if (invoke(service.abandonGame())) currentView = "home"
clearSelection()
} else if (confirmAction === "delete-history") {
if (invoke(service.removeHistoryGame(pendingHistoryId), "Deleting saved game…"))
currentView = "history"
pendingHistoryId = ""
} else if (confirmAction === "clear-history") {
if (invoke(service.clearHistory(), "Clearing game history…"))
currentView = "history"
} else if (confirmAction === "reset-settings") {
invoke(service.resetSettings(), "Resetting settings…")
}
confirmAction = ""
}
function titleCase(value) {
var text = String(value || "")
return text.length ? text.charAt(0).toUpperCase() + text.slice(1) : ""
}
function moveCountLabel(plyCount) {
var moves = Math.ceil(Math.max(0, Number(plyCount || 0)) / 2)
return moves + (moves === 1 ? " move" : " moves")
}
function pieceAt(square) {
var pieces = game.board || []
for (var index = 0; index < pieces.length; index++)
if (pieces[index].square === square) return pieces[index]
return null
}
function clearSelection() {
selectedSquare = ""
legalTargets = []
}
function selectSquare(square) {
var piece = pieceAt(square)
if (!piece || piece.color !== game.turn) {
clearSelection()
return
}
selectedSquare = square
legalTargets = service && typeof service.legalMoves === "function"
? service.legalMoves(square) : []
}
function isLegalTarget(square) {
for (var index = 0; index < legalTargets.length; index++)
if (legalTargets[index].to === square) return true
return false
}
function activateSquare(square) {
cursorSquare = square
if (!gameInputEnabled) return
if (!selectedSquare) {
selectSquare(square)
return
}
if (square === selectedSquare) {
clearSelection()
return
}
var piece = pieceAt(square)
if (piece && piece.color === game.turn) {
selectSquare(square)
return
}
if (!isLegalTarget(square)) {
actionNotice = "That square is not a legal destination."
return
}
requestBoardMove(selectedSquare, square)
}
function requestBoardMove(from, to) {
if (!gameInputEnabled) return
var commandResult = service.requestMove(from, to, null)
if (commandResult && commandResult.code === "PROMOTION_REQUIRED") {
actionNotice = "Choose a promotion piece."
return
}
if (invoke(commandResult)) clearSelection()
}
function checkedKing() {
if (!game.in_check) return ""
var pieces = game.board || []
for (var index = 0; index < pieces.length; index++)
if (pieces[index].piece === "king" && pieces[index].color === game.turn)
return pieces[index].square
return ""
}
function opposite(side) { return side === "black" ? "white" : "black" }
function capturedBy(side) {
var material = game.material && game.material.counts
? game.material.counts : null
if (!material) return ""
var enemy = opposite(side)
var current = material[enemy] || ({})
var initial = { pawn: 8, knight: 2, bishop: 2, rook: 2, queen: 1 }
var whiteGlyph = { pawn: "♙", knight: "♘", bishop: "♗", rook: "♖", queen: "♕" }
var blackGlyph = { pawn: "♟", knight: "♞", bishop: "♝", rook: "♜", queen: "♛" }
var glyphs = enemy === "white" ? whiteGlyph : blackGlyph
var output = ""
var order = ["queen", "rook", "bishop", "knight", "pawn"]
for (var index = 0; index < order.length; index++) {
var piece = order[index]
var missing = initial[piece] - Number(current[piece] || 0)
for (var count = 0; count < missing; count++) output += glyphs[piece]
}
return output
}
function effectiveOrientation() {
if (manualOrientation) return manualOrientation
var stored = String(game.orientation || "white")
if (stored === "black") return "black"
if (stored === "auto" && game.mode === "local") return game.turn || "white"
if (stored === "manual") return "white"
return game.human_color === "black" ? "black" : "white"
}
function effectiveBoardTheme() {
var appearance = service && service.settingsSnapshot
? service.settingsSnapshot.appearance : null
var requested = String(appearance && appearance.board_theme || "charcoal")
return /^(charcoal|green|ivory)$/.test(requested)
? requested : "charcoal"
}
function effectiveLegalMoveHints() {
var appearance = service && service.settingsSnapshot
? service.settingsSnapshot.appearance : null
return !appearance || appearance.show_legal_moves !== false
}
function flipBoard() {
manualOrientation = boardOrientation === "white" ? "black" : "white"
}
function statusText() {
if (gameStatus === "idle") return "Choose how you want to play"
if (gameStatus === "paused-error")
return aiError ? "Computer move failed — game paused" : "Save failed — game paused"
if (gameStatus === "paused") return "Game paused"
if (gameStatus === "active-computer") return "Computer is thinking"
if (gameStatus === "promotion-pending") return "Choose a promotion piece"
if (gameStatus === "completed") return resultTitle()
if (gameStatus === "abandoned") return "Game ended"
if (game.in_check) return "Check — " + titleCase(game.turn) + " to move"
if (game.mode === "computer" && game.turn === game.human_color) return "Your move"
return titleCase(game.turn) + " to move"
}
function resultTitle() {
var result = game.result || ({})
var winner = result.winner ? titleCase(result.winner) : ""
if (result.reason === "checkmate") return "Checkmate — " + winner + " wins"
if (result.reason === "stalemate") return "Draw by stalemate"
if (result.reason === "dead-position") return "Draw — checkmate is impossible"
if (result.reason === "threefold-claim") return "Draw claimed by repetition"
if (result.reason === "fivefold-automatic") return "Draw by fivefold repetition"
if (result.reason === "fifty-move-claim") return "Draw claimed under the fifty-move rule"
if (result.reason === "seventy-five-move-automatic") return "Draw under the seventy-five-move rule"
if (result.reason === "draw-agreement") return "Draw by agreement"
if (result.reason === "timeout") return winner ? winner + " wins on time" : "Draw on time"
if (result.reason === "timeout-insufficient-mating-possibility")
return "Draw on time — checkmate was impossible"
if (result.reason === "resignation")
return winner ? winner + " wins by resignation" : "Draw after resignation"
return result.score ? "Game finished — " + result.score : "Game finished"
}
function claimCurrentDraw() {
var claims = game.claims || ({})
var type = claims.threefold_current ? "threefold"
: claims.fifty_move_current ? "fifty-move" : ""
if (!type) {
actionNotice = "A draw cannot be claimed in the current position."
return
}
invoke(service.claimDraw(game.turn, type, null))
drawActionsOpen = false
}
function claimProspectiveDraw(entry) {
if (!entry) return
var type = entry.threefold ? "threefold" : "fifty-move"
invoke(service.claimDraw(game.turn, type, entry.uci))
drawActionsOpen = false
clearSelection()
}
function respondToOffer(accept) {
invoke(service.respondToDraw(game.turn, accept))
drawActionsOpen = false
}
function easierDifficulty() {
if (game.difficulty === "strong") return "challenging"
if (game.difficulty === "challenging") return "casual"
return "learner"
}
function replayStep(delta) {
if (!replayData || !replayData.frames) return
replayPly = Math.max(0, Math.min(replayData.frames.length - 1,
replayPly + delta))
}
function handleEscape() {
if (confirmDialog.opened) { confirmDialog.opened = false; return }
if (newGameDialog.opened) { newGameDialog.opened = false; return }
if (gameStatus === "promotion-pending") return
if (drawActionsOpen) { drawActionsOpen = false; return }
if (selectedSquare) { clearSelection(); return }
if (currentView === "replay") {
currentView = "history"
return
}
if (currentView !== "game" && currentView !== "home") {
currentView = "home"
return
}
if (currentView === "game" && hasPlayableGame && gameStatus !== "paused") {
invoke(pauseCurrentGame("user"))
return
}
requestClose()
}
Connections {
target: root.service
ignoreUnknownSignals: true
function onHistoryRecordLoaded(replay) {
root.replayPly = replay && replay.frames ? replay.frames.length - 1 : 0
root.replayOrientation = replay && replay.record
&& replay.record.orientation === "black" ? "black" : "white"
root.currentView = "replay"
root.actionNotice = ""
}
function onHistoryRecordLoadFailed(error) {
root.actionNotice = "That saved game could not be opened. "
+ String(error && error.code || "HISTORY_RECORD_INVALID")
}
function onExportCompleted(path) {
root.actionNotice = "PGN saved to " + path
}
function onSettingsSaved(settings) {
root.actionNotice = "Settings saved."
}
}
onCurrentViewChanged: {
if (gameWindow.visible) Qt.callLater(root.focusCurrentView)
}
FloatingWindow {
id: gameWindow
title: "Omarchy Chess"
implicitWidth: Math.max(640, root.preferredWindowSize.width)
implicitHeight: Math.max(560, root.preferredWindowSize.height)
minimumSize: Qt.size(640, 560)
visible: false
color: Color.background
onVisibleChanged: {
if (!visible && !root.closingFromHost) root.requestClose()
}
FocusScope {
id: focusScope
anchors.fill: parent
focus: gameWindow.visible
Rectangle {
anchors.fill: parent
color: Color.background
ColumnLayout {
anchors.fill: parent
anchors.margins: 20
spacing: 14
RowLayout {
Layout.fillWidth: true
spacing: 10
Rectangle {
visible: root.currentView === "home"
Layout.preferredWidth: 44
Layout.preferredHeight: 44
radius: Math.max(7, Style.cornerRadius)
color: Qt.rgba(Color.foreground.r, Color.foreground.g,
Color.foreground.b, 0.045)
border.width: 1
border.color: Qt.rgba(Color.foreground.r, Color.foreground.g,
Color.foreground.b, 0.2)
ChessUi.ChessPiece {
anchors.centerIn: parent
width: 36
height: 36
pieceColor: "black"
pieceType: "knight"
enabled: false
}
}
ChessUi.SecondaryButton {
visible: root.currentView !== "home"
text: "‹ Home"
accessibleDescription: "Return to home"
onClicked: { root.clearSelection(); root.currentView = "home" }
}
ColumnLayout {
Layout.fillWidth: true
spacing: 1
Text {
text: root.currentView === "game" ? root.statusText() : "Omarchy Chess"
color: Color.foreground
font.pixelSize: root.compactLayout ? 19 : 23
font.weight: Font.DemiBold
elide: Text.ElideRight
Layout.fillWidth: true
}
Text {
visible: root.currentView === "game" && root.game.mode
text: root.game.mode === "computer" ? "Play Computer · " + root.titleCase(root.game.difficulty) : "Local Two-Player"
color: Color.muted
font.pixelSize: 12
}
}
ChessUi.SecondaryButton { text: "History"; visible: !root.compactLayout && root.currentView !== "history"; accessibleDescription: "Open completed game history"; onClicked: root.currentView = "history" }
ChessUi.SecondaryButton { text: "Settings"; visible: !root.compactLayout && root.currentView === "home"; accessibleDescription: "Open chess settings"; onClicked: root.currentView = "settings" }
ChessUi.SecondaryButton { text: "Help"; visible: !root.compactLayout && root.currentView !== "help"; accessibleDescription: "Open chess controls and help"; onClicked: root.currentView = "help" }
ChessUi.SecondaryButton { Layout.preferredWidth: 88; text: "Close"; accessibleDescription: "Close and safely pause Omarchy Chess"; onClicked: root.requestClose() }
}
ChessUi.StatusBanner {
Layout.fillWidth: true
visible: root.payloadNotice !== "" || root.actionNotice !== ""
|| root.game.persistence_healthy === false || root.aiError
text: root.aiError ? "The computer could not finish its move"
: root.game.persistence_healthy === false ? "Your game could not be saved"
: root.payloadNotice || root.actionNotice
detail: root.aiError
? (root.gameClockEnabled
? "The clock is paused and your game is safe. Retry, use an easier level, or continue as a local game."
: "Your untimed game is safe. Retry, use an easier level, or continue as a local game.")
: root.game.persistence_healthy === false ? "The game is paused and safe in memory. Retry saving before continuing." : ""
kind: root.game.persistence_healthy === false || root.aiError ? "error" : "info"
iconText: root.game.persistence_healthy === false || root.aiError ? "!" : "i"
}
Loader {
id: contentLoader
Layout.fillWidth: true
Layout.fillHeight: true
sourceComponent: root.currentView === "game" ? gameComponent
: root.currentView === "history" ? historyComponent
: root.currentView === "replay" ? replayComponent
: root.currentView === "help" ? helpComponent
: root.currentView === "settings" ? settingsComponent : homeComponent
}
RowLayout {
Layout.fillWidth: true
spacing: 12
Text {
Layout.fillWidth: true
text: root.currentView === "game" ? "Arrows/HJKL move · Enter selects · F flips · U undo · P pause · ? help" : root.currentView === "home" ? "Offline by design · No account required" : "Fully offline · Native QML · Games stay on this device"
color: Color.muted
font.pixelSize: 11
elide: Text.ElideRight
}
Text {
text: root.service && root.service.persistenceBusy ? "Saving…" : root.game.persistence_healthy === false ? "Save needs attention" : "Saved locally"
color: root.game.persistence_healthy === false ? Color.urgent : Color.muted
font.pixelSize: 11
}
}
}
}
Item {
id: keyCatcher
anchors.fill: parent
focus: true
z: -1
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Escape) {
root.handleEscape(); event.accepted = true
} else if (event.key === Qt.Key_F1 || event.key === Qt.Key_Question) {
root.currentView = "help"; event.accepted = true
} else if (root.currentView === "game" && !root.modalOpen) {
if (event.key === Qt.Key_F) { root.flipBoard(); event.accepted = true }
else if (event.key === Qt.Key_U) { root.openConfirmation("undo"); event.accepted = true }
else if (event.key === Qt.Key_P) {
if (root.gameStatus === "paused") root.invoke(root.service.resumeGame())
else if (root.hasPlayableGame) root.invoke(root.pauseCurrentGame("user"))
event.accepted = true
} else if (event.key === Qt.Key_D) { root.drawActionsOpen = !root.drawActionsOpen; event.accepted = true }
else if (event.key === Qt.Key_R && (event.modifiers & Qt.ControlModifier)) { root.openConfirmation("resign"); event.accepted = true }
else if (event.key === Qt.Key_N) { root.openNewGameDialog(root.game.mode || "computer", ({})); event.accepted = true }
} else if (root.currentView === "replay" && !root.modalOpen) {
if (event.key === Qt.Key_Left) { root.replayStep(-1); event.accepted = true }
else if (event.key === Qt.Key_Right) { root.replayStep(1); event.accepted = true }
else if (event.key === Qt.Key_Home) { root.replayPly = 0; event.accepted = true }
else if (event.key === Qt.Key_End && root.replayData) { root.replayPly = root.replayData.frames.length - 1; event.accepted = true }
else if (event.key === Qt.Key_F) { root.replayOrientation = root.replayOrientation === "white" ? "black" : "white"; event.accepted = true }
else if (event.key === Qt.Key_C) { root.invoke(root.service.copyPgn(root.replayData.record.game_id), "PGN copied."); event.accepted = true }
}
}
}
ChessUi.NewGameDialog {
id: newGameDialog
anchors.fill: parent
z: 20
opened: false
onStartRequested: function(options) { root.beginGame(options) }
onCanceled: {
opened = false
Qt.callLater(root.focusCurrentView)
}
}
ChessUi.PromotionDialog {
id: promotionDialog
anchors.fill: parent
z: 22
opened: root.gameStatus === "promotion-pending"
moverColor: root.game.pending_promotion ? root.game.pending_promotion.side
: (root.game.turn || "white")
fromSquare: root.game.pending_promotion ? root.game.pending_promotion.from : ""
toSquare: root.game.pending_promotion ? root.game.pending_promotion.to : ""
onChosen: function(piece) {
if (root.invoke(root.service.choosePromotion(piece))) root.clearSelection()
Qt.callLater(root.focusCurrentView)
}
onCanceled: root.actionNotice = "Choose a piece to complete the promotion."
}
ChessUi.ConfirmDialog {
id: confirmDialog
anchors.fill: parent
z: 24
opened: false
title: "Confirm action"
message: ""
confirmText: "Confirm"
cancelText: "Cancel"
destructive: false
onConfirmed: {
root.performConfirmedAction()
Qt.callLater(root.focusCurrentView)
}
onCanceled: {
opened = false
root.pendingNewGameOptions = null
root.confirmAction = ""
Qt.callLater(root.focusCurrentView)
}
}
}
}
Component {
id: homeComponent
ChessUi.HomeView {
hasPlayableGame: root.hasPlayableGame
compactLayout: root.compactLayout
game: root.game
historyCount: root.service && root.service.historySummary
? Number(root.service.historySummary.total || 0) : 0
onResumeRequested: {
if (root.gameStatus === "paused") root.invoke(root.service.resumeGame())
root.currentView = "game"
Qt.callLater(root.focusCurrentView)
}
onComputerGameRequested: root.openNewGameDialog("computer", ({}))
onLocalGameRequested: root.openNewGameDialog("local", ({}))
onHistoryRequested: root.currentView = "history"
onSettingsRequested: root.currentView = "settings"
onHelpRequested: root.currentView = "help"
}
}
Component {
id: gameComponent
Item {
id: gameView
function syncResponsiveMetrics() {
var board = root.sideBySideGameLayout ? wideBoardView : compactBoardView
var rail = root.sideBySideGameLayout ? wideRailLoader : compactRailLoader
root.measuredGameViewportWidth = width
root.measuredGameViewportHeight = height
root.measuredBoardSize = board.boardSize
root.measuredRailHeight = rail.height
root.measuredRailImplicitHeight = rail.implicitHeight
}
Component.onCompleted: Qt.callLater(syncResponsiveMetrics)
onWidthChanged: Qt.callLater(syncResponsiveMetrics)
onHeightChanged: Qt.callLater(syncResponsiveMetrics)
function focusBoard() {
if (root.sideBySideGameLayout) wideBoardView.forceActiveFocus()
else compactBoardView.forceActiveFocus()
}
Connections {
target: root
function onGameFocusRequested() { gameView.focusBoard() }
}
RowLayout {
anchors.fill: parent; spacing: 16; visible: root.sideBySideGameLayout
Item {
Layout.fillWidth: true
Layout.fillHeight: true
ChessUi.BoardView {
id: wideBoardView
anchors.centerIn: parent
width: Math.max(0, Math.floor(Math.min(parent.width, parent.height) / 8) * 8)
height: width
pieces: root.game.board || []; orientation: root.boardOrientation; selectedSquare: root.selectedSquare; cursorSquare: root.cursorSquare; legalMoves: root.legalTargets; lastMove: root.latestMove; checkedKingSquare: root.checkedKingSquare; inputEnabled: root.gameInputEnabled
boardTheme: root.boardTheme
showLegalMoves: root.showLegalMoveHints
reducedMotion: root.service && root.service.settingsSnapshot.accessibility ? root.service.settingsSnapshot.accessibility.reduced_motion : false
highContrast: root.service && root.service.settingsSnapshot.accessibility ? root.service.settingsSnapshot.accessibility.high_contrast_indicators : false
showCoordinates: !root.service || !root.service.settingsSnapshot.appearance || root.service.settingsSnapshot.appearance.coordinates !== false
onSquareActivated: function(square) { root.activateSquare(square) }
onMoveRequested: function(from, to) { root.requestBoardMove(from, to) }
onPromotionRequested: function(from, to) { root.requestBoardMove(from, to) }
onFlipRequested: root.flipBoard()
onCursorMoved: function(square) { root.cursorSquare = square }
onCancelRequested: root.clearSelection()
onBoardSizeChanged: Qt.callLater(gameView.syncResponsiveMetrics)
}
}
Loader {
id: wideRailLoader
Layout.preferredWidth: root.mediumLayout ? 252 : 292
Layout.fillHeight: true
sourceComponent: railComponent
onHeightChanged: Qt.callLater(gameView.syncResponsiveMetrics)
onImplicitHeightChanged: Qt.callLater(gameView.syncResponsiveMetrics)
}
}
ColumnLayout {
anchors.fill: parent; spacing: 12; visible: !root.sideBySideGameLayout
ChessUi.BoardView {
id: compactBoardView
readonly property real compactRailHeight: Math.max(210,
compactRailLoader.implicitHeight)
Layout.fillWidth: true
Layout.minimumHeight: 0
Layout.preferredHeight: Math.min(width,
Math.max(0, parent.height - compactRailHeight - 12))
Layout.maximumHeight: Layout.preferredHeight
pieces: root.game.board || []; orientation: root.boardOrientation; selectedSquare: root.selectedSquare; cursorSquare: root.cursorSquare; legalMoves: root.legalTargets; lastMove: root.latestMove; checkedKingSquare: root.checkedKingSquare; inputEnabled: root.gameInputEnabled
boardTheme: root.boardTheme
showLegalMoves: root.showLegalMoveHints
reducedMotion: root.service && root.service.settingsSnapshot.accessibility ? root.service.settingsSnapshot.accessibility.reduced_motion : false
highContrast: root.service && root.service.settingsSnapshot.accessibility ? root.service.settingsSnapshot.accessibility.high_contrast_indicators : false
showCoordinates: !root.service || !root.service.settingsSnapshot.appearance || root.service.settingsSnapshot.appearance.coordinates !== false
onSquareActivated: function(square) { root.activateSquare(square) }
onMoveRequested: function(from, to) { root.requestBoardMove(from, to) }
onPromotionRequested: function(from, to) { root.requestBoardMove(from, to) }
onFlipRequested: root.flipBoard()
onCursorMoved: function(square) { root.cursorSquare = square }
onCancelRequested: root.clearSelection()
onBoardSizeChanged: Qt.callLater(gameView.syncResponsiveMetrics)
}
Loader {
id: compactRailLoader
Layout.fillWidth: true
Layout.minimumHeight: Math.max(210, implicitHeight)
Layout.preferredHeight: Layout.minimumHeight
Layout.maximumHeight: Layout.minimumHeight
sourceComponent: railComponent
onHeightChanged: Qt.callLater(gameView.syncResponsiveMetrics)
onImplicitHeightChanged: Qt.callLater(gameView.syncResponsiveMetrics)
}
}
}
}
Component {
id: railComponent
Rectangle {
implicitHeight: railContent.implicitHeight + 28
radius: 14
color: Qt.rgba(Color.foreground.r, Color.foreground.g, Color.foreground.b, 0.045)
border.width: 1
border.color: Qt.rgba(Color.foreground.r, Color.foreground.g, Color.foreground.b, 0.12)
clip: true
ColumnLayout {
id: railContent
anchors.fill: parent; anchors.margins: 14; spacing: 9
RowLayout {
Layout.fillWidth: true
visible: root.compactLayout
spacing: 12
RowLayout {
Layout.fillWidth: true
Text {
Layout.fillWidth: true
text: root.game.players
? root.game.players[root.boardOrientation === "white" ? "black" : "white"].name
: "Opponent"
textFormat: Text.PlainText
color: Color.foreground
font.pixelSize: 15
font.weight: Font.Medium
elide: Text.ElideRight
}
ChessUi.PlayerClock {
Layout.preferredWidth: Style.space(152)
side: root.boardOrientation === "white" ? "black" : "white"
remainingMs: root.game.clock && root.game.clock.enabled ? root.game.clock[(root.boardOrientation === "white" ? "black" : "white") + "_ms"] : -1
running: root.game.clock && !root.game.clock.paused && root.game.clock.running_side === side
paused: !root.game.clock || root.game.clock.paused === true
clockEnabled: root.game.clock && root.game.clock.enabled === true
}
}
RowLayout {
Layout.fillWidth: true
Text {
Layout.fillWidth: true
text: root.game.players ? root.game.players[root.boardOrientation].name : "Player"
textFormat: Text.PlainText
color: Color.foreground
font.pixelSize: 15
font.weight: Font.Medium
elide: Text.ElideRight
}
ChessUi.PlayerClock {
Layout.preferredWidth: Style.space(152)
side: root.boardOrientation
remainingMs: root.game.clock && root.game.clock.enabled ? root.game.clock[root.boardOrientation + "_ms"] : -1
running: root.game.clock && !root.game.clock.paused && root.game.clock.running_side === side
paused: !root.game.clock || root.game.clock.paused === true
clockEnabled: root.game.clock && root.game.clock.enabled === true
}
}
}
RowLayout {
Layout.fillWidth: true
visible: !root.compactLayout
Text { Layout.fillWidth: true; text: root.game.players ? root.game.players[root.boardOrientation === "white" ? "black" : "white"].name : "Opponent"; textFormat: Text.PlainText; color: Color.foreground; font.pixelSize: 15; font.weight: Font.Medium; elide: Text.ElideRight }
ChessUi.PlayerClock {
side: root.boardOrientation === "white" ? "black" : "white"
remainingMs: root.game.clock && root.game.clock.enabled ? root.game.clock[(root.boardOrientation === "white" ? "black" : "white") + "_ms"] : -1