-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui-view.ss
executable file
·309 lines (266 loc) · 10.4 KB
/
gui-view.ss
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
#|
File : graphical view
Author : Wouter Van Rossem
|#
#!r6rs
(library
(gui-view)
(export gui-view%)
(import (rnrs base (6))
(rnrs io simple)
(rnrs control (6))
(scheme class)
(scheme gui base)
(rnrs mutable-pairs)
(prefix (only (scheme base) list cons null? null car cdr list-ref) s:)
(magicthegathering gui)
(magicthegathering controller)
(magicthegathering observer-pattern))
; Interface name: view
; Methods:
; - public:
; * display-message:
; arguments: message
; output : none
; description: display a message to the user
; * get-user-input:
; arguments: label
; output : none
; description: ask for input for a certain question (label)
; * get-user-choice:
; arguments: label, choice
; output: unspecified
; description: get a choice from a list of choices from the user
; * get-user-yes/no:
; arguments: title, message
; output : 'yes/'no
; description: get a user response to a certain question
; * get-user-answer:
; arguments: title, message, button1, button2, button3
; output : none
; description: get a choice between maximum 3 options from the user
; * choice-from-library:
; arguments: player, topx
; output : card%
; description: get a choice from the top x cards of target player's library
; * display-error:
; arguments: error-message
; output : none
; description: display an error-message to the user
; - private: none
(define view<%> (interface () display-message get-user-input get-user-choice get-user-yes/no display-error
get-user-answer choice-from-library))
; Class name: gui-view
; Superclass: subject%
; Description: Implements the view interface + handles model updates
; Attributes: - public: none
; - private: view, controller
; Methods:
; - public:
; * start-mtg:
; arguments: player1, player2, turn, mtg
; output : none
; description: start the gui view for mtg
; * initialize-hand:
; arguments: player
; output : none
; description: initialize the hand-panel of a player
; * clear-hand:
; arguments: player
; output: none
; description: clears the hand-panel of a player
; * update-library/gy/rfg-size
; arguments: player
; output : none
; description: update the size of a cardstack-panel
; * update-life:
; arguments: player
; output : none
; description: update the life-panel of a player
; * update-phase/step:
; arguments: none
; output : none
; description: update the phase or step panel
; * update-priority/active-player/nr-of-turns:
; arguments: none
; output : none
; description: update the "who has priority"/"active-player"/"nr-of-turns" message
; * add-card:
; arguments: zone, card, player
; output : none
; description: add a card-canvas to a zone of a player
; * remove-card:
; arguments: zone, card, player
; output : none
; description: remove a card-canvas from a zone of a player
; * tap-permanent:
; arguments: permanent, player
; output : none
; description: tap a cardcanvas of a player
; * untap-permanents:
; arguments: player
; output : none
; description: untap all card-canvases a player
; * update-mana:
; arguments: color, player
; output : none
; description: update the mana of a color of a player
; * update-all-mana:
; arguments: player
; output : none
; description: update the whole mana-pool panel of a player
; * announce-spell:
; arguments: zone, card, player
; output : none
; description: send the announce spell frame to start
; * update-announced-spell-mana:
; arguments: none
; output : none
; description: update the mana to spend from the announce spell frame
; * update-announced-spell-state:
; arguments: state
; output : none
; description: change the state of the announce spell frame
; * announced-spell-done:
; arguments: none
; output : none
; description: send the announce spell frame it is done
; * add-stack-spell:
; arguments: stack-spell
; output : none
; description: add a new spell to the stack frame
; * remove-top-of-stack:
; arguments: none
; output : none
; description: remove the top of the stack frame
; * set-attacking/blocking:
; arguments: creature, owner
; output : none
; description: set a cardcanvas to attack or block
; * remove-attacking/blocking:
; arguments: creature, owner
; output : none
; description: set a cardcanvas to stop attacking or blocking
; - private: none
(define gui-view%
(class* subject% (view<%>)
(super-new (name 'gui-view))
(inherit attach detach notify)
(define view (new frame% (label "Main") (width 500) (height 200)))
(define controller 0)
(send view show #t)
; ( player% player% turn% mtg% -> )
(define/public (start-mtg player1 player2 turn mtg)
(send view show #f)
(set! controller
(new controller% (model mtg) (view this)))
(set! view
(new mtg-frame% (player1 player1) (player2 player2) (turn turn) (controller controller) (mtg mtg)))
(send view show #t))
; ( string -> )
(define/public (display-message message)
(message-box "" message))
; ( string -> string )
(define/public (get-user-input label)
(get-text-from-user label label view))
; ( string pair -> unspecified)
(define/public (get-user-choice label choices)
(let ((choice (get-choices-from-user label label choices view)))
(if choice
(s:list-ref choices (s:car choice))
#f)))
; ( string string -> symbol )
(define/public (get-user-yes/no title message)
(message-box title message view (s:list 'yes-no)))
; ( string string string string string -> symbol )
(define/public (get-user-answer title message button1 button2 button3)
(message-box/custom title message button1 button2 button3 view))
; ( string -> )
(define/public (display-error error-message)
(bell)
(message-box "Error" error-message))
; ( player% number -> card% )
(define/public (choice-from-library player top-x)
(send view choice-from-library player top-x))
; ********** MODEL UPDATES ***************
; ( player% -> )
(define/public (initialize-hand player)
(send view initialize-hand player))
; ( player% -> )
(define/public (clear-hand player)
(send view clear-hand player))
; ( player% -> )
(define/public (update-library-size player)
(send view update-library-size player))
; ( player% -> )
(define/public (update-graveyard-size player)
(send view update-graveyard-size player))
; ( player% -> )
(define/public (update-rfg-size player)
(send view update-rfg-size player))
; ( player% -> )
(define/public (update-life player)
(send view update-life player))
; ( -> )
(define/public (update-phase)
(send view update-phase))
; ( -> )
(define/public (update-step)
(send view update-step))
; ( -> )
(define/public (update-priority)
(send view update-priority))
; ( -> )
(define/public (update-active-player)
(send view update-active-player))
; ( -> )
(define/public (update-nr-of-turns)
(send view update-nr-of-turns))
; ( symbol card% player% -> )
(define/public (add-card zone card player)
(send view add-card zone card player))
; ( symbol card% player% -> )
(define/public (remove-card zone card player)
(send view remove-card zone card player))
; ( permanent% player% -> )
(define/public (tap-permanent permanent player)
(send view tap-permanent permanent player))
; ( player% -> )
(define/public (untap-permanents player)
(send view untap-permanents player))
; ( symbol player% -> )
(define/public (update-mana color player)
(send view update-mana color player))
; ( player% -> )
(define/public (update-all-mana player)
(send view update-all-mana player))
; ( stack-spell/abi% -> )
(define/public (announce-spell stack-spell)
(send view announce-spell stack-spell))
; ( -> )
(define/public (update-announced-spell-mana)
(send view update-announced-spell-mana))
; ( symbol -> )
(define/public (update-announced-spell-state state)
(send view update-announced-spell-state state))
; ( -> )
(define/public (announced-spell-done)
(send view announced-spell-done))
; ( stack-spell/abi% -> )
(define/public (add-stack-spell stack-spell)
(send view add-stack-spell stack-spell))
; ( -> )
(define/public (remove-top-of-stack)
(send view remove-top-of-stack))
; ( creature% player% -> )
(define/public (set-attacking creature owner)
(send view set-attacking creature owner))
; ( creature% player% -> )
(define/public (remove-attacking creature owner)
(send view remove-attacking creature owner))
; ( creature% player% -> )
(define/public (set-blocking creature owner)
(send view set-blocking creature owner))
; ( creature% player% -> )
(define/public (remove-blocking creature owner)
(send view remove-blocking creature owner)))))