Esempio n. 1
0
bool ConfirmScreen(const char *info, const char *msg)
{
	int w = gGraphicsDevice.cachedConfig.Res.x;
	int h = gGraphicsDevice.cachedConfig.Res.y;
	ClearScreen(&gGraphicsDevice);
	TextString(&gTextManager,
		info,
		&gGraphicsDevice,
		Vec2iNew((w - TextGetStringWidth(info)) / 2, (h - CDogsTextHeight()) / 2));
	TextString(&gTextManager,
		msg,
		&gGraphicsDevice,
		Vec2iNew((w - TextGetStringWidth(msg)) / 2, (h + CDogsTextHeight()) / 2));
	BlitFlip(&gGraphicsDevice, &gConfig.Graphics);

	int c = GetKey(&gEventHandlers);
	return (c == 'Y' || c == 'y');
}
Esempio n. 2
0
static void DrawAIChatter(const DrawBuffer *b, const Vec2i offset)
{
	Vec2i pos;
	const Tile *tile = &b->tiles[0][0];
	pos.y = b->dy + cWallOffset.dy + offset.y;
	for (int y = 0; y < Y_TILES; y++, pos.y += TILE_HEIGHT)
	{
		pos.x = b->dx + cWallOffset.dx + offset.x;
		for (int x = 0; x < b->Size.x; x++, tile++, pos.x += TILE_WIDTH)
		{
			if (!(tile->flags & MAPTILE_OUT_OF_SIGHT))
			{
				// Draw the items that are in LOS
				for (int i = 0; i < (int)tile->things.size; i++)
				{
					const ThingId *tid = CArrayGet(&tile->things, i);
					if (tid->Kind != KIND_CHARACTER)
					{
						continue;
					}
					const TActor *a = CArrayGet(&gActors, tid->Id);
					if (!a->aiContext)
					{
						continue;
					}
					const char *text =
						AIStateGetChatterText(a->aiContext->State);
					Vec2i textPos = Vec2iNew(
						a->tileItem.x - b->xTop + offset.x -
							TextGetStringWidth(text) / 2,
						a->tileItem.y - b->yTop + offset.y - ACTOR_HEIGHT);
					TextString(
						&gTextManager,
						AIStateGetChatterText(a->aiContext->State),
						b->g,
						textPos);
				}
			}
		}
		tile += X_TILES - b->Size.x;
	}
}
Esempio n. 3
0
void MenuDisplaySubmenus(MenuSystem *ms)
{
	int i;
	int x = 0, yStart = 0;
	int maxWidth = 0;
	menu_t *menu = ms->current;

	switch (menu->type)
	{
	// TODO: refactor the three menu types (normal, options, campaign) into one
	case MENU_TYPE_NORMAL:
	case MENU_TYPE_OPTIONS:
		{
			int isCentered = menu->type == MENU_TYPE_NORMAL;
			int xOptions;
			for (i = 0; i < menu->u.normal.numSubMenus; i++)
			{
				int width = TextGetStringWidth(menu->u.normal.subMenus[i].name);
				if (width > maxWidth)
				{
					maxWidth = width;
				}
			}
			switch (ms->align)
			{
			case MENU_ALIGN_CENTER:
				x = MS_CENTER_X(*ms, maxWidth);
				if (!isCentered)
				{
					x -= 20;
				}
				break;
			case MENU_ALIGN_LEFT:
				x = ms->pos.x;
				break;
			default:
				assert(0 && "unknown alignment");
				break;
			}
			yStart = MS_CENTER_Y(
				*ms, menu->u.normal.numSubMenus * CDogsTextHeight());
			xOptions = x + maxWidth + 10;

			// Display normal menu items
			for (i = 0; i < menu->u.normal.numSubMenus; i++)
			{
				int y = yStart + i * CDogsTextHeight();
				menu_t *subMenu = &menu->u.normal.subMenus[i];

				// Display menu item
				const char *name = subMenu->name;
				if (i == menu->u.normal.index)
				{
					DrawTextStringMasked(name, ms->graphics, Vec2iNew(x, y), colorRed);
				}
				else if (subMenu->isDisabled)
				{
					color_t dark = { 64, 64, 64, 255 };
					DrawTextStringMasked(name, ms->graphics, Vec2iNew(x, y), dark);
				}
				else
				{
					DrawTextString(name, ms->graphics, Vec2iNew(x, y));
				}

				// display option value
				if (subMenu->type == MENU_TYPE_SET_OPTION_TOGGLE ||
					subMenu->type == MENU_TYPE_SET_OPTION_RANGE ||
					subMenu->type == MENU_TYPE_SET_OPTION_SEED ||
					subMenu->type == MENU_TYPE_SET_OPTION_UP_DOWN_VOID_FUNC_VOID ||
					subMenu->type == MENU_TYPE_SET_OPTION_RANGE_GET_SET ||
					subMenu->type == MENU_TYPE_VOID_FUNC_VOID)
				{
					int optionInt = MenuOptionGetIntValue(subMenu);
					switch (subMenu->u.option.displayStyle)
					{
					case MENU_OPTION_DISPLAY_STYLE_INT:
						CDogsTextIntAt(xOptions, y, optionInt);
						break;
					case MENU_OPTION_DISPLAY_STYLE_YES_NO:
						CDogsTextStringAt(xOptions, y, optionInt ? "Yes" : "No");
						break;
					case MENU_OPTION_DISPLAY_STYLE_ON_OFF:
						CDogsTextStringAt(xOptions, y, optionInt ? "On" : "Off");
						break;
					case MENU_OPTION_DISPLAY_STYLE_STR_FUNC:
						CDogsTextStringAt(xOptions, y, subMenu->u.option.uFunc.str());
						break;
					case MENU_OPTION_DISPLAY_STYLE_INT_TO_STR_FUNC:
						CDogsTextStringAt(xOptions, y, subMenu->u.option.uFunc.intToStr(optionInt));
						break;
					default:
						break;
					}
				}
			}
		}
		break;
	case MENU_TYPE_CAMPAIGNS:
		{
			int y = MS_CENTER_Y(*ms, 12 * CDogsTextHeight());

		#define ARROW_UP	"\036"
		#define ARROW_DOWN	"\037"

			if (menu->u.normal.scroll != 0)
			{
				DisplayMenuItem(
					MS_CENTER_X(*ms, TextGetStringWidth(ARROW_UP)),
					y - 2 - CDogsTextHeight(),
					ARROW_UP,
					0);
			}

			for (i = menu->u.normal.scroll;
				i < MIN(menu->u.normal.scroll + 12, menu->u.normal.numSubMenus);
				i++)
			{
				int isSelected = i == menu->u.normal.index;
				menu_t *subMenu = &menu->u.normal.subMenus[i];
				const char *name = subMenu->name;
				// TODO: display subfolders
				DisplayMenuItem(
					MS_CENTER_X(*ms, TextGetStringWidth(name)),
					y,
					name,
					isSelected);

				if (isSelected && subMenu->type == MENU_TYPE_CAMPAIGN_ITEM)
				{
					char s[255];
					const char *filename = subMenu->u.campaign.filename;
					int isBuiltin = subMenu->u.campaign.isBuiltin;
					sprintf(s, "( %s )", isBuiltin ? "Internal" : filename);
					DrawTextStringSpecial(
						s,
						TEXT_XCENTER | TEXT_BOTTOM,
						ms->pos,
						ms->size,
						Vec2iNew(ms->size.x / 12, 0));
				}

				y += CDogsTextHeight();
			}

			if (i < menu->u.normal.numSubMenus - 1)
			{
				DisplayMenuItem(
					MS_CENTER_X(*ms, TextGetStringWidth(ARROW_DOWN)),
					y + 2,
					ARROW_DOWN,
					0);
			}
		}
		break;
	case MENU_TYPE_KEYS:
		{
			int xKeys;
			x = MS_CENTER_X(*ms, (CDogsTextCharWidth('a') * 10)) / 2;
			xKeys = x * 3;
			yStart = (gGraphicsDevice.cachedConfig.ResolutionHeight / 2) - (CDogsTextHeight() * 10);

			for (i = 0; i < menu->u.normal.numSubMenus; i++)
			{
				int y = yStart + i * CDogsTextHeight();
				int isSelected = i == menu->u.normal.index;
				menu_t *subMenu = &menu->u.normal.subMenus[i];

				const char *name = subMenu->name;
				if (isSelected &&
					subMenu->type != MENU_TYPE_SET_OPTION_CHANGE_KEY)
				{
					CDogsTextStringWithTableAt(x, y, name, &tableFlamed);
				}
				else
				{
					CDogsTextStringAt(x, y, name);
				}

				if (subMenu->type == MENU_TYPE_SET_OPTION_CHANGE_KEY)
				{
					const char *keyName;
					if (menu->u.normal.changeKeyMenu == subMenu)
					{
						keyName = "Press a key";
					}
					else if (subMenu->u.changeKey.code == KEY_CODE_MAP)
					{
						keyName = SDL_GetKeyName(gConfig.Input.PlayerKeys[0].Keys.map);
					}
					else
					{
						keyName = SDL_GetKeyName(InputGetKey(
							subMenu->u.changeKey.keys,
							subMenu->u.changeKey.code));
					}
					DisplayMenuItem(xKeys, y, keyName, isSelected);
				}
			}
		}
		break;
	default:
		// No submenus, don't display anything
		break;
	}
}