2 * menus.c -- platform-indendent menu handling code for ShogiVar (adapted from XBoard)
4 * Copyright 1991 by Digital Equipment Corporation, Maynard,
7 * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
8 * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
10 * The following terms apply to Digital Equipment Corporation's copyright
12 * ------------------------------------------------------------------------
15 * Permission to use, copy, modify, and distribute this software and its
16 * documentation for any purpose and without fee is hereby granted,
17 * provided that the above copyright notice appear in all copies and that
18 * both that copyright notice and this permission notice appear in
19 * supporting documentation, and that the name of Digital not be
20 * used in advertising or publicity pertaining to distribution of the
21 * software without specific, written prior permission.
23 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
30 * ------------------------------------------------------------------------
32 * The following terms apply to the enhanced version of XBoard
33 * distributed by the Free Software Foundation:
34 * ------------------------------------------------------------------------
36 * GNU XBoard is free software: you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation, either version 3 of the License, or (at
39 * your option) any later version.
41 * GNU XBoard is distributed in the hope that it will be useful, but
42 * WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 * General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program. If not, see http://www.gnu.org/licenses/. *
49 *------------------------------------------------------------------------
50 ** See the file ChangeLog for a revision history. */
61 #include <sys/types.h>
69 #else /* not STDC_HEADERS */
70 extern char *getenv();
73 # else /* not HAVE_STRING_H */
75 # endif /* not HAVE_STRING_H */
76 #endif /* not STDC_HEADERS */
86 // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
96 # define _(s) gettext (s)
97 # define N_(s) gettext_noop (s)
104 * Button/menu procedures
108 int shiftKey
, controlKey
;
109 char *gameCopyFilename
, *gamePasteFilename
;
121 Board
.Timer1
.Enabled
= False
;
123 ScheduleDelayedEvent(&DoChange
, 500);
129 if(FileNamePopUpWrapper("Save Game", "", "*.gam", NULL
, 0, "w", Board
.CMSave
.Filename
, NULL
))
136 if(FileNamePopUpWrapper("Create Text Diagram", "", "*.txt", NULL
, 0, "w", Board
.CMDiagram
.Filename
, NULL
))
143 if(FileNamePopUpWrapper("Create Small Text Diagram", "", "*.txt", NULL
, 0, "w", Board
.CMDiagram
.Filename
, NULL
))
150 if(FileNamePopUpWrapper("Load Game", "", "*.gam", NULL
, 0, "r", Board
.CMSave
.Filename
, NULL
))
181 strcpy(ExtraPiece
, "Black"); CheckAdd();
187 strcpy(ExtraPiece
, "White"); CheckAdd();
194 Reduce
= 1; SetHandicap();
200 if(strcmp(Turn
, "White") ) strcpy(Turn
, "White"); else strcpy(Turn
, "Black");
201 MarkMenuItem("Setup.Turn", !strcpy(Turn
, "White"));
220 if(LegalMoves
== 0) {
237 EndSetup(); SetHandicap();
246 # define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
253 MARK_MENU_ITEM("Moves.ShowLegal", SeeMove
);
259 strcpy(Threat
, strcmp(Threat
, "On") ? "On" : "Off");
261 MARK_MENU_ITEM("Moves.ShowTheat", !strcmp(Threat
, "On"));
268 if (!Eval
) strcpy(Board
.Caption
, Cap
);
269 strcpy(Board
.PieceID
.Caption
, Eval
? "Evaluation On" : "Evaluation Off");
271 MARK_MENU_ITEM("Moves.Evaluate", Eval
);
277 int w
; // white is a computer player
278 if(!strcmp(Computer
, "White")) w
= 0, strcpy( Computer
, "None"); else
279 if(!strcmp(Computer
, "Both")) w
= 0, strcpy( Computer
, "Black"); else
280 if(!strcmp(Computer
, "Black")) w
= 1, strcpy( Computer
, "Both"); else
281 if(!strcmp(Computer
, "None")) w
= 1, strcpy( Computer
, "White");
283 MARK_MENU_ITEM("Setup.CompWhite", w
);
284 if (w
&& !strcmp(Turn
, "White")) CompMain();
290 int b
; // black is a computer player
291 if(!strcmp(Computer
, "Black")) b
= 0, strcpy( Computer
, "None"); else
292 if(!strcmp(Computer
, "Both")) b
= 0, strcpy( Computer
, "White"); else
293 if(!strcmp(Computer
, "White")) b
= 1, strcpy( Computer
, "Both"); else
294 if(!strcmp(Computer
, "None")) b
= 1, strcpy( Computer
, "Black");
296 MARK_MENU_ITEM("Setup.CompBlack", b
);
297 if (b
&& !strcmp(Turn
, "Black")) CompMain();
302 { // Toggle between Weak and Less Weak
303 strcpy(Grade
, strcmp(Grade
, "LessWeak") ? "LessWeak": "Weak");
305 MARK_MENU_ITEM("Setup.LessWeak", !strcmp(Grade
, "LessWeak"));
314 MARK_MENU_ITEM("Setup.Notate", !Notate
);
320 ShowLast
= !ShowLast
;
322 MARK_MENU_ITEM("Moves.Flash", ShowLast
);
328 AutoPromote
= !AutoPromote
;
330 MARK_MENU_ITEM("Setup.AutoProm", AutoPromote
);
337 if(Timing
) ClocksOff(); else ClocksOn();
338 MARK_MENU_ITEM("Setup.Clocks", !Timing
);
339 if(Board
.Timer1
.Enabled
) StartClockTimer(1000);
348 MARK_MENU_ITEM("Setup.Japanese", !western
);
355 if(LionHawkVer
== 2) LionHawkVer
= 1, v
= 42, c
= 'L';
356 else LionHawkVer
= 2, v
= 26, c
= 'D';
357 Pieces
[47].Value
= Pieces
[64].Value
= Pieces
[18].PrValue
= v
;
358 Pieces
[47].special
= Pieces
[64].special
= c
;
360 MARK_MENU_ITEM("Setup.LionHawk", LionHawkVer
== 2);
364 * Menu definition tables
367 MenuItem gameMenu
[] = {
368 {N_("New Game"), "<Ctrl>n", "NewGame", NewGameProc
},
369 {N_("Load Game"), "<Ctrl>o", "LoadGame", LoadGameProc
},
370 {N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc
},
371 {N_("Change Game"), "<Ctrl>s", "ChangeGame", ChangeGameProc
},
372 {"----", NULL
, NULL
, NothingProc
},
373 {N_("Quit "), "<Ctrl>q", "Quit", QuitProc
},
374 {NULL
, NULL
, NULL
, NULL
}
377 MenuItem movesMenu
[] = {
378 {N_("Show Legal Moves"), NULL
, "ShowLegal", ShowLegalProc
, CHECK
},
379 {N_("Show Influence/Threats"), "<ctrl>i", "ShowThreat", ShowThreatsProc
, CHECK
},
380 {N_("Flash Last Move"), NULL
, "Flash", FlashProc
, CHECK
},
381 {"----", NULL
, NULL
, NothingProc
},
382 {N_("Force Move"), "<ctrl>f", "ForceMove", ForceProc
},
383 {"----", NULL
, NULL
, NothingProc
},
384 {N_("Take Back"), "<ctrl>b", "TakeBack", TakeBack
},
385 {N_("Take Back All"), "<shift>Delete", "BackAll", TakeAll
},
386 {"----", NULL
, NULL
, NothingProc
},
387 {N_("Replay"), "<ctrl>r", "Replay", Replay
},
388 {N_("Replay All"), "<shift>Insert", "RepAll", ReplayAll
},
389 {"----", NULL
, NULL
, NothingProc
},
390 {N_("Suggest Move"), "<ctrl>m", "Suggest", SetSuggest
},
391 {"----", NULL
, NULL
, NothingProc
},
392 {N_("Evaluate"), "<ctrl>e", "Evaluate", EvaluateProc
, CHECK
},
393 {"----", NULL
, NULL
, NothingProc
},
394 {N_("Print Moves"), "<ctrl>p", "PrintMoves", PrintScore
},
395 {"----", NULL
, NULL
, NothingProc
},
396 {N_("Create Text Score"), "<ctrl>t", "CreateLarge", DiagramProc
},
397 {N_("Create Text Diagram"), "<ctrl>y" , "CreateSmall", SmallProc
},
398 {NULL
, NULL
, NULL
, NULL
}
401 MenuItem setupMenu
[] = {
402 {N_("Computer White"), NULL
, "CompWhite", CompWhiteProc
, CHECK
},
403 {N_("Computer Black"), NULL
, "CompBlack", CompBlackProc
, CHECK
},
404 {"----", NULL
, NULL
, NothingProc
},
405 {N_("Rotate Board"), "<ctrl>w", "Rotate", RotateProc
},
406 {"----", NULL
, NULL
, NothingProc
},
407 {N_("Switch Sides"), "<ctrl>x", "SwitchSides", SwitchCompPlayer
},
408 {"----", NULL
, NULL
, NothingProc
},
409 {N_("Difficulty Less Weak"), "F6", "LessWeak", LevelProc
, CHECK
},
410 {"----", NULL
, NULL
, NothingProc
},
411 {N_("Notation"), NULL
, "Notation", NotateProc
, CHECK
},
412 {N_("Clocks"), NULL
, "Clocks", ClocksProc
, CHECK
},
413 {N_("Auto Promotion"), "<ctrl>a", "AutoProm", AutoPromProc
, CHECK
},
414 {"----", NULL
, NULL
, NothingProc
},
415 {N_("Clear Board"), NULL
, "Clear", ClearProc
},
416 {N_("Add Black Pieces"), NULL
, "AddBlack", AddBlackProc
},
417 {N_("Add White Pieces"), NULL
, "AddWhite", AddWhiteProc
},
418 {N_("Remove Pieces"), NULL
, "Remove", RemoveProc
},
419 {N_("Move Pieces"), NULL
, "Setup", MovePieceProc
},
420 {N_("White to Move"), NULL
, "Turn", TurnProc
, CHECK
},
421 {N_("Set Handicap"), "<ctrl>h", "Handicap", HandicapProc
},
422 {"----", NULL
, NULL
, NothingProc
},
423 {N_("Japanese Pieces"), NULL
, "Japanese", PiecesProc
, CHECK
},
424 {"----", NULL
, NULL
, NothingProc
},
425 {N_("Lion Hawk Version 2"), NULL
, "LionHawk", LionHawkProc
, CHECK
},
426 {NULL
, NULL
, NULL
, NULL
}
429 MenuItem helpMenu
[] = {
430 {N_("About"), "F1", "About", AboutProc
},
431 {"----", NULL
, NULL
, NothingProc
},
432 {N_("General"), "F2", "General", SetGeneral
},
433 {N_("Rules"), "F3", "Rules", SetRules
},
434 {N_("Piece Help"), "F4", "PieceHelp", PieceHelpProc
},
435 {NULL
, NULL
, NULL
, NULL
}
438 MenuItem noMenu
[] = {
439 {NULL
, NULL
, NULL
, NULL
}
443 {N_("Game"), "Game", gameMenu
},
444 {N_("Moves"), "Moves", movesMenu
},
445 {N_("Set-Up"), "Setup", setupMenu
},
446 {N_("Help"), "Help", helpMenu
},
451 MenuNameToItem (char *menuName
)
456 static MenuItem a
= { NULL
, NULL
, NULL
, NothingProc
};
457 extern Option mainOptions
[];
458 strncpy(buf
, menuName
, 511);
459 p
= strchr(buf
, '.');
460 if(!p
) menuTab
= noMenu
, p
= menuName
; else {
462 for(i
=0; menuBar
[i
].name
; i
++)
463 if(!strcmp(buf
, menuBar
[i
].ref
)) break;
464 if(!menuBar
[i
].name
) return NULL
; // main menu not found
465 menuTab
= menuBar
[i
].mi
;
467 if(*p
== '\0') { a
.handle
= mainOptions
[i
+1].handle
; return &a
; } // main menu bar
468 for(i
=0; menuTab
[i
].string
; i
++)
469 if(menuTab
[i
].ref
&& !strcmp(p
, menuTab
[i
].ref
)) return menuTab
+ i
;
470 return NULL
; // item not found
473 Enables icsEnables
[] = {
474 { "File.MailMove", False
},
479 GreyRevert (Boolean grey
)
481 EnableNamedMenuItem("Edit.Revert", !grey
);
482 EnableNamedMenuItem("Edit.Annotate", !grey
);
488 MarkMenuItem("Setup.Japanese", True
);
489 MarkMenuItem("Setup.Clocks", !Timing
);
490 MarkMenuItem("Setup.Notation", !Notate
);
491 MarkMenuItem("Moves.Flash", ShowLast
);
492 MarkMenuItem("Moves.ShowLegal", SeeMove
);
493 MarkMenuItem("Moves.Evaluate", Eval
);
494 MarkMenuItem("Moves.ShowThreat", !strcmp(Threat
, "On"));
495 MarkMenuItem("Setup.LessWeak", !strcmp(Grade
, "LessWeak"));
496 MarkMenuItem("Setup.CompWhite", !strcmp(Computer
, "White") || !strcmp(Computer
, "Both"));
497 MarkMenuItem("Setup.CompBlack", !strcmp(Computer
, "Black") || !strcmp(Computer
, "Both"));
498 if(strcmp(Choice
, "Tenjiku")) {
499 EnableNamedMenuItem("Setup.LionHawk", False
);
501 EnableNamedMenuItem("Setup.LionHawk", True
);
502 MarkMenuItem("Setup.LionHawk", LionHawkVer
== 2);