Example #1
0
int MissionDescription(int y, const char *description, int hilite)
{
	int w_ws, w_word, x, lines;
	const char *ws, *word, *p, *s;

	TextGoto(20 - TextCharWidth('\020'), y);
	if (hilite)
		TextCharWithTable('\020', tableFlamed);
	else
		TextChar('\020');

	x = 20;
	lines = 1;
	TextGoto(x, y);

	s = ws = word = description;
	while (*s) {
		// Find word
		ws = s;
		while (*s == ' ' || *s == '\n')
			s++;
		word = s;
		while (*s != 0 && *s != ' ' && *s != '\n')
			s++;

		for (w_ws = 0, p = ws; p < word; p++)
			w_ws += TextCharWidth(*p);
		for (w_word = 0; p < s; p++)
			w_word += TextCharWidth(*p);

		if (x + w_ws + w_word > 300 && w_ws + w_word < 280) {
			y += TextHeight();
			x = 20;
			lines++;
			ws = word;
			w_ws = 0;
		}

		x += w_ws;
		TextGoto(x, y);

		for (p = word; p < s; p++)
			TextChar(*p);

		x += w_word;
	}

	if (hilite)
		TextCharWithTable('\021', tableFlamed);
	else
		TextChar('\021');

	return lines;
}
Example #2
0
static void ShowAllKeys(int index, int change)
{
	int x1, x2, y1, y2;
	
	x1 = CenterX((TextCharWidth('a') * 10)) / 2;
	x2 = x1 * 3;
	
	y1 = (SCREEN_HEIGHT / 2) - (TextHeight() * 10);
	y2 = (SCREEN_HEIGHT / 2) - (TextHeight() * 2);
	
	DisplayKeys(x1, x2, y1, "Player One", &gPlayer1Data, index, change);
	DisplayKeys(x1, x2, y2, "Player Two", &gPlayer2Data, index - 6, change - 6);
	
	y2 += TextHeight() * 8;
	
	TextStringAt(x1, y2, "Map");
	
	if (change == 12)
		DisplayMenuItem(x2, y2, SELECTKEY, index == 12);
	else
		DisplayMenuItem(x2, y2, SDL_GetKeyName(gOptions.mapKey), index == 12);
	
#define DONE	"Done"
	
	y2 += TextHeight () * 2;
	
	DisplayMenuItem(CenterX(TextWidth(DONE)), y2, DONE, index == 13);
}
Example #3
0
int TextWidth(const char *s)
{
    int w = 0;

    while (*s)
        w += TextCharWidth(*s++);
    return w;
}
Example #4
0
static int NameSelection(int x, int index, struct PlayerData *data,
			 int cmd)
{
	int i;
	int y;

	char s[2];
	static char letters[] =
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ !#?:.-0123456789";
	static char smallLetters[] =
		"abcdefghijklmnopqrstuvwxyz !#?:.-0123456789";
	static int selection[2] = { -1, -1 };

	// Kludge since Watcom won't let me initialize selection with a strlen()
	if (selection[0] < 0)
		selection[0] = selection[1] = strlen(letters);

	if (cmd & CMD_BUTTON1) {
		if (selection[index] == strlen(letters)) {
			PlaySound(SND_LAUNCH, 0, 255);
			return 0;
		}

		if (strlen(data->name) < sizeof(data->name) - 1) {
			int l = strlen(data->name);
			data->name[l + 1] = 0;
			if (l > 0 && data->name[l - 1] != ' ')
				data->name[l] =
				    smallLetters[selection[index]];
			else
				data->name[l] = letters[selection[index]];
			PlaySound(SND_MACHINEGUN, 0, 255);
		} else
			PlaySound(SND_KILL, 0, 255);
	} else if (cmd & CMD_BUTTON2) {
		if (data->name[0]) {
			data->name[strlen(data->name) - 1] = 0;
			PlaySound(SND_BANG, 0, 255);
		} else
			PlaySound(SND_KILL, 0, 255);
	} else if (cmd & CMD_LEFT) {
		if (selection[index] > 0) {
			selection[index]--;
			PlaySound(SND_DOOR, 0, 255);
		}
	} else if (cmd & CMD_RIGHT) {
		if (selection[index] < strlen(letters)) {
			selection[index]++;
			PlaySound(SND_DOOR, 0, 255);
		}
	} else if (cmd & CMD_UP) {
		if (selection[index] > 9) {
			selection[index] -= 10;
			PlaySound(SND_DOOR, 0, 255);
		}
	} else if (cmd & CMD_DOWN) {
		if (selection[index] < strlen(letters) - 9) {
			selection[index] += 10;
			PlaySound(SND_DOOR, 0, 255);
		} else if (selection[index] < strlen(letters)) {
			selection[index] = strlen(letters);
			PlaySound(SND_DOOR, 0, 255);
		}
	}

	#define ENTRY_COLS	10
	#define	ENTRY_SPACING	12
	
	y = CenterY(((TextHeight() * ((strlen(letters) - 1) / ENTRY_COLS) )));

	if (gOptions.twoPlayers && index == CHARACTER_PLAYER1)
		x = CenterOf(0, (SCREEN_WIDTH / 2), ((ENTRY_SPACING * (ENTRY_COLS - 1)) + TextCharWidth('a')));
	else if (gOptions.twoPlayers && index == CHARACTER_PLAYER2)
		x = CenterOf((SCREEN_WIDTH / 2), (SCREEN_WIDTH), ((ENTRY_SPACING * (ENTRY_COLS - 1)) + TextCharWidth('a')));
	else
		x = CenterX(((ENTRY_SPACING * (ENTRY_COLS - 1)) + TextCharWidth('a')));

	// Draw selection

	s[1] = 0;
	for (i = 0; i < strlen(letters); i++) {
		s[0] = letters[i];

		TextGoto(x + (i % ENTRY_COLS) * ENTRY_SPACING,
			 y + (i / ENTRY_COLS) * TextHeight());

		if (i == selection[index])
			TextCharWithTable(letters[i], &tableFlamed);
		else
			TextChar(letters[i]);
/*
		DisplayMenuItem(x + (i % 10) * 12,
				80 + (i / 10) * TextHeight(), s,
				i == selection[index]);
*/
	}

	DisplayMenuItem(x + (i % ENTRY_COLS) * ENTRY_SPACING,
			y + (i / ENTRY_COLS) * TextHeight(),
			endChoice, i == selection[index]);

	return 1;
}