summaryrefslogtreecommitdiffstats
path: root/kgoldrunner/src/kgoldrunner.cpp
blob: 01b9176f187bb10cb9a1fb91dafde2389d71a153 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
/*
 * Copyright (C) 2003 Ian Wadham and Marco Kr�ger <ianw2@optusnet.com.au>
 */

#include <kprinter.h>
#include <tqpainter.h>
#include <tqpaintdevicemetrics.h>

#include <kglobal.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kmenubar.h>
#include <kstatusbar.h>
#include <kkeydialog.h>
#include <kaccel.h>
#include <kio/netaccess.h>
#include <kfiledialog.h>
#include <kconfig.h>

#include <kedittoolbar.h>
#include <ktoolbar.h>

#include <kstdaccel.h>
#include <kaction.h>
#include <kstdaction.h>
#include <kstdgameaction.h>

#include "kgrconsts.h"
#include "kgrobject.h"
#include "kgrfigure.h"
#include "kgrcanvas.h"
#include "kgrdialog.h"
#include "kgrgame.h"
#include "kgoldrunner.h"

KGoldrunner::KGoldrunner()
    : KMainWindow (0, "KGoldrunner"),
      view (new KGrCanvas (this))
{
/******************************************************************************/
/*************  FIND WHERE THE GAMES DATA AND HANDBOOK SHOULD BE  *************/
/******************************************************************************/

    // Avoid "saveOK()" check if an error-exit occurs during the file checks.
    startupOK = TRUE;

    // Get directory paths for the system levels, user levels and manual.
    if (! getDirectories()) {
	fprintf (stderr, "getDirectories() FAILED\n");
	startupOK = FALSE;
	return;				// If games directory not found, abort.
    }

    // This message is to help diagnose distribution or installation problems.
    printf
    ("The games data and handbook should be in the following locations:\n");
    printf ("System games: %s\nUser data:    %s\nHandbook:     %s\n",
	systemDataDir.myStr(), userDataDir.myStr(), systemHTMLDir.myStr());

/******************************************************************************/
/************************  SET PLAYFIELD AND GAME DATA  ***********************/
/******************************************************************************/

    game = new KGrGame (view, systemDataDir, userDataDir);

    // Initialise the collections of levels (i.e. the list of games).
    if (! game->initCollections()) {
	startupOK = FALSE;
	return;				// If no game files, abort.
    }

    hero = game->getHero();		// Get a pointer to the hero.

/******************************************************************************/
/*************************  SET UP THE USER INTERFACE  ************************/
/******************************************************************************/

    // Get catalog for translation
    KGlobal::locale()->insertCatalogue("libkdegames");

    // Tell the KMainWindow that this is the main widget
    setCentralWidget (view);

    // Set up our actions (menu, toolbar and keystrokes) ...
    setupActions();

    // and a status bar.
    initStatusBar();

    // Connect the game actions to the menu and toolbar displays.
    connect(game, TQT_SIGNAL (setEditMenu (bool)),	TQT_SLOT (setEditMenu (bool)));
    connect(game, TQT_SIGNAL (markRuleType (char)), TQT_SLOT (markRuleType (char)));
    connect(game, TQT_SIGNAL (hintAvailable(bool)),	TQT_SLOT (adjustHintAction(bool)));
    connect(game, TQT_SIGNAL (defaultEditObj()),	TQT_SLOT (defaultEditObj()));

    // Apply the saved mainwindow settings, if any, and ask the mainwindow
    // to automatically save settings if changed: window size, toolbar
    // position, icon size, etc.
    setAutoSaveSettings();

#ifdef QT3
    // Base size of playing-area and widgets on the monitor resolution.
    int dw = KApplication::desktop()->width();
    if (dw > 800) {				// More than 800x600.
	view->changeSize (+1);		// Scale 1.25:1.
    }
    if (dw > 1024) {			// More than 1024x768.
	view->changeSize (+1);
	view->changeSize (+1);		// Scale 1.75:1.
	setUsesBigPixmaps (TRUE);	// Use big toolbar buttons.
    }
    view->setBaseScale();		// Set scale for level-names.
#endif
    setFixedSize (view->size());

    makeEditToolbar();			// Uses pixmaps from "view".
    editToolbar->hide();
    setDockEnabled (DockBottom, FALSE);
    setDockEnabled (DockLeft, FALSE);
    setDockEnabled (DockRight, FALSE);

    // Make it impossible to turn off the editor toolbar.
    // Accidentally hiding it would make editing impossible.
    setDockMenuEnabled (FALSE);

    // Set mouse control of the hero as the default.
    game->setMouseMode (TRUE);

    // Paint the main widget (title, menu, status bar, blank playfield).
    show();

    // Force the main widget to appear before the "Start Game" dialog does.
    tqApp->processEvents();

    // Call the "Start Game" function and pop up the "Start Game" dialog.
    game->startLevelOne();
}

KGoldrunner::~KGoldrunner()
{
    delete editToolbar;
}

void KGoldrunner::setupActions()
{
    /**************************************************************************/
    /******************************   GAME MENU  ******************************/
    /**************************************************************************/

    // New Game...
    // Load Saved Game...
    // Play Any Level...
    // Play Next Level...
    // Tutorial
    // --------------------------

    KAction * newAction =	KStdGameAction::
				gameNew (
				game,
				TQT_SLOT(startLevelOne()), actionCollection());
    newAction->			setText (i18n("&New Game..."));
    KAction * loadGame =	KStdGameAction::
				load (
				game, TQT_SLOT(loadGame()), actionCollection());
    loadGame->			setText (i18n("&Load Saved Game..."));
    (void)			new KAction (
				i18n("&Play Any Level..."),
				0,
				game, TQT_SLOT(startAnyLevel()), actionCollection(),
				"play_any");
    (void)			new KAction (
				i18n("Play &Next Level..."),
				0,
				game,
				TQT_SLOT(startNextLevel()), actionCollection(),
				"play_next");

    // Save Game...
    // Save Edits... (extra copy)
    // --------------------------

    saveGame =			KStdGameAction::
				save (
				game, TQT_SLOT(saveGame()), actionCollection());
    saveGame->			setText (i18n("&Save Game..."));
    saveGame->			setShortcut (Key_S); // Alternate key.

    // Pause
    // Show High Scores
    // Get a Hint
    // Kill the Hero
    // --------------------------

    myPause =			KStdGameAction::
				pause (
				TQT_TQOBJECT(this), TQT_SLOT(stopStart()), actionCollection());
    myPause->			setShortcut (Key_Escape); // Alternate key.
    highScore =			KStdGameAction::
				highscores (
				game, TQT_SLOT(showHighScores()), actionCollection());
    hintAction =		new KAction (
				i18n("&Get Hint"), "ktip",
				0,
				game, TQT_SLOT(showHint()), actionCollection(),
				"get_hint");
    killHero =			new KAction (
				i18n("&Kill Hero"),
				Key_Q,
				game, TQT_SLOT(herosDead()), actionCollection(),
				"kill_hero");

    // Quit
    // --------------------------

    (void)			KStdGameAction::
				quit (
				TQT_TQOBJECT(this), TQT_SLOT(close()), actionCollection());

    /**************************************************************************/
    /***************************   GAME EDITOR MENU  **************************/
    /**************************************************************************/

    // Create a Level
    // Edit Any Level...
    // Edit Next Level...
    // --------------------------

    (void)			new KAction (
				i18n("&Create Level"),
				0,
				TQT_TQOBJECT(game), TQT_SLOT(createLevel()), actionCollection(),
				"create");
    (void)			new KAction (
				i18n("&Edit Any Level..."),
				0,
				TQT_TQOBJECT(game), TQT_SLOT(updateLevel()), actionCollection(),
				"edit_any");
    (void)			new KAction (
				i18n("Edit &Next Level..."),
				0,
				TQT_TQOBJECT(game), TQT_SLOT(updateNext()), actionCollection(),
				"edit_next");

    // Save Edits...
    // Move Level...
    // Delete Level...
    // --------------------------

    saveEdits =			new KAction (
				i18n("&Save Edits..."),
				0,
				TQT_TQOBJECT(game), TQT_SLOT(saveLevelFile()), actionCollection(),
				"save_edits");
    saveEdits->setEnabled (FALSE);			// Nothing to save, yet.

    (void)			new KAction (
				i18n("&Move Level..."),
				0,
				TQT_TQOBJECT(game), TQT_SLOT(moveLevelFile()), actionCollection(),
				"move_level");
    (void)			new KAction (
				i18n("&Delete Level..."),
				0,
				TQT_TQOBJECT(game),
				TQT_SLOT(deleteLevelFile()), actionCollection(),
				"delete_level");

    // Create a Game
    // Edit Game Info...
    // --------------------------

    (void)			new KAction (
				i18n("Create Game..."),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(createGame()), actionCollection(),
				"create_game");
    (void)			new KAction (
				i18n("Edit Game Info..."),
				0,
				TQT_TQOBJECT(this),
				TQT_SLOT(editGameInfo()), actionCollection(),
				"edit_game");

    /**************************************************************************/
    /***************************   LANDSCAPES MENU  ***************************/
    /**************************************************************************/

    // Default shortcut keys are set by "kgoldrunnerui.rc".

    setKGoldrunner =		new KRadioAction (
				"K&Goldrunner",
				0,			// Default Shift+G
				TQT_TQOBJECT(this), TQT_SLOT(lsKGoldrunner()), actionCollection(),
				"kgoldrunner");
    setAppleII =		new KRadioAction (
				"&Apple II",
				0,			// Default Shift+A
				TQT_TQOBJECT(this), TQT_SLOT(lsApple2()), actionCollection(),
				"apple_2");
    setIceCave =		new KRadioAction (
				i18n("&Ice Cave"),
				0,			// Default Shift+I
				TQT_TQOBJECT(this), TQT_SLOT(lsIceCave()), actionCollection(),
				"ice_cave");
    setMidnight =		new KRadioAction (
				i18n("&Midnight"),
				0,			// Default Shift+M
				TQT_TQOBJECT(this), TQT_SLOT(lsMidnight()), actionCollection(),
				"midnight");
    setKDEKool =		new KRadioAction (
				i18n("&KDE Kool"),
				0,			// Default Shift+K
				TQT_TQOBJECT(this), TQT_SLOT(lsKDEKool()), actionCollection(),
				"kde_kool");

    setKGoldrunner->		setExclusiveGroup ("landscapes");
    setAppleII->		setExclusiveGroup ("landscapes");
    setIceCave->		setExclusiveGroup ("landscapes");
    setMidnight->		setExclusiveGroup ("landscapes");
    setKDEKool->		setExclusiveGroup ("landscapes");
    setKGoldrunner->		setChecked (TRUE);

    /**************************************************************************/
    /****************************   SETTINGS MENU  ****************************/
    /**************************************************************************/

    // Mouse Controls Hero
    // Keyboard Controls Hero
    // --------------------------

    setMouse =			new KRadioAction (
				i18n("&Mouse Controls Hero"),
				0,
				TQT_TQOBJECT(this),
				TQT_SLOT(setMouseMode()), actionCollection(),
				"mouse_mode");
    setKeyboard =		new KRadioAction (
				i18n("&Keyboard Controls Hero"),
				0,
				TQT_TQOBJECT(this),
				TQT_SLOT(setKeyBoardMode()), actionCollection(),
				"keyboard_mode");

    setMouse->			setExclusiveGroup ("control");
    setKeyboard->		setExclusiveGroup ("control");
    setMouse->			setChecked (TRUE);

    // Normal Speed
    // Beginner Speed
    // Champion Speed
    // Increase Speed
    // Decrease Speed
    // --------------------------

    KRadioAction * nSpeed =	new KRadioAction (
				i18n("Normal Speed"),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(normalSpeed()), actionCollection(),
				"normal_speed");
    KRadioAction * bSpeed =	new KRadioAction (
				i18n("Beginner Speed"),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(beginSpeed()), actionCollection(),
				"beginner_speed");
    KRadioAction * cSpeed =	new KRadioAction (
				i18n("Champion Speed"),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(champSpeed()), actionCollection(),
				"champion_speed");
    (void)			new KAction (		// Repeatable action.
				i18n("Increase Speed"),
				Key_Plus,
				TQT_TQOBJECT(this), TQT_SLOT(incSpeed()), actionCollection(),
				"increase_speed");
    (void)			new KAction (		// Repeatable action.
				i18n("Decrease Speed"),
				Key_Minus,
				TQT_TQOBJECT(this), TQT_SLOT(decSpeed()), actionCollection(),
				"decrease_speed");

    nSpeed->			setExclusiveGroup ("speed");
    bSpeed->			setExclusiveGroup ("speed");
    cSpeed->			setExclusiveGroup ("speed");
    nSpeed->			setChecked (TRUE);

    // Traditional Rules
    // KGoldrunner Rules
    // --------------------------

    tradRules =			new KRadioAction (
				i18n("&Traditional Rules"),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(setTradRules()), actionCollection(),
				"trad_rules");
    kgrRules =			new KRadioAction (
				i18n("K&Goldrunner Rules"),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(setKGrRules()), actionCollection(),
				"kgr_rules");

    tradRules->			setExclusiveGroup ("rules");
    kgrRules->			setExclusiveGroup ("rules");
    tradRules->			setChecked (TRUE);

    // Larger Playing Area
    // Smaller Playing Area
    // --------------------------

    (void)			new KAction (
				i18n("Larger Playing Area"),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(makeLarger()), actionCollection(),
				"larger_area");
    (void)			new KAction (
				i18n("Smaller Playing Area"),
				0,
				TQT_TQOBJECT(this), TQT_SLOT(makeSmaller()), actionCollection(),
				"smaller_area");

    // Configure Shortcuts...
    // Configure Toolbars...
    // --------------------------

    KStdAction::keyBindings (
				TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureKeys()),
				actionCollection());
    // KStdAction::configureToolbars (
				// this, TQT_SLOT(optionsConfigureToolbars()),
				// actionCollection());

    /**************************************************************************/
    /**************************   KEYSTROKE ACTIONS  **************************/
    /**************************************************************************/

    // Two-handed KB controls and alternate one-handed controls for the hero.

    (void)	new KAction (i18n("Move Up"), Key_Up,
		TQT_TQOBJECT(this), TQT_SLOT(goUp()), actionCollection(), "move_up");
    (void)	new KAction (i18n("Move Right"), Key_Right,
		TQT_TQOBJECT(this), TQT_SLOT(goR()), actionCollection(), "move_right");
    (void)	new KAction (i18n("Move Down"), Key_Down,
		TQT_TQOBJECT(this), TQT_SLOT(goDown()), actionCollection(), "move_down");
    (void)	new KAction (i18n("Move Left"), Key_Left,
		TQT_TQOBJECT(this), TQT_SLOT(goL()), actionCollection(), "move_left");
    (void)	new KAction (i18n("Stop"), Key_Space,
		TQT_TQOBJECT(this), TQT_SLOT(stop()), actionCollection(), "stop");
    (void)	new KAction (i18n("Dig Right"), Key_C,
		TQT_TQOBJECT(this), TQT_SLOT(digR()), actionCollection(), "dig_right");
    (void)	new KAction (i18n("Dig Left"), Key_Z,
		TQT_TQOBJECT(this), TQT_SLOT(digL()), actionCollection(), "dig_left");

    // Alternate one-handed controls.  Set up in "kgoldrunnerui.rc".

    // Key_I, "move_up"
    // Key_L, "move_right"
    // Key_K, "move_down"
    // Key_J, "move_left"
    // Key_Space, "stop" (as above)
    // Key_O, "dig_right"
    // Key_U, "dig_left"

#ifdef KGR_DEBUG
    // Authors' debugging aids.

    (void)	new KAction (i18n("Step"), Key_Period,
		game, TQT_SLOT(doStep()), actionCollection(), "do_step");
    (void)	new KAction (i18n("Test Bug Fix"), Key_B,
		game, TQT_SLOT(bugFix()), actionCollection(), "bug_fix");
    (void)	new KAction (i18n("Show Positions"), Key_D,
		game, TQT_SLOT(showFigurePositions()), actionCollection(), "step");
    (void)	new KAction (i18n("Start Logging"), Key_G,
		game, TQT_SLOT(startLogging()), actionCollection(), "logging");
    (void)	new KAction (i18n("Show Hero"), Key_H,
		game, TQT_SLOT(showHeroState()), actionCollection(), "show_hero");
    (void)	new KAction (i18n("Show Object"), Key_Question,
		game, TQT_SLOT(showObjectState()), actionCollection(), "show_obj");
    (void)	new KAction (i18n("Show Enemy") + "0", Key_0,
		this, TQT_SLOT(showEnemy0()), actionCollection(), "show_enemy_0");
    (void)	new KAction (i18n("Show Enemy") + "1", Key_1,
		this, TQT_SLOT(showEnemy1()), actionCollection(), "show_enemy_1");
    (void)	new KAction (i18n("Show Enemy") + "2", Key_2,
		this, TQT_SLOT(showEnemy2()), actionCollection(), "show_enemy_2");
    (void)	new KAction (i18n("Show Enemy") + "3", Key_3,
		this, TQT_SLOT(showEnemy3()), actionCollection(), "show_enemy_3");
    (void)	new KAction (i18n("Show Enemy") + "4", Key_4,
		this, TQT_SLOT(showEnemy4()), actionCollection(), "show_enemy_4");
    (void)	new KAction (i18n("Show Enemy") + "5", Key_5,
		this, TQT_SLOT(showEnemy5()), actionCollection(), "show_enemy_5");
    (void)	new KAction (i18n("Show Enemy") + "6", Key_6,
		this, TQT_SLOT(showEnemy6()), actionCollection(), "show_enemy_6");
#endif

    /**************************************************************************/
    /**************************   NOW SET IT ALL UP  **************************/
    /**************************************************************************/

    createGUI();
}

/******************************************************************************/
/**********************  SLOTS FOR STATUS BAR UPDATES  ************************/
/******************************************************************************/

void KGoldrunner::initStatusBar()
{
    TQString s = statusBar()->fontInfo().family();	// Set bold font.
    int i = statusBar()->fontInfo().pointSize();
    statusBar()->setFont (TQFont (s, i, TQFont::Bold));

    statusBar()->setSizeGripEnabled (FALSE);		// Use Settings menu ...

    statusBar()->insertItem ("", ID_LIVES);
    statusBar()->insertItem ("", ID_SCORE);
    statusBar()->insertItem ("", ID_LEVEL);
    statusBar()->insertItem ("", ID_HINTAVL);
    statusBar()->insertItem ("", ID_MSG, TQSizePolicy::Horizontally);

    showLives (5);					// Start with 5 lives.
    showScore (0);
    showLevel (0);
    adjustHintAction (FALSE);

    // Set the PAUSE/RESUME key-names into the status bar message.
    pauseKeys = myPause->shortcut().toString();
    pauseKeys = pauseKeys.replace (';', "\" " + i18n("or") + " \"");
    gameFreeze (FALSE);

    statusBar()->setItemFixed (ID_LIVES, -1);		// Fix current sizes.
    statusBar()->setItemFixed (ID_SCORE, -1);
    statusBar()->setItemFixed (ID_LEVEL, -1);

    connect(game, TQT_SIGNAL (showLives (long)),	TQT_SLOT (showLives (long)));
    connect(game, TQT_SIGNAL (showScore (long)),	TQT_SLOT (showScore (long)));
    connect(game, TQT_SIGNAL (showLevel (int)),	TQT_SLOT (showLevel (int)));
    connect(game, TQT_SIGNAL (gameFreeze (bool)),	TQT_SLOT (gameFreeze (bool)));
}

void KGoldrunner::showLives (long newLives)
{
    TQString tmp;
    tmp.setNum (newLives);
    if (newLives < 100)
	tmp = tmp.rightJustify (3, '0');
    tmp.insert (0, i18n("   Lives: "));
    tmp.append ("   ");
    statusBar()->changeItem (tmp, ID_LIVES);
}

void KGoldrunner::showScore (long newScore)
{
    TQString tmp;
    tmp.setNum (newScore);
    if (newScore < 10000)
	tmp = tmp.rightJustify (5, '0');
    tmp.insert (0, i18n("   Score: "));
    tmp.append ("   ");
    statusBar()->changeItem (tmp, ID_SCORE);
}

void KGoldrunner::showLevel (int newLevelNo)
{
    TQString tmp;
    tmp.setNum (newLevelNo);
    if (newLevelNo < 100)
	tmp = tmp.rightJustify (3, '0');
    tmp.insert (0, i18n("   Level: "));
    tmp.append ("   ");
    statusBar()->changeItem (tmp, ID_LEVEL);
}

void KGoldrunner::gameFreeze (bool on_off)
{
    if (on_off)
	statusBar()->changeItem
		    (i18n("Press \"%1\" to RESUME").tqarg(pauseKeys), ID_MSG);
    else
	statusBar()->changeItem
		    (i18n("Press \"%1\" to PAUSE").tqarg(pauseKeys), ID_MSG);
}

void KGoldrunner::adjustHintAction (bool hintAvailable)
{
    hintAction->setEnabled (hintAvailable);

    if (hintAvailable) {
	statusBar()->changeItem (i18n("   Has hint   "), ID_HINTAVL);
    }
    else {
	statusBar()->changeItem (i18n("   No hint   "), ID_HINTAVL);
    }
}

void KGoldrunner::markRuleType (char ruleType)
{
    if (ruleType == 'T')
	tradRules->activate();
    else
	kgrRules->activate();
}

void KGoldrunner::setEditMenu (bool on_off)
{
    saveEdits->setEnabled  (on_off);

    saveGame->setEnabled   (! on_off);
    hintAction->setEnabled (! on_off);
    killHero->setEnabled   (! on_off);
    highScore->setEnabled  (! on_off);

    if (on_off){
	editToolbar->show();
    }
    else {
	editToolbar->hide();
    }
}

/******************************************************************************/
/*******************   SLOTS FOR MENU AND KEYBOARD ACTIONS  *******************/
/******************************************************************************/

// Slot to halt (pause) or restart the game play.

void KGoldrunner::stopStart()
{
    if (! (KGrObject::frozen)) {
	game->freeze();
    }
    else {
	game->unfreeze();
    }
}

// Local slots to create or edit game information.

void KGoldrunner::createGame()		{game->editCollection (SL_CR_GAME);}
void KGoldrunner::editGameInfo()	{game->editCollection (SL_UPD_GAME);}

// Local slots to set the landscape (colour scheme).

void KGoldrunner::lsKGoldrunner()	{view->changeLandscape ("KGoldrunner");}
void KGoldrunner::lsApple2()		{view->changeLandscape ("Apple II");}
void KGoldrunner::lsIceCave()		{view->changeLandscape ("Ice Cave");}
void KGoldrunner::lsMidnight()		{view->changeLandscape ("Midnight");}
void KGoldrunner::lsKDEKool()		{view->changeLandscape ("KDE Kool");}

// Local slots to set mouse or keyboard control of the hero.

void KGoldrunner::setMouseMode()	{game->setMouseMode (TRUE);}
void KGoldrunner::setKeyBoardMode()	{game->setMouseMode (FALSE);}

// Local slots to set game speed.

void KGoldrunner::normalSpeed()		{hero->setSpeed (NSPEED);}
void KGoldrunner::beginSpeed()		{hero->setSpeed (BEGINSPEED);}
void KGoldrunner::champSpeed()		{hero->setSpeed (CHAMPSPEED);}
void KGoldrunner::incSpeed()		{hero->setSpeed (+1);}
void KGoldrunner::decSpeed()		{hero->setSpeed (-1);}

// Slots to set Traditional or KGoldrunner rules.

void KGoldrunner::setTradRules()
{
    KGrFigure::variableTiming = TRUE;
    KGrFigure::alwaysCollectNugget = TRUE;
    KGrFigure::runThruHole = TRUE;
    KGrFigure::reappearAtTop = TRUE;
    KGrFigure::searchStrategy = LOW;
}

void KGoldrunner::setKGrRules()
{
    KGrFigure::variableTiming = FALSE;
    KGrFigure::alwaysCollectNugget = FALSE;
    KGrFigure::runThruHole = FALSE;
    KGrFigure::reappearAtTop = FALSE;
    KGrFigure::searchStrategy = MEDIUM;
}

// Local slots to make playing area larger or smaller.

void KGoldrunner::makeLarger()
{
    if (view->changeSize (+1))
	setFixedSize (view->size());
}

void KGoldrunner::makeSmaller()
{
    if (view->changeSize (-1))
	setFixedSize (view->size());
}

// Local slots for hero control keys.

void KGoldrunner::goUp()		{setKey (KB_UP);}
void KGoldrunner::goR()			{setKey (KB_RIGHT);}
void KGoldrunner::goDown()		{setKey (KB_DOWN);}
void KGoldrunner::goL()			{setKey (KB_LEFT);}
void KGoldrunner::stop()		{setKey (KB_STOP);}
void KGoldrunner::digR()		{setKey (KB_DIGRIGHT);}
void KGoldrunner::digL()		{setKey (KB_DIGLEFT);}

// Local slots for authors' debugging aids.

void KGoldrunner::showEnemy0()		{game->showEnemyState (0);}
void KGoldrunner::showEnemy1()		{game->showEnemyState (1);}
void KGoldrunner::showEnemy2()		{game->showEnemyState (2);}
void KGoldrunner::showEnemy3()		{game->showEnemyState (3);}
void KGoldrunner::showEnemy4()		{game->showEnemyState (4);}
void KGoldrunner::showEnemy5()		{game->showEnemyState (5);}
void KGoldrunner::showEnemy6()		{game->showEnemyState (6);}

void KGoldrunner::saveProperties(KConfig *config)
{
    // The 'config' object points to the session managed
    // config file.  Anything you write here will be available
    // later when this app is restored.

    config->setGroup ("Game");		// Prevents a compiler warning.
    printf ("I am in KGoldrunner::saveProperties.\n");
    // config->writeEntry("qqq", qqq);
}

void KGoldrunner::readProperties(KConfig *config)
{
    // The 'config' object points to the session managed
    // config file.  This function is automatically called whenever
    // the app is being restored.  Read in here whatever you wrote
    // in 'saveProperties'

    config->setGroup ("Game");		// Prevents a compiler warning.
    printf ("I am in KGoldrunner::readProperties.\n");
    // TQString qqq = config->readEntry("qqq");
}

void KGoldrunner::optionsShowToolbar()
{
    // this is all very cut and paste code for showing/hiding the
    // toolbar
    // if (m_toolbarAction->isChecked())
        // toolBar()->show();
    // else
        // toolBar()->hide();
}

void KGoldrunner::optionsShowStatusbar()
{
    // this is all very cut and paste code for showing/hiding the
    // statusbar
    // if (m_statusbarAction->isChecked())
        // statusBar()->show();
    // else
        // statusBar()->hide();
}

void KGoldrunner::optionsConfigureKeys()
{
    KKeyDialog::configure(actionCollection());

    // Update the PAUSE/RESUME message in the status bar.
    pauseKeys = myPause->shortcut().toString();
    pauseKeys = pauseKeys.replace (';', "\" " + i18n("or") + " \"");
    gameFreeze (KGrObject::frozen);	// Refresh the status bar text.
}

void KGoldrunner::optionsConfigureToolbars()
{
    // use the standard toolbar editor
#if defined(KDE_MAKE_VERSION)
# if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
    saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
# else
    saveMainWindowSettings(KGlobal::config());
# endif
#else
    saveMainWindowSettings(KGlobal::config());
#endif
}

void KGoldrunner::newToolbarConfig()
{
    // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
    // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
    createGUI();

#if defined(KDE_MAKE_VERSION)
# if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
    applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
# else
    applyMainWindowSettings(KGlobal::config());
# endif
#else
    applyMainWindowSettings(KGlobal::config());
#endif
}

void KGoldrunner::optionsPreferences()
{
    // popup some sort of preference dialog, here
    // KGoldrunnerPreferences dlg;
    // if (dlg.exec())
    // {
        // redo your settings
    // }
}

void KGoldrunner::changeStatusbar(const TQString& text)
{
    // display the text on the statusbar
    statusBar()->message(text);
}

void KGoldrunner::changeCaption(const TQString& text)
{
    // display the text on the caption
    setCaption(text);
}

bool KGoldrunner::getDirectories()
{
    bool result = TRUE;

    // WHERE THINGS ARE: In the KDE 3 environment (Release 3.1.1), application
    // documentation and data files are in a directory structure given by
    // $KDEDIRS (e.g. "/usr/local/kde" or "/opt/trinity/").  Application user data
    // files are in a directory structure given by $KDEHOME ("$HOME/.kde").
    // Within those two structures, the three sub-directories will typically be
    // "share/doc/HTML/en/kgoldrunner/", "share/apps/kgoldrunner/system/" and
    // "share/apps/kgoldrunner/user/".  Note that it is necessary to have
    // an extra path level ("system" or "user") after "kgoldrunner", otherwise
    // all the KGoldrunner files have similar path names (after "apps") and
    // KDE always locates directories in $KDEHOME and never the released games.

    // The directory strings are set by KDE at run time and might change in
    // later releases, so use them with caution and only if something gets lost.

    KStandardDirs * dirs = new KStandardDirs();

#ifdef QT3
    TQString myDir = "kgoldrunner";
#else
    TQString myDir = "kgoldrun";
#endif

    // Find the KGoldrunner Users' Guide, English version (en).
    systemHTMLDir = dirs->findResourceDir ("html", "en/" + myDir + "/");
    if (systemHTMLDir.length() <= 0) {
	KGrMessage::information (this, i18n("Get Folders"),
	i18n("Cannot find documentation sub-folder 'en/%1/' "
	"in area '%2' of the KDE folder ($KDEDIRS).")
	.tqarg(myDir).tqarg(dirs->kde_default ("html")));
	// result = FALSE;		// Don't abort if the doc is missing.
    }
    else
	systemHTMLDir.append ("en/" + myDir + "/");

    // Find the system collections in a directory of the required KDE type.
    systemDataDir = dirs->findResourceDir ("data", myDir + "/system/");
    if (systemDataDir.length() <= 0) {
	KGrMessage::information (this, i18n("Get Folders"),
	i18n("Cannot find system games sub-folder '%1/system/' "
	"in area '%2' of the KDE folder ($KDEDIRS).")
	.tqarg(myDir).tqarg(dirs->kde_default ("data")));
	result = FALSE;			// ABORT if the games data is missing.
    }
    else
	systemDataDir.append (myDir + "/system/");

    // Locate and optionally create directories for user collections and levels.
    bool create = TRUE;
    userDataDir   = dirs->saveLocation ("data", myDir + "/user/", create);
    if (userDataDir.length() <= 0) {
	KGrMessage::information (this, i18n("Get Folders"),
	i18n("Cannot find or create user games sub-folder '%1/user/' "
	"in area '%2' of the KDE user area ($KDEHOME).")
	.tqarg(myDir).tqarg(dirs->kde_default ("data")));
	// result = FALSE;		// Don't abort if user area is missing.
    }
    else {
	create = dirs->makeDir (userDataDir + "levels/");
	if (! create) {
	    KGrMessage::information (this, i18n("Get Folders"),
	    i18n("Cannot find or create 'levels/' folder in "
	    "sub-folder '%1/user/' in the KDE user area ($KDEHOME).").tqarg(myDir));
	    // result = FALSE;		// Don't abort if user area is missing.
	}
    }

    return (result);
}

// This method is invoked when top-level window is closed, whether by selecting
// "Quit" from the menu or by clicking the "X" at the top right of the window.

bool KGoldrunner::queryClose ()
{
    // Last chance to save: user has clicked "X" widget or menu-Quit.
    bool cannotContinue = TRUE;
    game->saveOK (cannotContinue);
    return (TRUE);
}

void KGoldrunner::setKey (KBAction movement)
{
    if (game->inEditMode()) return;

    // Using keyboard control can automatically disable mouse control.
    if (game->inMouseMode()) {
        // Halt the game while a message is displayed.
        game->setMessageFreeze (TRUE);

        switch (KGrMessage::warning (this, i18n("Switch to Keyboard Mode"),
		i18n("You have pressed a key that can be used to move the "
		"Hero. Do you want to switch automatically to keyboard "
		"control? Mouse control is easier to use in the long term "
		"- like riding a bike rather than walking!"),
		i18n("Switch to &Keyboard Mode"), i18n("Stay in &Mouse Mode")))
        {
        case 0: game->setMouseMode (FALSE);	// Set internal mouse mode OFF.
		setMouse->setChecked (FALSE);	// Adjust the Settings menu.
		setKeyboard->setChecked (TRUE);
                break;
        case 1: break;
        }

        // Unfreeze the game, but only if it was previously unfrozen.
        game->setMessageFreeze (FALSE);

        if (game->inMouseMode())
            return;                    		// Stay in Mouse Mode.
    }

    if ( game->getLevel() != 0 )
    {
      if (! hero->started )			// Start when first movement
          game->startPlaying();			// key is pressed ...
      game->heroAction (movement);
    }
}

/******************************************************************************/
/**********************  MAKE A TOOLBAR FOR THE EDITOR   **********************/
/******************************************************************************/

#include <tqwmatrix.h>
void KGoldrunner::makeEditToolbar()
{
    // Set up the pixmaps for the editable objects.
    TQPixmap pixmap;
    TQImage image;

    TQPixmap brickbg	= view->getPixmap (BRICK);
    TQPixmap fbrickbg	= view->getPixmap (FBRICK);

    TQPixmap freebg	= view->getPixmap (FREE);
    TQPixmap nuggetbg	= view->getPixmap (NUGGET);
    TQPixmap polebg	= view->getPixmap (POLE);
    TQPixmap betonbg	= view->getPixmap (BETON);
    TQPixmap ladderbg	= view->getPixmap (LADDER);
    TQPixmap hladderbg	= view->getPixmap (HLADDER);
    TQPixmap edherobg	= view->getPixmap (HERO);
    TQPixmap edenemybg	= view->getPixmap (ENEMY);

    if (usesBigPixmaps()) {	// Scale up the pixmaps (to give cleaner looking
				// icons than leaving it for TQToolButton to do).
	TQWMatrix w;
	w = w.scale (2.0, 2.0);

	// The pixmaps shown on the buttons used to remain small and incorrectly
	// painted, in KDE, in spite of the 2x (32x32) scaling.  "insertButton"
	// calls TQIconSet, to generate a set of icons from each pixmapx, then
	// seems to select the small size to paint on the button.  The following
	// line forces all icons, large and small, to be size 32x32 in advance.
	TQIconSet::setIconSize (TQIconSet::Small, TQSize (32, 32));

	brickbg			= brickbg.xForm (w);
	fbrickbg		= fbrickbg.xForm (w);

	freebg			= freebg.xForm (w);
	nuggetbg		= nuggetbg.xForm (w);
	polebg			= polebg.xForm (w);
	betonbg			= betonbg.xForm (w);
	ladderbg		= ladderbg.xForm (w);
	hladderbg		= hladderbg.xForm (w);
	edherobg		= edherobg.xForm (w);
	edenemybg		= edenemybg.xForm (w);
    }

    editToolbar = new KToolBar (this, TQt::DockTop, TRUE, "Editor", TRUE);

    // Choose a colour that enhances visibility of the KGoldrunner pixmaps.
    // editToolbar->setPalette (TQPalette (TQColor (150, 150, 230)));

    // editToolbar->setHorizontallyStretchable (TRUE);	// Not effective in KDE.

    // All those separators are just to get reasonable visual spacing of the
    // pixmaps in KDE.  "setHorizontallyStretchable(TRUE)" does it in TQt.

    editToolbar->insertSeparator();

    editToolbar->insertButton ("filenew",  0,           TQT_SIGNAL(clicked()), game,
			TQT_SLOT(createLevel()),  TRUE,  i18n("&Create a Level"));
    editToolbar->insertButton ("fileopen", 1,           TQT_SIGNAL(clicked()), game,
			TQT_SLOT(updateLevel()),  TRUE,  i18n("&Edit Any Level..."));
    editToolbar->insertButton ("filesave", 2,           TQT_SIGNAL(clicked()), game,
			TQT_SLOT(saveLevelFile()),TRUE,  i18n("&Save Edits..."));

    editToolbar->insertSeparator();
    editToolbar->insertSeparator();

    editToolbar->insertButton ("ktip",     3,           TQT_SIGNAL(clicked()), game,
		TQT_SLOT(editNameAndHint()),TRUE,i18n("Edit Name/Hint"));

    editToolbar->insertSeparator();
    editToolbar->insertSeparator();

    editToolbar->insertButton (freebg,    (int)FREE,    TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT(freeSlot()),     TRUE,  i18n("Empty space"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (edherobg,  (int)HERO,    TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (edheroSlot()),  TRUE,  i18n("Hero"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (edenemybg, (int)ENEMY,   TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (edenemySlot()), TRUE,  i18n("Enemy"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (brickbg,   (int)BRICK,   TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (brickSlot()),   TRUE,  i18n("Brick (can dig)"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (betonbg,   (int)BETON,   TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (betonSlot()),   TRUE,  i18n("Concrete (cannot dig)"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (fbrickbg,  (int)FBRICK,  TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (fbrickSlot()),  TRUE,  i18n("Trap (can fall through)"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (ladderbg,  (int)LADDER,  TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (ladderSlot()),  TRUE,  i18n("Ladder"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (hladderbg, (int)HLADDER, TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (hladderSlot()), TRUE,  i18n("Hidden ladder"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (polebg,    (int)POLE,    TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (poleSlot()),    TRUE,  i18n("Pole (or bar)"));
    editToolbar->insertSeparator();
    editToolbar->insertButton (nuggetbg,  (int)NUGGET,  TQT_SIGNAL(clicked()), TQT_TQOBJECT(this),
		TQT_SLOT (nuggetSlot()),  TRUE,  i18n("Gold nugget"));

    editToolbar->setToggle ((int) FREE,    TRUE);
    editToolbar->setToggle ((int) HERO,    TRUE);
    editToolbar->setToggle ((int) ENEMY,   TRUE);
    editToolbar->setToggle ((int) BRICK,   TRUE);
    editToolbar->setToggle ((int) BETON,   TRUE);
    editToolbar->setToggle ((int) FBRICK,  TRUE);
    editToolbar->setToggle ((int) LADDER,  TRUE);
    editToolbar->setToggle ((int) HLADDER, TRUE);
    editToolbar->setToggle ((int) POLE,    TRUE);
    editToolbar->setToggle ((int) NUGGET,  TRUE);

    pressedButton = (int) BRICK;
    editToolbar->setButton (pressedButton, TRUE);
}

/******************************************************************************/
/*********************   EDIT-BUTTON SLOTS   **********************************/
/******************************************************************************/

void KGoldrunner::freeSlot()
		{ game->setEditObj (FREE);    setButton ((int) FREE);    }
void KGoldrunner::edheroSlot()
		{ game->setEditObj (HERO);    setButton ((int) HERO);    }
void KGoldrunner::edenemySlot()
		{ game->setEditObj (ENEMY);   setButton ((int) ENEMY);   }
void KGoldrunner::brickSlot()
		{ game->setEditObj (BRICK);   setButton ((int) BRICK);   }
void KGoldrunner::betonSlot()
		{ game->setEditObj (BETON);   setButton ((int) BETON);   }
void KGoldrunner::fbrickSlot()
		{ game->setEditObj (FBRICK);  setButton ((int) FBRICK);  }
void KGoldrunner::ladderSlot()
		{ game->setEditObj (LADDER);  setButton ((int) LADDER);  }
void KGoldrunner::hladderSlot()
		{ game->setEditObj (HLADDER); setButton ((int) HLADDER); }
void KGoldrunner::poleSlot()
		{ game->setEditObj (POLE);    setButton ((int) POLE);    }
void KGoldrunner::nuggetSlot()
		{ game->setEditObj (NUGGET);  setButton ((int) NUGGET);  }
void KGoldrunner::defaultEditObj()
		{ setButton ((int) BRICK);				 }

void KGoldrunner::setButton (int btn)
{
    editToolbar->setButton (pressedButton, FALSE);
    pressedButton = btn;
    editToolbar->setButton (pressedButton, TRUE);
}

#include "kgoldrunner.moc"