mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-11 12:33:25 -08:00
Extract GameCreationOptions from DlgCreateGame
This commit is contained in:
parent
7487a383a3
commit
fae49848b3
6 changed files with 192 additions and 16 deletions
|
|
@ -216,6 +216,7 @@ set(cockatrice_SOURCES
|
|||
src/interface/widgets/deck_editor/deck_state_manager.cpp
|
||||
src/interface/widgets/deck_editor/deck_zone_dialog.cpp
|
||||
src/interface/widgets/deck_editor/printing_disabled_info_widget.cpp
|
||||
src/interface/widgets/game_hosting/game_creation_options.cpp
|
||||
src/interface/widgets/general/background_sources.cpp
|
||||
src/interface/widgets/general/display/background_plate_widget.cpp
|
||||
src/interface/widgets/general/display/banner_widget.cpp
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "dlg_create_game.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../interface/widgets/game_hosting/game_creation_options.h"
|
||||
#include "../interface/widgets/tabs/tab_room.h"
|
||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||
#include "libcockatrice/protocol/pb/room_commands.pb.h"
|
||||
|
|
@ -287,32 +288,34 @@ void DlgCreateGame::actReset()
|
|||
|
||||
void DlgCreateGame::actOK()
|
||||
{
|
||||
Command_CreateGame cmd;
|
||||
cmd.set_description(descriptionEdit->text().simplified().toStdString());
|
||||
cmd.set_password(passwordEdit->text().toStdString());
|
||||
cmd.set_max_players(maxPlayersEdit->value());
|
||||
cmd.set_only_buddies(onlyBuddiesCheckBox->isChecked());
|
||||
cmd.set_only_registered(onlyRegisteredCheckBox->isChecked());
|
||||
cmd.set_spectators_allowed(spectatorsAllowedCheckBox->isChecked());
|
||||
cmd.set_spectators_need_password(spectatorsNeedPasswordCheckBox->isChecked());
|
||||
cmd.set_spectators_can_talk(spectatorsCanTalkCheckBox->isChecked());
|
||||
cmd.set_spectators_see_everything(spectatorsSeeEverythingCheckBox->isChecked());
|
||||
cmd.set_join_as_judge(createGameAsJudgeCheckBox->isChecked());
|
||||
cmd.set_join_as_spectator(createGameAsSpectatorCheckBox->isChecked());
|
||||
cmd.set_starting_life_total(startingLifeTotalEdit->value());
|
||||
cmd.set_share_decklists_on_load(shareDecklistsOnLoadCheckBox->isChecked());
|
||||
cmd.set_shuffle_players(shufflePlayersCheckBox->isChecked());
|
||||
GameCreationOptions options;
|
||||
options.description = descriptionEdit->text();
|
||||
options.password = passwordEdit->text();
|
||||
options.maxPlayers = maxPlayersEdit->value();
|
||||
options.onlyBuddies = onlyBuddiesCheckBox->isChecked();
|
||||
options.onlyRegistered = onlyRegisteredCheckBox->isChecked();
|
||||
options.spectatorsAllowed = spectatorsAllowedCheckBox->isChecked();
|
||||
options.spectatorsNeedPassword = spectatorsNeedPasswordCheckBox->isChecked();
|
||||
options.spectatorsCanTalk = spectatorsCanTalkCheckBox->isChecked();
|
||||
options.spectatorsSeeEverything = spectatorsSeeEverythingCheckBox->isChecked();
|
||||
options.joinAsJudge = createGameAsJudgeCheckBox->isChecked();
|
||||
options.joinAsSpectator = createGameAsSpectatorCheckBox->isChecked();
|
||||
options.startingLifeTotal = startingLifeTotalEdit->value();
|
||||
options.shareDecklistsOnLoad = shareDecklistsOnLoadCheckBox->isChecked();
|
||||
options.shufflePlayers = shufflePlayersCheckBox->isChecked();
|
||||
|
||||
auto _gameTypes = QString();
|
||||
QMapIterator<int, QRadioButton *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
|
||||
while (gameTypeCheckBoxIterator.hasNext()) {
|
||||
gameTypeCheckBoxIterator.next();
|
||||
if (gameTypeCheckBoxIterator.value()->isChecked()) {
|
||||
cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
|
||||
options.gameTypeIds.append(gameTypeCheckBoxIterator.key());
|
||||
_gameTypes += gameTypeCheckBoxIterator.value()->text() + ", ";
|
||||
}
|
||||
}
|
||||
|
||||
Command_CreateGame cmd = options.toCreateGameCommand();
|
||||
|
||||
SettingsCache::instance().game().setRememberGameSettings(rememberGameSettings->isChecked());
|
||||
if (rememberGameSettings->isChecked()) {
|
||||
SettingsCache::instance().game().setGameDescription(descriptionEdit->text());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#include "game_creation_options.h"
|
||||
|
||||
Command_CreateGame GameCreationOptions::toCreateGameCommand() const
|
||||
{
|
||||
Command_CreateGame cmd;
|
||||
cmd.set_description(description.simplified().toStdString());
|
||||
cmd.set_password(password.toStdString());
|
||||
cmd.set_max_players(maxPlayers);
|
||||
cmd.set_only_buddies(onlyBuddies);
|
||||
cmd.set_only_registered(onlyRegistered);
|
||||
cmd.set_spectators_allowed(spectatorsAllowed);
|
||||
cmd.set_spectators_need_password(spectatorsNeedPassword);
|
||||
cmd.set_spectators_can_talk(spectatorsCanTalk);
|
||||
cmd.set_spectators_see_everything(spectatorsSeeEverything);
|
||||
cmd.set_join_as_judge(joinAsJudge);
|
||||
cmd.set_join_as_spectator(joinAsSpectator);
|
||||
cmd.set_starting_life_total(startingLifeTotal);
|
||||
cmd.set_share_decklists_on_load(shareDecklistsOnLoad);
|
||||
cmd.set_shuffle_players(shufflePlayers);
|
||||
for (int gameTypeId : gameTypeIds) {
|
||||
cmd.add_game_type_ids(gameTypeId);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* @file game_creation_options.h
|
||||
* @ingroup RoomWidgets
|
||||
*/
|
||||
|
||||
#ifndef GAME_CREATION_OPTIONS_H
|
||||
#define GAME_CREATION_OPTIONS_H
|
||||
|
||||
#include "libcockatrice/protocol/pb/room_commands.pb.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* @brief The values needed to create a game, independent of the widgets that edit them.
|
||||
*
|
||||
* Pure value object: it holds no widget or settings dependencies, so every host entry
|
||||
* point can build a @ref Command_CreateGame through the same conversion.
|
||||
*/
|
||||
struct GameCreationOptions
|
||||
{
|
||||
QString description;
|
||||
QString password;
|
||||
int maxPlayers = 2;
|
||||
bool onlyBuddies = false;
|
||||
bool onlyRegistered = false;
|
||||
bool spectatorsAllowed = true;
|
||||
bool spectatorsNeedPassword = false;
|
||||
bool spectatorsCanTalk = false;
|
||||
bool spectatorsSeeEverything = false;
|
||||
bool joinAsJudge = false;
|
||||
bool joinAsSpectator = false;
|
||||
int startingLifeTotal = 20;
|
||||
bool shareDecklistsOnLoad = false;
|
||||
bool shufflePlayers = false;
|
||||
QList<int> gameTypeIds;
|
||||
|
||||
/**
|
||||
* @brief Builds the room command, simplifying the description's whitespace.
|
||||
*/
|
||||
[[nodiscard]] Command_CreateGame toCreateGameCommand() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue