Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc small refactorings #1170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions client/citydlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ void unit_list_item::activate_and_close_dialog()
if (can_issue_orders()) {
unit_focus_set(m_unit);
queen()->city_overlay->dont_focus = true;
popdown_all_city_dialogs();
popdown_city_dialog();
}
}

Expand Down Expand Up @@ -2074,7 +2074,7 @@ void city_dialog::refresh()
update_cma_tab();
update_disabled();
} else {
destroy_city_dialog();
popdown_city_dialog();
}

update_map_canvas_visible();
Expand Down Expand Up @@ -2799,31 +2799,15 @@ void real_city_dialog_popup(struct city *pcity)
}

/**
Closes city dialog
* Closes the city overlay.
*/
void destroy_city_dialog()
void popdown_city_dialog()
{
// Only tyrans destroy cities instead building
if (king()->current_page() >= PAGE_GAME) {
if (queen()) {
queen()->city_overlay->hide();
}
}

/**
Close the dialog for the given city.
*/
void popdown_city_dialog(struct city *pcity)
{
Q_UNUSED(pcity)

popdown_all_city_dialogs(); // We only ever have one city dialog
}

/**
Close the dialogs for all cities.
*/
void popdown_all_city_dialogs() { queen()->city_overlay->hide(); }

/**
Refresh (update) all data for the given city's dialog.
*/
Expand Down
6 changes: 3 additions & 3 deletions client/client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ void set_client_state(enum client_states newstate)
break;

case C_S_DISCONNECTED:
popdown_all_city_dialogs();
popdown_city_dialog();
close_all_diplomacy_dialogs();
popdown_all_game_dialogs();
meswin_clear_older(MESWIN_CLEAR_ALL, 0);
Expand All @@ -818,7 +818,7 @@ void set_client_state(enum client_states newstate)
break;

case C_S_PREPARING:
popdown_all_city_dialogs();
popdown_city_dialog();
close_all_diplomacy_dialogs();
popdown_all_game_dialogs();
meswin_clear_older(MESWIN_CLEAR_ALL, 0);
Expand Down Expand Up @@ -892,7 +892,7 @@ void set_client_state(enum client_states newstate)
}
city_list_iterate_end;
}
popdown_all_city_dialogs();
popdown_city_dialog();
close_all_diplomacy_dialogs();
popdown_all_game_dialogs();
unit_focus_set(nullptr);
Expand Down
5 changes: 4 additions & 1 deletion client/climisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ void client_remove_city(struct city *pcity)
// nothing yet
}

popdown_city_dialog(pcity);
if (auto dialog = is_any_city_dialog_open();
dialog && pcity->id == dialog->id) {
popdown_city_dialog();
}
game_remove_city(&wld, pcity);
city_report_dialog_update();
refresh_city_mapcanvas(&old_city, ptile, true, false);
Expand Down
2 changes: 1 addition & 1 deletion client/connectdlg_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool is_server_running()
if (server_quitting) {
return false;
}
return serverProcess::i()->state();
return serverProcess::i()->state() > QProcess::NotRunning;
}

/**
Expand Down
14 changes: 4 additions & 10 deletions client/mapctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ void map_view::keyPressEvent(QKeyEvent *event)
Qt::KeyboardModifiers key_mod = QApplication::keyboardModifiers();
bool is_shift = key_mod.testFlag(Qt::ShiftModifier);

auto scale = queen()->mapview_wdg->scale();

if (C_S_RUNNING == client_state()) {
if (is_shift) {
switch (event->key()) {
Expand All @@ -116,35 +114,31 @@ void map_view::keyPressEvent(QKeyEvent *event)
case Qt::Key_Up:
case Qt::Key_8:
if (is_shift) {
recenter_button_pressed(queen()->mapview_wdg->width() / 2 / scale,
lmoureaux marked this conversation as resolved.
Show resolved Hide resolved
0);
recenter_button_pressed(width() / 2 / scale(), 0);
} else {
key_unit_move(DIR8_NORTH);
}
return;
case Qt::Key_Left:
case Qt::Key_4:
if (is_shift) {
recenter_button_pressed(0,
queen()->mapview_wdg->height() / 2 / scale);
recenter_button_pressed(0, height() / 2 / scale());
} else {
key_unit_move(DIR8_WEST);
}
return;
case Qt::Key_Right:
case Qt::Key_6:
if (is_shift) {
recenter_button_pressed(queen()->mapview_wdg->width() / scale,
queen()->mapview_wdg->height() / 2 / scale);
recenter_button_pressed(width() / scale(), height() / 2 / scale());
} else {
key_unit_move(DIR8_EAST);
}
return;
case Qt::Key_Down:
case Qt::Key_2:
if (is_shift) {
recenter_button_pressed(queen()->mapview_wdg->width() / 2 / scale,
queen()->mapview_wdg->height() / scale);
recenter_button_pressed(width() / 2 / scale(), height() / scale());
} else {
key_unit_move(DIR8_SOUTH);
}
Expand Down
2 changes: 1 addition & 1 deletion client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void tileset_changed(void)
}

update_unit_info_label(get_units_in_focus());
destroy_city_dialog();
popdown_city_dialog();
// Update science report if open
if (queen()->isRepoDlgOpen(QStringLiteral("SCI"))) {
i = queen()->gimmeIndexOf(QStringLiteral("SCI"));
Expand Down
2 changes: 1 addition & 1 deletion client/packhand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ void handle_game_info(const struct packet_game_info *pinfo)
}

if (game.info.is_edit_mode != pinfo->is_edit_mode) {
popdown_all_city_dialogs();
popdown_city_dialog();
// Clears the current goto command.
clear_hover_state();

Expand Down
10 changes: 4 additions & 6 deletions client/page_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,15 @@ void page_load::browse_saves()
/**
State of preview has been changed
*/
void page_load::state_preview(int new_state)
void page_load::state_preview()
{
Q_UNUSED(new_state)
QItemSelection slctn;

gui_options.gui_qt_show_preview =
ui.show_preview->checkState() != Qt::Unchecked;
slctn = ui.saves_load->selectionModel()->selection();
auto selection = ui.saves_load->selectionModel()->selection();
ui.saves_load->selectionModel()->clearSelection();
ui.saves_load->selectionModel()->select(
slctn, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
selection,
QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
}

void page_load::slot_selection_changed(const QItemSelection &selected,
Expand Down
2 changes: 1 addition & 1 deletion client/page_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class page_load : public QWidget {
private slots:
void slot_selection_changed(const QItemSelection &,
const QItemSelection &);
void state_preview(int);
void state_preview();
void browse_saves();

private:
Expand Down
3 changes: 1 addition & 2 deletions client/qtg_cxxside.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ void editgui_popdown_all();
void start_turn();
void real_city_dialog_popup(struct city *pcity);
void real_city_dialog_refresh(struct city *pcity);
void popdown_city_dialog(struct city *pcity);
void popdown_all_city_dialogs();
void popdown_city_dialog();
bool handmade_scenario_warning();
void refresh_unit_city_dialogs(struct unit *punit);
bool city_dialog_is_open(struct city *pcity);
Expand Down
2 changes: 1 addition & 1 deletion client/top_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void top_bar::addWidget(QWidget *fsw)
*/
void top_bar_show_map()
{
popdown_all_city_dialogs();
popdown_city_dialog();
queen()->game_tab_widget->setCurrentIndex(0);
}

Expand Down