Example #1
0
bool NumPlayersSelection(GraphicsDevice *graphics, EventHandlers *handlers)
{
	MenuSystem ms;
	MenuSystemInit(
		&ms, handlers, graphics,
		Vec2iZero(),
		graphics->cachedConfig.Res);
	ms.allowAborts = true;
	ms.root = ms.current = MenuCreateNormal(
		"",
		"Select number of players",
		MENU_TYPE_NORMAL,
		0);
	MenuAddSubmenu(ms.current, MenuCreateReturn("(No local players)", 0));
	for (int i = 0; i < MAX_LOCAL_PLAYERS; i++)
	{
		char buf[2];
		sprintf(buf, "%d", i + 1);
		MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1));
	}
	MenuAddExitType(&ms, MENU_TYPE_RETURN);
	// Select 1 player default
	ms.current->u.normal.index = 1;

	MenuLoop(&ms);
	const bool ok = !ms.hasAbort;
	if (ok)
	{
		const int numPlayers = ms.current->u.returnCode;
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			CASSERT(!p->IsLocal, "unexpected local player");
		CA_FOREACH_END()
		// Add the players
		for (int i = 0; i < numPlayers; i++)
		{
			GameEvent e = GameEventNew(GAME_EVENT_PLAYER_DATA);
			e.u.PlayerData = PlayerDataDefault(i);
			e.u.PlayerData.UID = gNetClient.FirstPlayerUID + i;
			GameEventsEnqueue(&gGameEvents, e);
		}
		// Process the events to force add the players
		HandleGameEvents(&gGameEvents, NULL, NULL, NULL);
		// This also causes the client to send player data to the server
	}
	MenuSystemTerminate(&ms);
	return ok;
}
Example #2
0
	UNUSED(d); UNUSED(dIndex); return false;
}
PlayerTemplate *PlayerTemplateGetById(PlayerTemplates *pt, const int id)
{
	UNUSED(pt); UNUSED(id); return NULL;
}


FEATURE(assign_unused, "Assign unused input device")
	// This feature is used to assign input devices to players, before the game
	// begins. All input devices can emit the "fire" command, at which point
	// those input devices are assigned to the next unassigned player. This
	// lets us easily assign different input devices to different players,
	// regardless of the number and type of input devices and players.
	PlayerDataInit(&gPlayerDatas);
	NPlayerData pd = PlayerDataDefault(0);
	PlayerDataAddOrUpdate(pd);
	pd.UID = 1;
	PlayerDataAddOrUpdate(pd);
	SCENARIO("Assign device to unset player")
		GIVEN("a player with an unset input device")
			PlayerData *p = CArrayGet(&gPlayerDatas, 0);
			p->inputDevice = INPUT_DEVICE_UNSET;
		WHEN("I assign it with an input device")
			const input_device_e d = INPUT_DEVICE_KEYBOARD;
			const int idx = 0;
			bool res = PlayerTrySetUnusedInputDevice(p, d, idx);
		THEN("the assignment should succeed")
			SHOULD_BE_TRUE(res);
		AND("the player should have the input device set")
			SHOULD_INT_EQUAL((int)p->inputDevice, (int)d);