Hello.

This patch adds internationalized shortcuts to main-menu items.
It's not perfect:
 * there is no detection of multiple items with the same translation.
 * there is no visual highlight so users won't know that something is
   different
 * only a-z are supported

Feel free to make modifications or send comments.

Index: menu.cpp
===================================================================
RCS file: /cvs/wormux/wormux/src/menu.cpp,v
retrieving revision 1.18
diff -r1.18 menu.cpp
154a156,159
> int CL_key_for(char c) {
>     return CL_KEY_A + tolower(c) - 'a';
> }
>
158,170c163,202
<   // Clic gauche ?
<   if (touche.id == CL_MOUSE_LEFTBUTTON)
<   {
<     int x = CL_Mouse::get_x();
<     int y = CL_Mouse::get_y();
<     if (jouer.Test (x, y)) { choix = menuJOUER; return; }
<     if (options.Test (x, y)) { choix = menuOPTIONS; return; }
<     if (infos.Test (x, y)) { choix = menuINFOS; return; }
<     if (quitter.Test (x, y)) { choix = menuQUITTER; return; }
<   }
<
<   if (touche.id == CL_KEY_ENTER){ choix = menuJOUER; return; }
<   if (touche.id == CL_KEY_ESCAPE) { choix = menuQUITTER; return; }
---
>     switch (touche.id) {
>       case CL_KEY_ENTER:
>           choix = menuJOUER;
>           break;
>       case CL_KEY_ESCAPE:
>           choix = menuQUITTER;
>           break;
>       case CL_MOUSE_LEFTBUTTON:
>           {
>               int x = CL_Mouse::get_x();
>               int y = CL_Mouse::get_y();
>               if (jouer.Test (x, y)) { choix = menuJOUER; return; }
>               if (options.Test (x, y)) { choix = menuOPTIONS; return; }
>               if (infos.Test (x, y)) { choix = menuINFOS; return; }
>               if (quitter.Test (x, y)) { choix = menuQUITTER; return; }
>           }
>           break;
>       default:
>           {
>               struct foo {
>                   const char  *text;
>                   menu_item   value;
>               };
>
>               static const foo menu_foo[] = {
>                   {"Play", menuJOUER},
>                   {"Options", menuOPTIONS},
>                   {"Infos", menuINFOS},
>                   {"Quit", menuQUITTER}
>               };
>
>               /* Use first character as keybinding */
>               for (size_t i=0; i<sizeof menu_foo / sizeof *menu_foo; ++i)
>                   if (touche.id == CL_key_for (*gettext (menu_foo[i].text))) {
>                       choix = menu_foo[i].value;
>                       return;
>                   }
>           }
>           break;
>     }

Z/K

-- 
Zygmunt Krynicki


Répondre à