-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.ml
585 lines (529 loc) · 23 KB
/
gui.ml
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
(*Module written as a dummy for running the GUI separately*)
module FormatOps = struct
type cardsfile = Yojson.Basic.json
let rec wordlist (x:string) =
if String.length x = 0 then [] else
if String.contains x ' ' then
let currindex = (String.index x ' ') in
let remainingstring = String.sub x (currindex + 1)
(String.length x - (currindex + 1)) in
String.sub x 0 currindex::wordlist remainingstring
else x::[]
let break_line (x: string) (break: int) =
let rec recompose (acc: string) (l: string list) (break: int) =
match l with
| [] -> acc
| hd::tl ->
if String.length (acc^hd) < break
then recompose (acc^hd^" ") tl break
else acc^"\n"^(recompose (hd^" ") tl break)
in
let ls = wordlist x in
recompose "" ls break
let get_deck (x: string) =
let open Yojson.Basic.Util in
let try_deck = try Some (Yojson.Basic.from_file x) with
_ -> None in
let deck = match try_deck with
| None -> print_string "error in deck"; exit 0
| Some d -> d in
[deck] |> flatten |> filter_member "text" |> filter_string
let get_random x =
let r = Random.int ((List.length x)) in
let rec rand_acc x n =
if n = 0 then
match x with
| [] -> "error_done"
| hd::tl -> hd
else
match x with
| [] -> "error_endearly"
| hd::tl -> rand_acc tl (n-1)
in rand_acc x r
let get_random_break x n =
break_line (get_random x) n
end
(*Open system files*)
open Client
open State
open RecurringCall
open Async.Std
let flush () = after(Core.Std.sec 0.)
(*GTK Initializations*)
let locale () = GtkMain.Main.init ()
let destroy () = GMain.Main.quit ()
(*Global references to decks, hands, etc*)
let score_visible = ref None
let about_visible = ref None
let expansion_enabled = ref false
let judging_mode = ref false
(*let init_state = ref (client_get_user_state ())*)
let (curr_user_state: State.univ_c_state option ref) = ref None
let player_hand = ref None
let submissions = ref None
let gamelog = GText.buffer ()
let winner_log = ref None
let format_scores () =
let rec format_list l =
match l with
| (u,s)::tl -> (string_of_int u)^": "
^(string_of_int s)^"\n"^(format_list tl)
| [] -> "" in
match !curr_user_state with
| None -> "Error: invalid data"
| Some s -> format_list (s.scores)
let rec find_idx n l =
match l with
| [] -> ""
| hd::tl -> if n = 1 then hd else find_idx (n-1) tl
let get_current_score () =
match !curr_user_state with
| None -> "0"
| Some s ->
let find_score n l =
List.fold_left
(fun score (id, s) -> if n = id then s + score else score) 0 l
in
string_of_int (find_score (Client.current_id ()) s.scores)
let rec get_submissions x =
match !submissions with
| None -> "Waiting on submissions"
| Some ls ->
find_idx x (List.map snd ls)
let rec get_hand_num x l =
match l with
| None -> "Waiting on server"
| Some hand ->
FormatOps.break_line (find_idx x (hand)) 22
let rec get_submit_num x l =
match l with
| None -> "Waiting on server"
| Some hand -> (find_idx x (hand))
let submit_hand_num n =
get_submit_num n !player_hand
let submit_judge_num n =
get_submissions n
let get_curr_bl () =
match !curr_user_state with
| None -> "Waiting on server"
| Some x -> x.b_card
let get_winners () =
let score_string = ref "" in
let rec generate_string l =
match l with
| [] -> !score_string
| (bc, wc, _)::tl ->
bc^"\n-->"^wc^"\n\n"^
(generate_string tl) in
match !winner_log with
| None -> gamelog#set_text "No winners yet!"
| Some s ->
let log = generate_string s in
gamelog#set_text log
(*Options window, currently only contains one option*)
(*let options_window () =
let option_window = GWindow.window ~title:"Options" ~resizable:false
~border_width:5 () in
let myclose _ = option_window#destroy() in
ignore(option_window#connect#destroy ~callback:(myclose));
let vbox = GPack.vbox ~spacing:5 ~packing:option_window#add () in
let info = GMisc.label ~line_wrap:true
(*~text:"Enable/disable expansion pack. Warning: This will reset your
current game and all data will be lost."*) ~packing:vbox#add () in
let checkbox = GButton.check_button ~active:(!expansion_enabled)
~packing:vbox#add () in
let confirm = GButton.button ~packing:vbox#add ~label:"Confirm!"() in
info#set_text("Enable/disable expansion packs. Warning: This will reset your
current game and all data will be lost.");
checkbox#set_label("Use expansion packs!");
let update_expansion () = expansion_enabled:= (checkbox#active) in
ignore(confirm#connect#clicked(update_expansion));
ignore(confirm#connect#clicked(myclose));
option_window#show ()*)
(*About screen - includes image, about text*)
let about_screen () =
match !about_visible with
|None ->
let icon = GdkPixbuf.from_file "res/icon.png" in
let about = GWindow.window ~title:"About" ~resizable:false
~border_width:5 () in
about#set_icon (Some icon);
let myclose _ = about_visible:=None;about#destroy () in
ignore(about#connect#destroy(myclose));
let vbox = GPack.vbox ~packing:about#add() in
let logo = GdkPixbuf.from_file "res/cards.png" in
let logo_widget = GMisc.image ~pixbuf:logo ~packing:vbox#add () in
logo_widget#set_pixbuf logo;
let aboutlabel = GMisc.label ~line_wrap:true ~packing:vbox#add
~justify:`CENTER() in
aboutlabel#set_text("1.0.1r12045\n\nCharley Chen\nMatthew Li\nAustin Liu
Jared Wong\n
Some code borrowed from the open-source lablgtk2 libraries.\n
2015. All rights reserved.");
let okbutton = GButton.button ~packing:vbox#add () in
okbutton#set_label("Close");
ignore(okbutton#connect#clicked(myclose));
about_visible:= Some about;
about#show ()
|Some s -> ()
(*Score screen popup - includes current scores, and a list of winning cards,
*black cards, and the players who won the cards*)
let score_dialog () =
let icon = GdkPixbuf.from_file "res/icon.png" in
let score = GWindow.window ~title:"Winning Cards" ~resizable:true
~border_width:5 ~height:600 ~width: 270 () in
score#set_icon(Some icon);
score_visible:= Some score;
let myclose _ =score_visible:=None;score#destroy() in
ignore(score#connect#destroy(myclose));
let mainbox = GBin.scrolled_window ~packing:score#add () in
get_winners();
let winnerstext = GText.view ~buffer:gamelog
~justification:`FILL ~packing:mainbox#add ~cursor_visible:false
~wrap_mode:`WORD () in
winnerstext#set_editable(false);
(*Sets values of scores and items - use to integrate scoring and winning cards*)
(*scores_list#set_text(get_scores ());*)
score#show ()
let main_window () =
ignore(locale ());
let icon = GdkPixbuf.from_file "res/icon.png" in
let window = GWindow.window
~resizable:false ~border_width:0 ~title:"Cards Against OCaml"() in
window#set_icon(Some icon);
let main_destroy _ = destroy();ignore(exit 0);() in
ignore(window#connect#destroy(main_destroy));
let menubox = GPack.vbox ~packing:window#add () in
let menubar = GMenu.menu_bar ~packing:menubox#pack() in
let hbox = GPack.hbox ~packing:(menubox#pack ~padding:50) () in
let windowbox = GPack.vbox ~packing:(hbox#pack ~padding:50) () in
let hbox_top = GPack.hbox ~packing:(windowbox#pack ~padding:0) () in
let current_mode = GMisc.label ~packing:(hbox_top#pack ~padding:5) () in
let logo = GdkPixbuf.from_file "res/logo.png" in
let logo_widget = GMisc.image ~pixbuf:logo ~packing:hbox_top#add () in
logo_widget#set_pixbuf logo;
(*let opt_menu = GMenu.menu () in
let opt_button = GMenu.menu_item ~label:("More settings")
~packing:opt_menu#append () in
ignore(opt_button#connect#activate(options_window));
let menu_opts = GMenu.menu_item ~label:"Options"
~packing:menubar#append () in
menu_opts#set_submenu (opt_menu);*)
let about_menu = GMenu.menu () in
let about_button = GMenu.menu_item ~label:("About")
~packing:about_menu#append () in
ignore(about_button#connect#activate ~callback:about_screen);
let exit_button = GMenu.menu_item ~label:("Exit")
~packing:about_menu #append () in
ignore(exit_button#connect#activate ~callback:destroy);
let menu_about = GMenu.menu_item ~label:"About" ~packing:menubar#append() in
menu_about#set_submenu(about_menu);
let bcbox = GPack.hbox ~packing:(windowbox#pack ~padding:10) () in
let mhbox = GPack.vbox ~packing:(windowbox#pack ~padding:0) () in
let timerframe = GBin.frame ~packing:(bcbox#pack ~padding:5)
~label: "Timer:" ~width: 70 ~height:70 () in
let timer = GMisc.label ~packing:(timerframe#add) () in
let bcframe = GBin.frame ~packing:(bcbox#pack ~padding:50)
~label:"Current Black Card" ~width:540 ~height:95 () in
let scoreframe = GBin.frame ~packing:(bcbox#pack ~padding:5)
~label: "Score:" ~width:70 ~height:70 () in
let show_score = GButton.button ~packing:(hbox_top#pack ~padding:5)
~label:("Show scores") () in
let score_dialog_opt () =
match !score_visible with
|None -> score_dialog ()
|Some window -> window#destroy () in
ignore(show_score#connect#clicked(score_dialog_opt));
let score = GMisc.label ~packing:(scoreframe#add) () in
let cbox1 = GPack.hbox ~packing:(mhbox#pack ~padding:0) () in
let cbox2 = GPack.hbox ~packing:(mhbox#pack ~padding:0) () in
let card1box = GPack.vbox ~packing:(cbox1#pack ~padding:0) () in
let card2box = GPack.vbox ~packing:(cbox1#pack ~padding:0) () in
let card3box = GPack.vbox ~packing:(cbox1#pack ~padding:0) () in
let card4box = GPack.vbox ~packing:(cbox1#pack ~padding:0) () in
let card5box = GPack.vbox ~packing:(cbox1#pack ~padding:0) () in
let card6box = GPack.vbox ~packing:(cbox2#pack ~padding:0) () in
let card7box = GPack.vbox ~packing:(cbox2#pack ~padding:0) () in
let card8box = GPack.vbox ~packing:(cbox2#pack ~padding:0) () in
let card9box = GPack.vbox ~packing:(cbox2#pack ~padding:0) () in
let card10box = GPack.vbox ~packing:(cbox2#pack ~padding:0) () in
let card1frame = GBin.frame ~packing:(card1box#pack ~padding:0)
~width:160 ~height:160 () in
let card2frame = GBin.frame ~packing:(card2box#pack ~padding:0)
~width:160 ~height:160 () in
let card3frame = GBin.frame ~packing:(card3box#pack ~padding:0)
~width:160 ~height:160 () in
let card4frame = GBin.frame ~packing:(card4box#pack ~padding:0)
~width:160 ~height:160 () in
let card5frame = GBin.frame ~packing:(card5box#pack ~padding:0)
~width:160 ~height:160 () in
let card6frame = GBin.frame ~packing:(card6box#pack ~padding:0)
~width:160 ~height:160 () in
let card7frame = GBin.frame ~packing:(card7box#pack ~padding:0)
~width:160 ~height:160 () in
let card8frame = GBin.frame ~packing:(card8box#pack ~padding:0)
~width:160 ~height:160 () in
let card9frame = GBin.frame ~packing:(card9box#pack ~padding:0)
~width:160 ~height:160 () in
let card10frame = GBin.frame ~packing:(card10box#pack ~padding:0)
~width:160 ~height:160 () in
let btext = "Waiting on server" in
let bcard = GMisc.label ~packing:bcframe#add ~line_wrap:true () in
let card1 = GButton.button ~label:btext
~packing:(card1frame#add) ~relief:`NONE () in
card1#set_focus_on_click(false);
let card2 = GButton.button ~label:btext
~packing:(card2frame#add) ~relief:`NONE () in
card2#set_focus_on_click(false);
let card3 = GButton.button ~label:btext
~packing:(card3frame#add) ~relief:`NONE () in
card3#set_focus_on_click(false);
let card4 = GButton.button ~label:btext
~packing:(card4frame#add) ~relief:`NONE () in
card4#set_focus_on_click(false);
let card5 = GButton.button ~label:btext
~packing:(card5frame#add) ~relief:`NONE () in
card5#set_focus_on_click(false);
let card6 = GButton.button ~label:btext
~packing:(card6frame#add) ~relief:`NONE () in
card6#set_focus_on_click(false);
let card7 = GButton.button ~label:btext
~packing:(card7frame#add) ~relief:`NONE () in
card7#set_focus_on_click(false);
let card8 = GButton.button ~label:btext
~packing:(card8frame#add) ~relief:`NONE () in
card8#set_focus_on_click(false);
let card9 = GButton.button ~label:btext
~packing:(card9frame#add) ~relief:`NONE () in
card9#set_focus_on_click(false);
let card10 = GButton.button ~label:btext
~packing:(card10frame#add) ~relief:`NONE() in
card10#set_focus_on_click(false);
(*Code for initialization, can be modified to take data from the server
*when this is fully implemented.*)
(*Universal Callbacks: Methods for updating score, updating timer -
*bound to every button currently, primarily for debug. Can be modified*)
let update_gui_func () =
upon (client_get_user_state ()) (fun curr_state ->
match curr_state with
| Playing st->
judging_mode:=false;
curr_user_state:= Some st;
player_hand:= Some st.hand;
winner_log:=Some st.winners;
get_winners();
let h = Some st.hand in
card1#set_label(get_hand_num 1 h);
card2#set_label(get_hand_num 2 h);
card3#set_label(get_hand_num 3 h);
card4#set_label(get_hand_num 4 h);
card5#set_label(get_hand_num 5 h);
card6#set_label(get_hand_num 6 h);
card7#set_label(get_hand_num 7 h);
card8#set_label(get_hand_num 8 h);
card9#set_label(get_hand_num 9 h);
card10#set_label(get_hand_num 10 h);
current_mode#set_label("Pick the best card!");
bcard#set_label(st.b_card);
score#set_label(get_current_score())
| Judging st ->
judging_mode:=true;
curr_user_state:= Some st;
submissions:= Some st.played;
winner_log:=Some st.winners;
get_winners();
card1#set_label(FormatOps.break_line (get_submissions 1) 22);
card2#set_label(FormatOps.break_line (get_submissions 2) 22);
card3#set_label(FormatOps.break_line (get_submissions 3) 22);
card4#set_label(FormatOps.break_line (get_submissions 4) 22);
card5#set_label(FormatOps.break_line (get_submissions 5) 22);
card6#set_label(FormatOps.break_line (get_submissions 6) 22);
card7#set_label(FormatOps.break_line (get_submissions 7) 22);
card8#set_label(FormatOps.break_line (get_submissions 8) 22);
card9#set_label(FormatOps.break_line (get_submissions 9) 22);
card10#set_label(FormatOps.break_line (get_submissions 10) 22);
bcard#set_label (st.b_card);
score#set_label(get_current_score());
current_mode#set_label("You are the Czar!")
| JWaiting st ->
judging_mode:=true;
curr_user_state:= Some st;
winner_log:= Some st.winners;
get_winners();
card1#set_label("Waiting for players");
card2#set_label("Waiting for players");
card3#set_label("Waiting for players");
card4#set_label("Waiting for players");
card5#set_label("Waiting for players");
card6#set_label("Waiting for players");
card7#set_label("Waiting for players");
card8#set_label("Waiting for players");
card9#set_label("Waiting for players");
card10#set_label("Waiting for players");
bcard#set_label("Waiting for players");
current_mode#set_label("You are the Czar!");
score#set_label(get_current_score())
| PWaiting st ->
judging_mode:=false;
curr_user_state:= Some st;
winner_log:= Some st.winners;
card1#set_label("Waiting for czar");
card2#set_label("Waiting for czar");
card3#set_label("Waiting for czar");
card4#set_label("Waiting for czar");
card5#set_label("Waiting for czar");
card6#set_label("Waiting for czar");
card7#set_label("Waiting for czar");
card8#set_label("Waiting for czar");
card9#set_label("Waiting for czar");
card10#set_label("Waiting for czar");
bcard#set_label("Waiting for czar");
current_mode#set_label("Pick the best card!"));
score#set_label(get_current_score())
in
let gui_update_call = RecurringCall.create_call 1.0 update_gui_func in
RecurringCall.start_call gui_update_call;
let timer_update_call = RecurringCall.create_call 0.2
(fun () -> timer#set_label(string_of_int (Client.get_time ())))
in
RecurringCall.start_call timer_update_call;
let update_gui () = RecurringCall.start_call gui_update_call in
(*Callbacks: Here is where the callbacks are assigned for each
*of the 10 buttons in the main interface of the GUI. When connecting
*to the server, each of the 10 buttons' callbacks can be used to call
*functions which deal with card data from the server. In the dummy,
*all callbacks are identical. Later, each button can be assigned to
*additional callbacks to transmit which card was selected to the server.*)
let callback1 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 1)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 1)) (fun () ->
update_gui()) in
let callback2 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 2)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 2)) (fun () ->
update_gui()) in
let callback3 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 3)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 3)) (fun () ->
update_gui()) in
let callback4 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 4)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 4)) (fun () ->
update_gui()) in
let callback5 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 5)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 5)) (fun () ->
update_gui())in
let callback6 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 6)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 6)) (fun () ->
update_gui()) in
let callback7 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 7)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 7)) (fun () ->
update_gui()) in
let callback8 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 8)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 8)) (fun () ->
update_gui()) in
let callback9 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 9)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 9)) (fun () ->
update_gui()) in
let callback10 () = bcard#set_label("Waiting for other players");
if !judging_mode = true
then (upon (client_judge (submit_judge_num 10)) (fun () -> update_gui ()))
else upon (client_play_white (submit_hand_num 10)) (fun () ->
update_gui()) in
ignore(window#connect#destroy ~callback:main_destroy);
ignore(card1#connect#clicked ~callback:callback1);
ignore(card2#connect#clicked ~callback:callback2);
ignore(card3#connect#clicked ~callback:callback3);
ignore(card4#connect#clicked ~callback:callback4);
ignore(card5#connect#clicked ~callback:callback5);
ignore(card6#connect#clicked ~callback:callback6);
ignore(card7#connect#clicked ~callback:callback7);
ignore(card8#connect#clicked ~callback:callback8);
ignore(card9#connect#clicked ~callback:callback9);
ignore(card10#connect#clicked ~callback:callback10);
window#show()
(*let confirm_exit () =
let icon = GdkPixbuf.from_file "res/icon.png" in
let conf = GWindow.window
~resizable:false ~border_width:0 ~title:"Leaving?" () in
conf#set_icon(Some icon);
let vbox = GPack.vbox ~packing:(conf#add) () in
let txt = GMisc.label ~packing:(vbox#add) () in
let hbox = GPack.hbox ~packing:(vbox#add) () in
let yes = GButton.button ~packing:(hbox#add) ~label:("Yes")() in
let no = GButton.button ~packing:(hbox#add) ~label:("No")() in
txt#set_label("Are you sure you want to leave?");
ignore(no#connect#clicked(fun () -> conf#destroy()));
ignore(yes#connect#clicked(fun () -> (destroy();ignore(exit 0);())));
conf#show()*)
let initial_window () =
let is_connected = ref false in
let is_started = ref false in
ignore(locale ());
let icon = GdkPixbuf.from_file "res/icon.png" in
let splash = GWindow.window
~resizable:false ~border_width:10 ~title:"Cards Against OCaml" () in
splash#set_icon(Some icon);
let main_destroy () = splash#destroy();
if !is_started then () else ignore(exit 0) in
(*ignore(splash#connect#destroy(main_destroy));*)
let vbox = GPack.vbox ~packing:(splash#add) () in
let logo = GdkPixbuf.from_file "res/cards.png" in
let logo_widget = GMisc.image ~pixbuf:logo ~packing:vbox#add () in
logo_widget#set_pixbuf logo;
let indicator = GMisc.label ~packing:(vbox#add) () in
indicator#set_label("Connect to server before starting game.");
let boxbuffer = GBin.frame ~packing:(vbox#pack ~padding:5)
~label:"Server address" () in
let server = GText.buffer () in
let server_box = GText.view ~packing:(boxbuffer#add) () in
server#set_text("http://localhost:8080");
server_box#set_buffer(server);
let connect_button = GButton.button ~label:("Click to connect to server!")
~packing:vbox#add () in
let start_button = GButton.button ~label:("Click to start!")
~packing:vbox#add () in
let init_start () =
is_started:=true;
upon (Client.trigger_start()) (fun () -> (main_window();main_destroy())) in
let init_connect () =
let server_input = server#get_text () in
let connect_attempt =
if !is_connected then None else
try Some (connect_server server_input "string") with
| _ -> None in
match connect_attempt with
| Some d -> is_connected:=true;
upon d (fun () ->
ignore(start_button#connect#clicked ~callback:init_start);
indicator#set_label("You are now connected!"));
server_box#set_editable(false)
| None ->
if !is_connected
then indicator#set_label("You are already connected. Click to start!")
else indicator#set_label("Error, could not connect. Try again!") in
let connect_first () =
indicator#set_label("Connect to server first!") in
ignore(connect_button#connect#clicked ~callback:init_connect);
ignore(start_button#connect#clicked ~callback:connect_first);
ignore(splash#connect#destroy(main_destroy));
splash#show(); ()
let main () =
initial_window ();
let _ = GtkThread.start () in
GtkThread.sync Scheduler.go ()
let _ = main ()