adds new piece types in the promotion dialog and edit-position piece menu
[xboard.git] / xboard.c
index 489ef64..f9ed2d7 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -696,21 +696,27 @@ MenuItem buttonBar[] = {
     {NULL, NULL}
 };
 
-#define PIECE_MENU_SIZE 11
+#define PIECE_MENU_SIZE 18
 String pieceMenuStrings[2][PIECE_MENU_SIZE] = {
     { N_("White"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
-      N_("Queen"), N_("King"), "----", N_("Empty square"), N_("Clear board") },
+      N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"), 
+      N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"), 
+      N_("Empty square"), N_("Clear board") },
     { N_("Black"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
-      N_("Queen"), N_("King"), "----", N_("Empty square"), N_("Clear board") },
+      N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"), 
+      N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"), 
+      N_("Empty square"), N_("Clear board") }
 };
 /* must be in same order as PieceMenuStrings! */
 ChessSquare pieceMenuTranslation[2][PIECE_MENU_SIZE] = {
     { WhitePlay, (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop,
-       WhiteRook, WhiteQueen, WhiteKing,
-       (ChessSquare) 0, EmptySquare, ClearBoard },
+       WhiteRook, WhiteQueen, WhiteKing, (ChessSquare) 0, WhiteAlfil,
+       WhiteCannon, WhiteAngel, WhiteMarshall, (ChessSquare) 0, 
+       PromotePiece, DemotePiece, EmptySquare, ClearBoard },
     { BlackPlay, (ChessSquare) 0, BlackPawn, BlackKnight, BlackBishop,
-       BlackRook, BlackQueen, BlackKing,
-       (ChessSquare) 0, EmptySquare, ClearBoard },
+       BlackRook, BlackQueen, BlackKing, (ChessSquare) 0, BlackAlfil,
+       BlackCannon, BlackAngel, BlackMarshall, (ChessSquare) 0, 
+       PromotePiece, DemotePiece, EmptySquare, ClearBoard },
 };
 
 #define DROP_MENU_SIZE 6
@@ -2600,6 +2606,10 @@ XBoard square size (hint): %d\n\
     if (forceMono) {
       fprintf(stderr, _("%s: too few colors available; trying monochrome mode\n"),
              programName);
+      
+      if (appData.bitmapDirectory == NULL ||
+             appData.bitmapDirectory[0] == NULLCHAR)
+           appData.bitmapDirectory = DEF_BITMAP_DIR;
     }
 
     if (appData.lowTimeWarning && !appData.monoMode) {
@@ -3782,6 +3792,8 @@ void CreateXIMPieces()
     XSynchronize(xDisplay, False); /* Work-around for xlib/xt buffering bug */
 }
 
+char pieceBitmapNames[] = "pnbrqfeacwmohijgdvlsuk";
+
 #if HAVE_LIBXPM
 void CreateXPMPieces()
 {
@@ -3858,7 +3870,7 @@ void CreateXPMPieces()
            for (kind=0; kind<4; kind++) {
              snprintf(buf, sizeof(buf), "%s/%c%s%u.xpm",
                        ExpandPathName(appData.pixmapDirectory),
-                       ToLower(PieceToChar((ChessSquare)piece)),
+                       pieceBitmapNames[piece],
                        xpmkind[kind], ss);
                if (appData.debugMode) {
                    fprintf(stderr, _("(File:%s:) "), buf);
@@ -3922,7 +3934,7 @@ void CreatePieces()
 
     for (kind = SOLID; kind <= (appData.monoMode ? OUTLINE : SOLID); kind++) {
        for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
-           sprintf(buf, "%c%u%c.bm", ToLower(PieceToChar((ChessSquare)piece)),
+           sprintf(buf, "%c%u%c.bm", pieceBitmapNames[piece],
                    ss, kind == SOLID ? 's' : 'o');
            ReadBitmap(&pieceBitmap[kind][piece], buf, NULL, ss, ss);
        }
@@ -3947,7 +3959,7 @@ void CreatePieces()
 
     for (kind = SOLID; kind <= (appData.monoMode ? OUTLINE : SOLID); kind++) {
        for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
-           sprintf(buf, "%c%u%c.bm", ToLower(PieceToChar((ChessSquare)piece)),
+           sprintf(buf, "%c%u%c.bm", pieceBitmapNames[piece],
                    ss, kind == SOLID ? 's' : 'o');
            ReadBitmap(&pieceBitmap[kind][piece], buf,
                       bib->bits[kind][piece], ss, ss);
@@ -3976,6 +3988,7 @@ void ReadBitmap(pm, name, bits, wreq, hreq)
        strcat(fullname, name);
        errcode = XReadBitmapFile(xDisplay, xBoardWindow, fullname,
                                  &w, &h, pm, &x_hot, &y_hot);
+    fprintf(stderr, "load %s\n", name);
        if (errcode != BitmapSuccess) {
            switch (errcode) {
              case BitmapOpenFailed:
@@ -5829,11 +5842,12 @@ void PromotionPopUp()
                            layoutArgs, XtNumber(layoutArgs));
 
     j = 0;
-    XtSetArg(args[j], XtNlabel, _("Promote pawn to what?")); j++;
+    XtSetArg(args[j], XtNlabel, _("Promote to what?")); j++;
     XtSetArg(args[j], XtNborderWidth, 0); j++;
     dialog = XtCreateManagedWidget("promotion", dialogWidgetClass,
                                   layout, args, j);
 
+  if(gameInfo.variant != VariantShogi) {
     XawDialogAddButton(dialog, _("Queen"), PromotionCallback,
                       (XtPointer) dialog);
     XawDialogAddButton(dialog, _("Rook"), PromotionCallback,
@@ -5847,6 +5861,21 @@ void PromotionPopUp()
       XawDialogAddButton(dialog, _("King"), PromotionCallback,
                         (XtPointer) dialog);
     }
+    if(gameInfo.variant == VariantCapablanca || 
+       gameInfo.variant == VariantGothic || 
+       gameInfo.variant == VariantCapaRandom) {
+      XawDialogAddButton(dialog, _("Archbishop"), PromotionCallback,
+                        (XtPointer) dialog);
+      XawDialogAddButton(dialog, _("Chancellor"), PromotionCallback,
+                        (XtPointer) dialog);
+    }
+  } else // [HGM] shogi
+  {
+      XawDialogAddButton(dialog, _("Promote"), PromotionCallback,
+                        (XtPointer) dialog);
+      XawDialogAddButton(dialog, _("Defer"), PromotionCallback,
+                        (XtPointer) dialog);
+  }
     XawDialogAddButton(dialog, _("cancel"), PromotionCallback,
                       (XtPointer) dialog);
 
@@ -5901,6 +5930,10 @@ void PromotionCallback(w, client_data, call_data)
        return;
     } else if (strcmp(name, _("Knight")) == 0) {
        promoChar = 'n';
+    } else if (strcmp(name, _("Promote")) == 0) {
+       promoChar = '+';
+    } else if (strcmp(name, _("Defer")) == 0) {
+       promoChar = '=';
     } else {
        promoChar = ToLower(name[0]);
     }
@@ -7526,7 +7559,7 @@ void DisplayTitle(text)
        strcpy(title, text);
     } else if (appData.icsActive) {
         snprintf(icon, sizeof(icon), "%s", appData.icsHost);
-       snprintf(title, sizeof(title),"%s: %s", programName, appData.icsHost);
+       snprintf(title, sizeof(title), "%s: %s", programName, appData.icsHost);
     } else if (appData.cmailGameName[0] != NULLCHAR) {
         snprintf(icon, sizeof(icon), "%s", "CMail");
        snprintf(title,sizeof(title), "%s: %s", programName, "CMail");
@@ -7570,7 +7603,7 @@ void DisplayError(message, error)
            fprintf(stderr, "%s: %s: %s\n",
                    programName, message, strerror(error));
        }
-       snprintf(buf,sizeof(buf), "%s: %s", message, strerror(error));
+       snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
        message = buf;
     }
     ErrorPopUp(_("Error"), message, FALSE);