Author: mir3x Date: Sun Nov 1 18:46:12 2015 New Revision: 30346 URL: http://svn.gna.org/viewcvs/freeciv?rev=30346&view=rev Log: Added option to choose ai level, ai_fill, ruleset and rearranged button for more server options in PAGE_START in Qt-client.
See patch #6444 Modified: trunk/client/gui-qt/fc_client.cpp trunk/client/gui-qt/fc_client.h trunk/client/gui-qt/menu.cpp trunk/client/gui-qt/optiondlg.cpp trunk/client/gui-qt/pages.cpp Modified: trunk/client/gui-qt/fc_client.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fc_client.cpp?rev=30346&r1=30345&r2=30346&view=diff ============================================================================== --- trunk/client/gui-qt/fc_client.cpp (original) +++ trunk/client/gui-qt/fc_client.cpp Sun Nov 1 18:46:12 2015 @@ -616,13 +616,6 @@ option_dialog_popup(_("Set local options"), client_optset); } -/**************************************************************************** - Popups client options -****************************************************************************/ -void fc_client::popup_server_options() -{ - option_dialog_popup(_("Set server options"), server_optset); -} void fc_client::create_cursors(void) { @@ -777,3 +770,91 @@ { tabBar()->setTabTextColor(index, col); } + +/**************************************************************************** + Init's layout and default values for options in START_PAGE +****************************************************************************/ +void pregame_options::init() +{ + QGridLayout *layout; + QLabel *l1, *l2, *l3; + QPushButton *but; + int level; + + l1 = new QLabel(_("Number of Players\n(including AI):")); + l2 = new QLabel(_("AI Skill Level:")); + l3 = new QLabel(_("Ruleset Version:")); + layout = new QGridLayout(this); + max_players = new QSpinBox(this); + ailevel = new QComboBox(this); + cruleset = new QComboBox(this); + max_players->setRange(1, MAX_NUM_PLAYERS); + + for (level = 0; level < AI_LEVEL_COUNT; level++) { + if (is_settable_ai_level(static_cast<ai_level>(level))) { + const char *level_name = ai_level_translated_name( + static_cast<ai_level>(level)); + ailevel->addItem(level_name, level); + } + } + ailevel->setCurrentIndex(-1); + + connect(max_players, SIGNAL(valueChanged(int)), + SLOT(max_players_change(int))); + connect(ailevel, SIGNAL(currentIndexChanged(int)), + SLOT(ailevel_change(int))); + connect(cruleset, SIGNAL(currentIndexChanged(int)), + SLOT(ruleset_change(int))); + + but = new QPushButton; + but->setText(_("More Game Options")); + but->setIcon(fc_icons::instance()->get_icon("preferences-other")); + QObject::connect(but, SIGNAL(clicked()), this, + SLOT(popup_server_options())); + layout->addWidget(l1, 0, 1); + layout->addWidget(l2, 1, 1); + layout->addWidget(l3, 2, 1); + layout->addWidget(max_players, 0, 2); + layout->addWidget(ailevel, 1, 2); + layout->addWidget(cruleset, 2, 2); + layout->addWidget(but, 3, 1); + setLayout(layout); +} + +/**************************************************************************** + Slot for changing aifill value +****************************************************************************/ +void pregame_options::max_players_change(int i) +{ + option_int_set(optset_option_by_name(server_optset, "aifill"), i); +} + +/**************************************************************************** + Slot for changing level of AI +****************************************************************************/ +void pregame_options::ailevel_change(int i) +{ + int k; + const char *name; + + k = ailevel->currentData().toInt(); + name = ai_level_cmd(static_cast<ai_level>(k)); + send_chat_printf("/%s", name); +} + +/**************************************************************************** + Slot for changing ruleset +****************************************************************************/ +void pregame_options::ruleset_change(int i) +{ + set_ruleset(cruleset->currentText().toLocal8Bit().data()); +} + +/**************************************************************************** + Popups client options +****************************************************************************/ +void pregame_options::popup_server_options() +{ + option_dialog_popup(_("Set server options"), server_optset); +} + Modified: trunk/client/gui-qt/fc_client.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fc_client.h?rev=30346&r1=30345&r2=30346&view=diff ============================================================================== --- trunk/client/gui-qt/fc_client.h (original) +++ trunk/client/gui-qt/fc_client.h Sun Nov 1 18:46:12 2015 @@ -23,9 +23,11 @@ #endif // Qt -#include <QTabWidget> +#include <QComboBox> #include <QMainWindow> #include <QMap> +#include <QSpinBox> +#include <QTabWidget> // client #include "chatline_common.h" @@ -80,6 +82,7 @@ class QTreeWidget; class QStatusBar; class QMainWindow; +class pregame_options; class fc_icons { @@ -209,6 +212,7 @@ xvote *x_vote; goto_dialog *gtd; QCursor *fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES]; + pregame_options *pr_options; void gimme_place(QWidget* widget, QString str); int gimme_index_of(QString str); void remove_repo_dlg(QString str); @@ -242,7 +246,6 @@ public slots: void switch_page(int i); void popup_client_options(); - void popup_server_options(); protected slots: @@ -288,6 +291,27 @@ }; +/*************************************************************************** + Class for showing options in PAGE_START, options like ai_fill, ruleset + etc. +***************************************************************************/ +class pregame_options : public QWidget +{ + Q_OBJECT + QComboBox *ailevel; +public: + pregame_options() {}; + void init(); + QComboBox *cruleset; + QSpinBox *max_players; +private slots: + void max_players_change(int i); + void ailevel_change(int i); + void ruleset_change(int i); +public slots: + void popup_server_options(); +}; + // Return fc_client instance. Implementation in gui_main.cpp class fc_client *gui(); Modified: trunk/client/gui-qt/menu.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.cpp?rev=30346&r1=30345&r2=30346&view=diff ============================================================================== --- trunk/client/gui-qt/menu.cpp (original) +++ trunk/client/gui-qt/menu.cpp Sun Nov 1 18:46:12 2015 @@ -2222,7 +2222,7 @@ *****************************************************************/ void mr_menu::server_options() { - gui()->popup_server_options(); + gui()->pr_options->popup_server_options(); } /**************************************************************** Modified: trunk/client/gui-qt/optiondlg.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/optiondlg.cpp?rev=30346&r1=30345&r2=30346&view=diff ============================================================================== --- trunk/client/gui-qt/optiondlg.cpp (original) +++ trunk/client/gui-qt/optiondlg.cpp Sun Nov 1 18:46:12 2015 @@ -841,8 +841,11 @@ } if (option_optset(poption) == server_optset) { - if (strcmp(option_name(poption), "nationset") == 0) { + if (strcmp(option_name(poption), "nationset") == 0) { update_nationset_combo(); + } + if (strcmp(option_name(poption), "aifill") == 0) { + gui()->pr_options->max_players->setValue(option_int_get(poption)); } } } Modified: trunk/client/gui-qt/pages.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/pages.cpp?rev=30346&r1=30345&r2=30346&view=diff ============================================================================== --- trunk/client/gui-qt/pages.cpp (original) +++ trunk/client/gui-qt/pages.cpp Sun Nov 1 18:46:12 2015 @@ -57,7 +57,21 @@ ****************************************************************************/ void qtg_set_rulesets(int num_rulesets, char **rulesets) { - /* PORTME */ + int i; + int def_idx = -1; + + gui()->pr_options->cruleset->clear(); + gui()->pr_options->cruleset->blockSignals(true); + for (i = 0; i < num_rulesets; i++){ + gui()->pr_options->cruleset->addItem(rulesets[i], i); + if (!strcmp("default", rulesets[i])) { + def_idx = i; + } + } + + /* HACK: server should tell us the current ruleset. */ + gui()->pr_options->cruleset->setCurrentIndex(def_idx); + gui()->pr_options->cruleset->blockSignals(false); } /************************************************************************** @@ -75,6 +89,7 @@ { gui()->update_start_page(); } + /************************************************************************** Creates buttons and layouts for start page. @@ -508,14 +523,17 @@ ***************************************************************************/ void fc_client::create_start_page() { + QPushButton *but; + QStringList player_widget_list; pages_layout[PAGE_START] = new QGridLayout; - QStringList player_widget_list; start_players_tree = new QTreeWidget; + pr_options = new pregame_options(); chat_line = new QLineEdit; output_window = new QTextEdit; output_window->setReadOnly(false); chat_line->installEventFilter(this); + pr_options->init(); player_widget_list << _("Name") << _("Ready") << _("Leader") << _("Flag") << _("Nation") << _("Team"); @@ -531,14 +549,8 @@ SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(start_page_menu(QPoint))); - QPushButton *but; - but = new QPushButton; - but->setText(_("More Game Options")); - but->setIcon(fc_icons::instance()->get_icon("preferences-other")); - pages_layout[PAGE_START]->addWidget(but, 5, 3); - QObject::connect(but, SIGNAL(clicked()), this, - SLOT(popup_server_options())); - pages_layout[PAGE_START]->addWidget(start_players_tree, 0, 0, 2, 8); + pages_layout[PAGE_START]->addWidget(start_players_tree, 0, 0, 3, 6); + pages_layout[PAGE_START]->addWidget(pr_options, 0, 6, 3, 2); but = new QPushButton; but->setText(_("Disconnect")); but->setIcon(style()->standardPixmap(QStyle::SP_DialogCancelButton)); @@ -566,7 +578,7 @@ pre_vote = new pregamevote; pages_layout[PAGE_START]->addWidget(pre_vote, 4, 0, 1, 4); - pages_layout[PAGE_START]->addWidget(chat_line, 5, 0, 1, 3); + pages_layout[PAGE_START]->addWidget(chat_line, 5, 0, 1, 4); pages_layout[PAGE_START]->addWidget(output_window, 3, 0, 1, 8); connect(chat_line, SIGNAL(returnPressed()), this, SLOT(chat())); @@ -1152,7 +1164,7 @@ ***************************************************************************/ void fc_client::update_start_page() { - int conn_num; + int conn_num, i; QVariant qvar, qvar2; bool is_ready; QString nation, leader, team, str; @@ -1179,6 +1191,13 @@ player_item->setText(0, _("Players")); player_item->setData(0, Qt::UserRole, qvar2); + i = 0; + players_iterate(pplayer) { + i++; + } players_iterate_end; + gui()->pr_options->max_players->blockSignals(true); + gui()->pr_options->max_players->setValue(i); + gui()->pr_options->max_players->blockSignals(false); /** * Inserts playing players, observing custom players, and AI ) */ _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits