| 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 |
#include "menu_utils.h" |
| 30 |
|
| 31 |
#include <assert.h> |
| 32 |
|
| 33 |
#include <cdogs/draw/draw.h> |
| 34 |
#include <cdogs/draw/draw_actor.h> |
| 35 |
#include <cdogs/font.h> |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
void DisplayCharacterAndName( |
| 41 |
struct vec2i pos, const Character *c, const direction_e d, |
| 42 |
const char *name, const color_t color, const WeaponClass *gun) |
| 43 |
{ |
| 44 |
|
| 45 |
|
| 46 |
pos.y += 8; |
| 47 |
struct vec2i namePos = svec2i_add(pos, svec2i(-FontStrW(name) / 2, -30)); |
| 48 |
DrawCharacterSimple(c, pos, d, false, false, gun); |
| 49 |
FontStrMask(name, namePos, color); |
| 50 |
} |
| 51 |
|
| 52 |
void MenuDisplayPlayer( |
| 53 |
const menu_t *menu, GraphicsDevice *g, |
| 54 |
const struct vec2i pos, const struct vec2i size, const void *data) |
| 55 |
{ |
| 56 |
UNUSED(g); |
| 57 |
const MenuDisplayPlayerData *d = data; |
| 58 |
struct vec2i playerPos; |
| 59 |
char s[22]; |
| 60 |
UNUSED(menu); |
| 61 |
struct vec2i dPos = pos; |
| 62 |
dPos.x -= size.x; |
| 63 |
playerPos = svec2i( |
| 64 |
dPos.x + size.x * 3 / 4 - 12 / 2, CENTER_Y(dPos, size, 0) - 12); |
| 65 |
|
| 66 |
PlayerData *pData = PlayerDataGetByUID(d->PlayerUID); |
| 67 |
if (d->currentMenu && strcmp((*d->currentMenu)->name, "Name") == 0) |
| 68 |
{ |
| 69 |
sprintf(s, "%c%s%c", '>', pData->name, '<'); |
| 70 |
} |
| 71 |
else |
| 72 |
{ |
| 73 |
strcpy(s, pData->name); |
| 74 |
} |
| 75 |
const WeaponClass *gun = NULL; |
| 76 |
if (d->GunIdx >= 0 && d->GunIdx < MAX_WEAPONS) |
| 77 |
{ |
| 78 |
gun = pData->guns[d->GunIdx]; |
| 79 |
} |
| 80 |
|
| 81 |
DisplayCharacterAndName(playerPos, &pData->Char, d->Dir, s, colorWhite, gun); |
| 82 |
} |
| 83 |
|
| 84 |
void MenuDisplayPlayerControls( |
| 85 |
const menu_t *menu, GraphicsDevice *g, |
| 86 |
const struct vec2i pos, const struct vec2i size, const void *data) |
| 87 |
{ |
| 88 |
UNUSED(g); |
| 89 |
char s[256]; |
| 90 |
const int *playerUID = data; |
| 91 |
const int y = pos.y + size.y - FontH(); |
| 92 |
|
| 93 |
UNUSED(menu); |
| 94 |
|
| 95 |
const PlayerData *pData = PlayerDataGetByUID(*playerUID); |
| 96 |
char directionNames[256]; |
| 97 |
InputGetDirectionNames( |
| 98 |
directionNames, pData->inputDevice, pData->deviceIndex); |
| 99 |
switch (pData->inputDevice) |
| 100 |
{ |
| 101 |
case INPUT_DEVICE_KEYBOARD: |
| 102 |
{ |
| 103 |
char button1[256], button2[256]; |
| 104 |
InputGetButtonName( |
| 105 |
pData->inputDevice, pData->deviceIndex, CMD_BUTTON1, button1); |
| 106 |
InputGetButtonName( |
| 107 |
pData->inputDevice, pData->deviceIndex, CMD_BUTTON2, button2); |
| 108 |
sprintf(s, "(%s,\n%s and %s)", directionNames, button1, button2); |
| 109 |
FontStr(s, svec2i(pos.x - FontStrW(s) / 2, y - FontH())); |
| 110 |
} |
| 111 |
break; |
| 112 |
case INPUT_DEVICE_JOYSTICK: |
| 113 |
{ |
| 114 |
sprintf(s, "(%s,", |
| 115 |
InputDeviceName(pData->inputDevice, pData->deviceIndex)); |
| 116 |
struct vec2i textPos = svec2i(pos.x - FontStrW(s) / 2, y - FontH()); |
| 117 |
FontStr(s, textPos); |
| 118 |
textPos.y += FontH(); |
| 119 |
color_t c = colorWhite; |
| 120 |
InputGetButtonNameColor( |
| 121 |
pData->inputDevice, pData->deviceIndex, CMD_BUTTON1, s, &c); |
| 122 |
textPos = FontStrMask(s, textPos, c); |
| 123 |
textPos = FontStr(" and ", textPos); |
| 124 |
c = colorWhite; |
| 125 |
InputGetButtonNameColor( |
| 126 |
pData->inputDevice, pData->deviceIndex, CMD_BUTTON2, s, &c); |
| 127 |
textPos = FontStrMask(s, textPos, c); |
| 128 |
FontStr(")", textPos); |
| 129 |
} |
| 130 |
break; |
| 131 |
case INPUT_DEVICE_AI: |
| 132 |
sprintf(s, "(%s)", |
| 133 |
InputDeviceName(pData->inputDevice, pData->deviceIndex)); |
| 134 |
FontStr(s, svec2i(pos.x - FontStrW(s) / 2, y)); |
| 135 |
break; |
| 136 |
case INPUT_DEVICE_UNSET: |
| 137 |
strcpy(s, "(no device; plug in a controller)"); |
| 138 |
FontStr(s, svec2i(pos.x - FontStrW(s) / 2, y)); |
| 139 |
break; |
| 140 |
default: |
| 141 |
CASSERT(false, "unknown device"); |
| 142 |
break; |
| 143 |
} |
| 144 |
} |