Example #1
0
void MenuProcessChangeKey(menu_t *menu)
{
	int key = GetKey(&gEventHandlers);	// wait until user has pressed a new button

	if (key == SDLK_ESCAPE)
	{
		MenuPlaySound(MENU_SOUND_BACK);
	}
	else if (KeyAvailable(
		key,
		menu->u.normal.changeKeyMenu->u.changeKey.code,
		menu->u.normal.changeKeyMenu->u.changeKey.keys,
		menu->u.normal.changeKeyMenu->u.changeKey.keysOther))
	{
		if (menu->u.normal.changeKeyMenu->u.changeKey.code != KEY_CODE_MAP)
		{
			InputSetKey(
				menu->u.normal.changeKeyMenu->u.changeKey.keys,
				key,
				menu->u.normal.changeKeyMenu->u.changeKey.code);
		}
		else
		{
			gConfig.Input.PlayerKeys[0].Keys.map = key;
		}
		MenuPlaySound(MENU_SOUND_ENTER);
	}
	else
	{
		MenuPlaySound(MENU_SOUND_ERROR);
	}
	menu->u.normal.changeKeyMenu = NULL;
}
Example #2
0
void MenuProcessCmd(MenuSystem *ms, int cmd)
{
	menu_t *menu = ms->current;
	menu_t *menuToChange = NULL;
	if (cmd == CMD_ESC || (cmd & CMD_BUTTON2) ||
		((cmd & CMD_LEFT) && menu->u.normal.isSubmenusAlt))
	{
		menuToChange = MenuProcessEscCmd(menu);
		if (menuToChange != NULL)
		{
			MenuPlaySound(MENU_SOUND_BACK);
			ms->current = menuToChange;
			goto bail;
		}
	}
	if (menu->type == MENU_TYPE_CUSTOM)
	{
		if (menu->u.customData.inputFunc(cmd, menu->u.customData.data))
		{
			ms->current = menu->parentMenu;
			goto bail;
		}
	}
	else
	{
		menuToChange = MenuProcessButtonCmd(ms, menu, cmd);
		if (menuToChange != NULL)
		{
			debug(D_VERBOSE, "change to menu type %d\n", menuToChange->type);
			if (menuToChange->type == MENU_TYPE_CAMPAIGN_ITEM)
			{
				MenuPlaySound(MENU_SOUND_START);
			}
			else
			{
				MenuPlaySound(MENU_SOUND_ENTER);
			}
			ms->current = menuToChange;
			goto bail;
		}
		MenuChangeIndex(menu, cmd);
	}

bail:
	if (menu->customPostInputFunc)
	{
		menu->customPostInputFunc(menu, cmd, menu->customPostInputData);
	}
	if (menuToChange && menuToChange->customPostEnterFunc)
	{
		menuToChange->customPostEnterFunc(
			menuToChange, menuToChange->customPostEnterData);
	}
}
Example #3
0
void MenuChangeIndex(menu_t *menu, int cmd)
{
	// Ignore if no submenus
	if (menu->u.normal.subMenus.size == 0)
	{
		return;
	}

	if (Up(cmd))
	{
		menu->u.normal.index--;
		if (menu->u.normal.index == -1)
		{
			menu->u.normal.index = (int)menu->u.normal.subMenus.size - 1;
		}
		MoveIndexToNextEnabledSubmenu(menu, 0);
		MenuPlaySound(MENU_SOUND_SWITCH);
	}
	else if (Down(cmd))
	{
		menu->u.normal.index++;
		if (menu->u.normal.index == (int)menu->u.normal.subMenus.size)
		{
			menu->u.normal.index = 0;
		}
		MoveIndexToNextEnabledSubmenu(menu, 1);
		MenuPlaySound(MENU_SOUND_SWITCH);
	}
	menu->u.normal.scroll =
		CLAMP(menu->u.normal.scroll,
			MAX(0, menu->u.normal.index - menu->u.normal.maxItems + 1),
			MIN((int)menu->u.normal.subMenus.size - 1, menu->u.normal.index + menu->u.normal.maxItems - 1));
	if (menu->u.normal.index < menu->u.normal.scroll)
	{
		menu->u.normal.scroll = menu->u.normal.index;
	}
}
Example #4
0
void MenuChangeIndex(menu_t *menu, int cmd)
{
	int leftRightMoves = MenuTypeLeftRightMoves(menu->type);
	if (Up(cmd) || (leftRightMoves && Left(cmd)))
	{
		do
		{
			menu->u.normal.index--;
			if (menu->u.normal.index < 0)
			{
				menu->u.normal.index = menu->u.normal.numSubMenus - 1;
			}
		} while (menu->u.normal.subMenus[menu->u.normal.index].isDisabled);
		MenuPlaySound(MENU_SOUND_SWITCH);
	}
	else if (Down(cmd) || (leftRightMoves && Right(cmd)))
	{
		do
		{
			menu->u.normal.index++;
			if (menu->u.normal.index >= menu->u.normal.numSubMenus)
			{
				menu->u.normal.index = 0;
			}
		} while (menu->u.normal.subMenus[menu->u.normal.index].isDisabled);
		MenuPlaySound(MENU_SOUND_SWITCH);
	}
	menu->u.normal.scroll =
		CLAMP(menu->u.normal.scroll,
			MAX(0, menu->u.normal.index - 11),
			MIN(menu->u.normal.numSubMenus - 1, menu->u.normal.index + 11));
	if (menu->u.normal.index < menu->u.normal.scroll)
	{
		menu->u.normal.scroll = menu->u.normal.index;
	}
}
Example #5
0
menu_t *MenuProcessEscCmd(menu_t *menu)
{
	menu_t *menuToChange = NULL;
	int quitMenuIndex = menu->u.normal.quitMenuIndex;
	if (quitMenuIndex != -1)
	{
		if (menu->u.normal.index != quitMenuIndex)
		{
			MenuPlaySound(MENU_SOUND_SWITCH);
			menu->u.normal.index = quitMenuIndex;
		}
		else if (menu->u.normal.subMenus.size > 0)
		{
			menuToChange = CArrayGet(&menu->u.normal.subMenus, quitMenuIndex);
		}
	}
	else
	{
		menuToChange = menu->parentMenu;
	}
	return menuToChange;
}
Example #6
0
static int HandleInputNameMenu(int cmd, void *data)
{
	PlayerSelectMenuData *d = data;
	struct PlayerData *p = d->display.pData;

	if (cmd & CMD_BUTTON1)
	{
		if (d->nameMenuSelection == (int)strlen(letters))
		{
			MenuPlaySound(MENU_SOUND_ENTER);
			return 1;
		}

		if (strlen(p->name) < sizeof p->name - 1)
		{
			size_t l = strlen(p->name);
			p->name[l + 1] = 0;
			if (l > 0 && p->name[l - 1] != ' ')
			{
				p->name[l] = smallLetters[d->nameMenuSelection];
			}
			else
			{
				p->name[l] = letters[d->nameMenuSelection];
			}
			MenuPlaySound(MENU_SOUND_ENTER);
		}
		else
		{
			MenuPlaySound(MENU_SOUND_ERROR);
		}
	}
	else if (cmd & CMD_BUTTON2)
	{
		if (p->name[0])
		{
			p->name[strlen(p->name) - 1] = 0;
			MenuPlaySound(MENU_SOUND_BACK);
		}
		else
		{
			MenuPlaySound(MENU_SOUND_ERROR);
		}
	}
	else if (cmd & CMD_LEFT)
	{
		if (d->nameMenuSelection > 0)
		{
			d->nameMenuSelection--;
			MenuPlaySound(MENU_SOUND_SWITCH);
		}
	}
	else if (cmd & CMD_RIGHT)
	{
		if (d->nameMenuSelection < (int)strlen(letters))
		{
			d->nameMenuSelection++;
			MenuPlaySound(MENU_SOUND_SWITCH);
		}
	}
	else if (cmd & CMD_UP)
	{
		if (d->nameMenuSelection >= ENTRY_COLS)
		{
			d->nameMenuSelection -= ENTRY_COLS;
			MenuPlaySound(MENU_SOUND_SWITCH);
		}
	}
	else if (cmd & CMD_DOWN)
	{
		if (d->nameMenuSelection <= (int)strlen(letters) - ENTRY_COLS)
		{
			d->nameMenuSelection += ENTRY_COLS;
			MenuPlaySound(MENU_SOUND_SWITCH);
		}
		else if (d->nameMenuSelection < (int)strlen(letters))
		{
			d->nameMenuSelection = (int)strlen(letters);
			MenuPlaySound(MENU_SOUND_SWITCH);
		}
	}

	return 0;
}
Example #7
0
void MenuActivate(MenuSystem *ms, menu_t *menu, int cmd)
{
	UNUSED(ms);
	MenuPlaySound(MENU_SOUND_SWITCH);
	switch (menu->type)
	{
	case MENU_TYPE_BASIC:
		// do nothing
		return;
	case MENU_TYPE_SET_OPTION_TOGGLE:
		*menu->u.option.uHook.optionToggle = !*menu->u.option.uHook.optionToggle;
		break;
	case MENU_TYPE_SET_OPTION_RANGE:
		{
			int option = *menu->u.option.uHook.optionRange.option;
			int increment = menu->u.option.uHook.optionRange.increment;
			int low = menu->u.option.uHook.optionRange.low;
			int high = menu->u.option.uHook.optionRange.high;
			if (Left(cmd))
			{
				if (low == option)
				{
					option = high;
				}
				else if (low + increment > option)
				{
					option = low;
				}
				else
				{
					option -= increment;
				}
			}
			else if (Right(cmd))
			{
				if (high == option)
				{
					option = low;
				}
				else if (high - increment < option)
				{
					option = high;
				}
				else
				{
					option += increment;
				}
			}
			*menu->u.option.uHook.optionRange.option = option;
		}
		break;
	case MENU_TYPE_SET_OPTION_SEED:
		{
			unsigned int seed = *menu->u.option.uHook.seed;
			unsigned int increment = 1;
			if (Button1(cmd))
			{
				increment *= 10;
			}
			if (Button2(cmd))
			{
				increment *= 100;
			}
			if (Left(cmd))
			{
				if (increment > seed)
				{
					seed = 0;
				}
				else
				{
					seed -= increment;
				}
			}
			else if (Right(cmd))
			{
				if (UINT_MAX - increment < seed)
				{
					seed = UINT_MAX;
				}
				else
				{
					seed += increment;
				}
			}
			*menu->u.option.uHook.seed = seed;
		}
		break;
	case MENU_TYPE_SET_OPTION_UP_DOWN_VOID_FUNC_VOID:
		if (Left(cmd))
		{
			menu->u.option.uHook.upDownFuncs.upFunc();
		}
		else if (Right(cmd))
		{
			menu->u.option.uHook.upDownFuncs.downFunc();
		}
		break;
	case MENU_TYPE_SET_OPTION_RANGE_GET_SET:
		{
			int option = menu->u.option.uHook.optionRangeGetSet.getFunc();
			int increment = menu->u.option.uHook.optionRangeGetSet.increment;
			if (Left(cmd))
			{
				if (menu->u.option.uHook.optionRangeGetSet.low + increment > option)
				{
					option = menu->u.option.uHook.optionRangeGetSet.low;
				}
				else
				{
					option -= increment;
				}
			}
			else if (Right(cmd))
			{
				if (menu->u.option.uHook.optionRangeGetSet.high - increment < option)
				{
					option = menu->u.option.uHook.optionRangeGetSet.high;
				}
				else
				{
					option += increment;
				}
			}
			menu->u.option.uHook.optionRangeGetSet.setFunc(option);
		}
		break;
	case MENU_TYPE_VOID_FUNC:
		menu->u.option.uHook.voidFunc.func(menu->u.option.uHook.voidFunc.data);
		break;
	case MENU_TYPE_SET_OPTION_CHANGE_KEY:
		menu->parentMenu->u.normal.changeKeyMenu = menu;
		break;
	default:
		printf("Error unhandled menu type %d\n", menu->type);
		assert(0);
		break;
	}
}
Example #8
0
static void WeaponSelect(menu_t *menu, int cmd, void *data)
{
	WeaponMenuData *d = data;
	PlayerData *p = PlayerDataGetByUID(d->display.PlayerUID);
	const CArray *weapons = &gMission.Weapons;

	// Don't process if we're not selecting a weapon
	if ((cmd & CMD_BUTTON1) && menu->u.normal.index < (int)weapons->size)
	{
		// Add the selected weapon

		// Check that the weapon hasn't been chosen yet
		const GunDescription **selectedWeapon =
			CArrayGet(weapons, menu->u.normal.index);
		for (int i = 0; i < p->weaponCount; i++)
		{
			if (p->weapons[i] == *selectedWeapon)
			{
				return;
			}
		}

		// Check that there are empty slots to add weapons
		if (p->weaponCount == MAX_WEAPONS)
		{
			return;
		}

		p->weapons[p->weaponCount] = *selectedWeapon;
		p->weaponCount++;
		SoundPlay(&gSoundDevice, (*selectedWeapon)->SwitchSound);

		// Note: need to enable before disabling otherwise
		// menu index is not updated properly

		// Enable "Done" menu item
		MenuEnableSubmenu(menu, (int)menu->u.normal.subMenus.size - 1);

		// Disable this menu entry
		MenuDisableSubmenu(menu, menu->u.normal.index);
	}
	else if (cmd & CMD_BUTTON2)
	{
		// Remove a weapon
		if (p->weaponCount > 0)
		{
			p->weaponCount--;
			MenuPlaySound(MENU_SOUND_BACK);

			// Re-enable the menu entry for this weapon
			const GunDescription *removedWeapon = p->weapons[p->weaponCount];
			for (int i = 0; i < (int)weapons->size; i++)
			{
				const GunDescription **g = CArrayGet(weapons, i);
				if (*g == removedWeapon)
				{
					MenuEnableSubmenu(menu, i);
					break;
				}
			}
		}

		// Disable "Done" if no weapons selected
		if (p->weaponCount == 0)
		{
			MenuDisableSubmenu(menu, (int)menu->u.normal.subMenus.size - 1);
		}
	}
}
Example #9
0
void MenuActivate(MenuSystem *ms, menu_t *menu, int cmd)
{
	Config lastConfig = gConfig;
	MenuPlaySound(MENU_SOUND_SWITCH);
	switch (menu->type)
	{
	case MENU_TYPE_BASIC:
		// do nothing
		// TODO: change ConfigApply to a custom hook
		return;
	case MENU_TYPE_SET_OPTION_TOGGLE:
		*menu->u.option.uHook.optionToggle = !*menu->u.option.uHook.optionToggle;
		break;
	case MENU_TYPE_SET_OPTION_RANGE:
		{
			int option = *menu->u.option.uHook.optionRange.option;
			int increment = menu->u.option.uHook.optionRange.increment;
			int low = menu->u.option.uHook.optionRange.low;
			int high = menu->u.option.uHook.optionRange.high;
			if (Left(cmd))
			{
				if (low == option)
				{
					option = high;
				}
				else if (low + increment > option)
				{
					option = low;
				}
				else
				{
					option -= increment;
				}
			}
			else if (Right(cmd))
			{
				if (high == option)
				{
					option = low;
				}
				else if (high - increment < option)
				{
					option = high;
				}
				else
				{
					option += increment;
				}
			}
			*menu->u.option.uHook.optionRange.option = option;
		}
		break;
	case MENU_TYPE_SET_OPTION_SEED:
		{
			unsigned int seed = *menu->u.option.uHook.seed;
			unsigned int increment = 1;
			if (Button1(cmd))
			{
				increment *= 10;
			}
			if (Button2(cmd))
			{
				increment *= 100;
			}
			if (Left(cmd))
			{
				if (increment > seed)
				{
					seed = 0;
				}
				else
				{
					seed -= increment;
				}
			}
			else if (Right(cmd))
			{
				if (UINT_MAX - increment < seed)
				{
					seed = UINT_MAX;
				}
				else
				{
					seed += increment;
				}
			}
			*menu->u.option.uHook.seed = seed;
		}
		break;
	case MENU_TYPE_SET_OPTION_UP_DOWN_VOID_FUNC_VOID:
		if (Left(cmd))
		{
			menu->u.option.uHook.upDownFuncs.upFunc();
		}
		else if (Right(cmd))
		{
			menu->u.option.uHook.upDownFuncs.downFunc();
		}
		break;
	case MENU_TYPE_SET_OPTION_RANGE_GET_SET:
		{
			int option = menu->u.option.uHook.optionRangeGetSet.getFunc();
			int increment = menu->u.option.uHook.optionRangeGetSet.increment;
			if (Left(cmd))
			{
				if (menu->u.option.uHook.optionRangeGetSet.low + increment > option)
				{
					option = menu->u.option.uHook.optionRangeGetSet.low;
				}
				else
				{
					option -= increment;
				}
			}
			else if (Right(cmd))
			{
				if (menu->u.option.uHook.optionRangeGetSet.high - increment < option)
				{
					option = menu->u.option.uHook.optionRangeGetSet.high;
				}
				else
				{
					option += increment;
				}
			}
			menu->u.option.uHook.optionRangeGetSet.setFunc(option);
		}
		break;
	case MENU_TYPE_VOID_FUNC_VOID:
		menu->u.option.uHook.toggleFuncs.toggle();
		break;
	case MENU_TYPE_SET_OPTION_CHANGE_KEY:
		menu->parentMenu->u.normal.changeKeyMenu = menu;
		break;
	default:
		printf("Error unhandled menu type %d\n", menu->type);
		assert(0);
		break;
	}
	if (!ConfigApply(&gConfig))
	{
		printf("Error: cannot apply new config; applying last config\n");
		gConfig = lastConfig;
		if (!ConfigApply(&gConfig))
		{
			printf("Error: cannot apply last config!\n");
			exit(1);
		}
	}
	// Update menu system
	// Note: only for the main menu system!
	ms->pos = Vec2iZero();
	ms->size = Vec2iNew(
		ms->graphics->cachedConfig.ResolutionWidth,
		ms->graphics->cachedConfig.ResolutionHeight);
}