<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40703 >
Patch implements an option to have the selection rectangle select cities only when there are both cities and units in the rectangle area. ----------------------------------------------------------------------- ここ五日の間にこのりんごを少しずつ食べるつもりだ。
client/mapctrl_common.c | 27 ++++++++++++++++++--------- client/options.c | 6 ++++++ client/options.h | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/client/mapctrl_common.c b/client/mapctrl_common.c index 8c3cc88..22c4b47 100644 --- a/client/mapctrl_common.c +++ b/client/mapctrl_common.c @@ -118,7 +118,7 @@ static void define_tiles_within_rectangle(void) const int inc_x = (rec_w > 0 ? half_W : -half_W); const int inc_y = (rec_h > 0 ? half_H : -half_H); int x, y, x2, y2, xx, yy; - int units = 0; + struct unit_list *units = unit_list_new(); y = rec_corner_y; for (yy = 0; yy <= segments_y; yy++, y += inc_y) { @@ -154,18 +154,27 @@ static void define_tiles_within_rectangle(void) tiles_hilited_cities = TRUE; } unit_list_iterate(ptile->units, punit) { - if (unit_owner(punit) == game.player_ptr) { - if (units == 0 && !rectangle_append) { - set_unit_focus(punit); - } else { - add_unit_focus(punit); - } - units++; - } + if (unit_owner(punit) == game.player_ptr) { + unit_list_append(units, punit); + } } unit_list_iterate_end; } } + if (!(separate_unit_selection && tiles_hilited_cities) + && unit_list_size(units) > 0) { + if (!rectangle_append) { + struct unit *punit = unit_list_get(units, 0); + set_unit_focus(punit); + unit_list_unlink(units, punit); + } + unit_list_iterate(units, punit) { + add_unit_focus(punit); + } unit_list_iterate_end; + } + unit_list_unlink_all(units); + unit_list_free(units); + /* Hilite in City List Window */ if (tiles_hilited_cities) { hilite_cities_from_canvas(); /* cityrep.c */ diff --git a/client/options.c b/client/options.c index 99afbc6..e0b6fb5 100644 --- a/client/options.c +++ b/client/options.c @@ -88,6 +88,7 @@ bool popup_new_cities = TRUE; bool keyboardless_goto = TRUE; bool show_task_icons = TRUE; bool enable_cursor_changes = TRUE; +bool separate_unit_selection = FALSE; /* This option is currently set by the client - not by the user. */ bool update_city_text_in_refresh_tile = TRUE; @@ -250,6 +251,11 @@ static client_option common_options[] = { "is being pointed at, as well as to indicate " "changes in the client or server state."), COC_INTERFACE), + GEN_BOOL_OPTION(separate_unit_selection, N_("Select cities before units"), + N_("If this option is enabled, when both cities and " + "units are present in the selection rectangle, only " + "cities will be selected."), + COC_INTERFACE), GEN_BOOL_OPTION(overview.layers[OLAYER_BACKGROUND], N_("Background layer"), diff --git a/client/options.h b/client/options.h index aee53c2..e3e3e75 100644 --- a/client/options.h +++ b/client/options.h @@ -52,6 +52,7 @@ extern bool update_city_text_in_refresh_tile; extern bool keyboardless_goto; extern bool show_task_icons; extern bool enable_cursor_changes; +extern bool separate_unit_selection; enum client_option_type { COT_BOOL,
client/mapctrl_common.c | 26 +++++++++++++++++--------- client/options.c | 6 ++++++ client/options.h | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/client/mapctrl_common.c b/client/mapctrl_common.c index e80acfe..67c7bf4 100644 --- a/client/mapctrl_common.c +++ b/client/mapctrl_common.c @@ -124,7 +124,7 @@ static void define_tiles_within_rectangle(void) const int inc_x = (rec_w > 0 ? half_W : -half_W); const int inc_y = (rec_h > 0 ? half_H : -half_H); int x, y, x2, y2, xx, yy; - int units = 0; + struct unit_list *units = unit_list_new(); y = rec_corner_y; for (yy = 0; yy <= segments_y; yy++, y += inc_y) { @@ -161,18 +161,26 @@ static void define_tiles_within_rectangle(void) tiles_hilited_cities = TRUE; } unit_list_iterate(ptile->units, punit) { - if (unit_owner(punit) == client.conn.playing) { - if (units == 0 && !rectangle_append) { - set_unit_focus(punit); - } else { - add_unit_focus(punit); - } - units++; - } + if (unit_owner(punit) == client.conn.playing) { + unit_list_append(units, punit); + } } unit_list_iterate_end; } } + if (!(separate_unit_selection && tiles_hilited_cities) + && unit_list_size(units) > 0) { + if (!rectangle_append) { + struct unit *punit = unit_list_get(units, 0); + set_unit_focus(punit); + unit_list_unlink(units, punit); + } + unit_list_iterate(units, punit) { + add_unit_focus(punit); + } unit_list_iterate_end; + } + unit_list_free(units); + /* Hilite in City List Window */ if (tiles_hilited_cities) { hilite_cities_from_canvas(); /* cityrep.c */ diff --git a/client/options.c b/client/options.c index ba89dfb..abc6f1e 100644 --- a/client/options.c +++ b/client/options.c @@ -90,6 +90,7 @@ bool popup_new_cities = TRUE; bool keyboardless_goto = TRUE; bool show_task_icons = TRUE; bool enable_cursor_changes = TRUE; +bool separate_unit_selection = FALSE; /* This option is currently set by the client - not by the user. */ bool update_city_text_in_refresh_tile = TRUE; @@ -265,6 +266,11 @@ static client_option common_options[] = { "is being pointed at, as well as to indicate " "changes in the client or server state."), COC_INTERFACE), + GEN_BOOL_OPTION(separate_unit_selection, N_("Select cities before units"), + N_("If this option is enabled, when both cities and " + "units are present in the selection rectangle, only " + "cities will be selected."), + COC_INTERFACE), GEN_BOOL_OPTION(overview.layers[OLAYER_BACKGROUND], N_("Background layer"), diff --git a/client/options.h b/client/options.h index 876bada..11a27fd 100644 --- a/client/options.h +++ b/client/options.h @@ -53,6 +53,7 @@ extern bool update_city_text_in_refresh_tile; extern bool keyboardless_goto; extern bool show_task_icons; extern bool enable_cursor_changes; +extern bool separate_unit_selection; extern char font_city_label[512]; extern char font_notify_label[512];
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev