From c832f02efdeefe9c7a33910d55f30abd2a9a051d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 22 Sep 2024 03:03:26 +0300 Subject: [PATCH 55/55] Editor: Add infrapoints editing See osdn #47385 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/editprop.c | 19 +++++++++++++++++++ client/gui-gtk-4.0/editprop.c | 19 +++++++++++++++++++ client/gui-gtk-5.0/editprop.c | 19 +++++++++++++++++++ common/networking/packets.def | 1 + server/edithand.c | 14 ++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/client/gui-gtk-3.22/editprop.c b/client/gui-gtk-3.22/editprop.c index 074dfad35b..3452aa12da 100644 --- a/client/gui-gtk-3.22/editprop.c +++ b/client/gui-gtk-3.22/editprop.c @@ -367,6 +367,7 @@ enum object_property_ids { OPID_PLAYER_SELECT_WEIGHT, OPID_PLAYER_SCIENCE, OPID_PLAYER_GOLD, + OPID_PLAYER_INFRAPOINTS, OPID_GAME_SCENARIO, OPID_GAME_SCENARIO_NAME, @@ -1802,6 +1803,9 @@ static struct propval *objbind_get_value_from_object(struct objbind *ob, case OPID_PLAYER_GOLD: pv->data.v_int = pplayer->economic.gold; break; + case OPID_PLAYER_INFRAPOINTS: + pv->data.v_int = pplayer->economic.infra_points; + break; default: log_error("%s(): Unhandled request for value of property %d " "(%s) from object of type \"%s\".", __FUNCTION__, @@ -2026,6 +2030,12 @@ static bool objbind_get_allowed_value_span(struct objbind *ob, *pstep = 1; *pbig_step = 100; return TRUE; + case OPID_PLAYER_INFRAPOINTS: + *pmin = 0; + *pmax = 1000000; /* Arbitrary. */ + *pstep = 1; + *pbig_step = 100; + return TRUE; case OPID_PLAYER_SELECT_WEIGHT: *pmin = -1; *pmax = 10000; /* Keep it under SINT16 */ @@ -2330,6 +2340,7 @@ static void objbind_pack_current_values(struct objbind *ob, } advance_index_iterate_end; packet->autoselect_weight = pplayer->autoselect_weight; packet->gold = pplayer->economic.gold; + packet->infrapoints = pplayer->economic.infra_points; packet->government = government_index(pplayer->government); packet->scenario_reserved = player_has_flag(pplayer, PLRF_SCENARIO_RESERVED); /* TODO: Set more packet fields. */ @@ -2572,6 +2583,9 @@ static void objbind_pack_modified_value(struct objbind *ob, case OPID_PLAYER_GOLD: packet->gold = pv->data.v_int; return; + case OPID_PLAYER_INFRAPOINTS: + packet->infrapoints = pv->data.v_int; + return; default: break; } @@ -3031,6 +3045,7 @@ static void objprop_setup_widget(struct objprop *op) case OPID_PLAYER_SELECT_WEIGHT: case OPID_PLAYER_SCIENCE: case OPID_PLAYER_GOLD: + case OPID_PLAYER_INFRAPOINTS: spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0); gtk_widget_set_hexpand(spin, TRUE); gtk_widget_set_halign(spin, GTK_ALIGN_END); @@ -3235,6 +3250,7 @@ static void objprop_refresh_widget(struct objprop *op, case OPID_PLAYER_SELECT_WEIGHT: case OPID_PLAYER_SCIENCE: case OPID_PLAYER_GOLD: + case OPID_PLAYER_INFRAPOINTS: spin = objprop_get_child_widget(op, "spin"); if (pv) { disable_gobject_callback(G_OBJECT(spin), @@ -4573,6 +4589,9 @@ static void property_page_setup_objprops(struct property_page *pp) ADDPROP(OPID_PLAYER_GOLD, _("Gold"), NULL, OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_INT); + ADDPROP(OPID_PLAYER_INFRAPOINTS, _("Infrapoints"), NULL, + OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, + VALTYPE_INT); return; case OBJTYPE_GAME: diff --git a/client/gui-gtk-4.0/editprop.c b/client/gui-gtk-4.0/editprop.c index 3a4fcf2887..425c325c1b 100644 --- a/client/gui-gtk-4.0/editprop.c +++ b/client/gui-gtk-4.0/editprop.c @@ -367,6 +367,7 @@ enum object_property_ids { OPID_PLAYER_SELECT_WEIGHT, OPID_PLAYER_SCIENCE, OPID_PLAYER_GOLD, + OPID_PLAYER_INFRAPOINTS, OPID_GAME_SCENARIO, OPID_GAME_SCENARIO_NAME, @@ -1803,6 +1804,9 @@ static struct propval *objbind_get_value_from_object(struct objbind *ob, case OPID_PLAYER_GOLD: pv->data.v_int = pplayer->economic.gold; break; + case OPID_PLAYER_INFRAPOINTS: + pv->data.v_int = pplayer->economic.infra_points; + break; default: log_error("%s(): Unhandled request for value of property %d " "(%s) from object of type \"%s\".", __FUNCTION__, @@ -2027,6 +2031,12 @@ static bool objbind_get_allowed_value_span(struct objbind *ob, *pstep = 1; *pbig_step = 100; return TRUE; + case OPID_PLAYER_INFRAPOINTS: + *pmin = 0; + *pmax = 1000000; /* Arbitrary. */ + *pstep = 1; + *pbig_step = 100; + return TRUE; case OPID_PLAYER_SELECT_WEIGHT: *pmin = -1; *pmax = 10000; /* Keep it under SINT16 */ @@ -2331,6 +2341,7 @@ static void objbind_pack_current_values(struct objbind *ob, } advance_index_iterate_end; packet->autoselect_weight = pplayer->autoselect_weight; packet->gold = pplayer->economic.gold; + packet->infrapoints = pplayer->economic.infra_points; packet->government = government_index(pplayer->government); packet->scenario_reserved = player_has_flag(pplayer, PLRF_SCENARIO_RESERVED); /* TODO: Set more packet fields. */ @@ -2573,6 +2584,9 @@ static void objbind_pack_modified_value(struct objbind *ob, case OPID_PLAYER_GOLD: packet->gold = pv->data.v_int; return; + case OPID_PLAYER_INFRAPOINTS: + packet->infrapoints = pv->data.v_int; + return; default: break; } @@ -3030,6 +3044,7 @@ static void objprop_setup_widget(struct objprop *op) case OPID_PLAYER_SELECT_WEIGHT: case OPID_PLAYER_SCIENCE: case OPID_PLAYER_GOLD: + case OPID_PLAYER_INFRAPOINTS: spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0); gtk_widget_set_hexpand(spin, TRUE); gtk_widget_set_halign(spin, GTK_ALIGN_END); @@ -3245,6 +3260,7 @@ static void objprop_refresh_widget(struct objprop *op, case OPID_PLAYER_SELECT_WEIGHT: case OPID_PLAYER_SCIENCE: case OPID_PLAYER_GOLD: + case OPID_PLAYER_INFRAPOINTS: spin = objprop_get_child_widget(op, "spin"); if (pv) { disable_gobject_callback(G_OBJECT(spin), @@ -4582,6 +4598,9 @@ static void property_page_setup_objprops(struct property_page *pp) ADDPROP(OPID_PLAYER_GOLD, _("Gold"), NULL, OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_INT); + ADDPROP(OPID_PLAYER_INFRAPOINTS, _("Infrapoints"), NULL, + OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, + VALTYPE_INT); return; case OBJTYPE_GAME: diff --git a/client/gui-gtk-5.0/editprop.c b/client/gui-gtk-5.0/editprop.c index 901491e4f0..7ea7a05e12 100644 --- a/client/gui-gtk-5.0/editprop.c +++ b/client/gui-gtk-5.0/editprop.c @@ -367,6 +367,7 @@ enum object_property_ids { OPID_PLAYER_SELECT_WEIGHT, OPID_PLAYER_SCIENCE, OPID_PLAYER_GOLD, + OPID_PLAYER_INFRAPOINTS, OPID_GAME_SCENARIO, OPID_GAME_SCENARIO_NAME, @@ -1803,6 +1804,9 @@ static struct propval *objbind_get_value_from_object(struct objbind *ob, case OPID_PLAYER_GOLD: pv->data.v_int = pplayer->economic.gold; break; + case OPID_PLAYER_INFRAPOINTS: + pv->data.v_int = pplayer->economic.infra_points; + break; default: log_error("%s(): Unhandled request for value of property %d " "(%s) from object of type \"%s\".", __FUNCTION__, @@ -2027,6 +2031,12 @@ static bool objbind_get_allowed_value_span(struct objbind *ob, *pstep = 1; *pbig_step = 100; return TRUE; + case OPID_PLAYER_INFRAPOINTS: + *pmin = 0; + *pmax = 1000000; /* Arbitrary. */ + *pstep = 1; + *pbig_step = 100; + return TRUE; case OPID_PLAYER_SELECT_WEIGHT: *pmin = -1; *pmax = 10000; /* Keep it under SINT16 */ @@ -2331,6 +2341,7 @@ static void objbind_pack_current_values(struct objbind *ob, } advance_index_iterate_end; packet->autoselect_weight = pplayer->autoselect_weight; packet->gold = pplayer->economic.gold; + packet->infrapoints = pplayer->economic.infra_points; packet->government = government_index(pplayer->government); packet->scenario_reserved = player_has_flag(pplayer, PLRF_SCENARIO_RESERVED); /* TODO: Set more packet fields. */ @@ -2573,6 +2584,9 @@ static void objbind_pack_modified_value(struct objbind *ob, case OPID_PLAYER_GOLD: packet->gold = pv->data.v_int; return; + case OPID_PLAYER_INFRAPOINTS: + packet->infrapoints = pv->data.v_int; + return; default: break; } @@ -3030,6 +3044,7 @@ static void objprop_setup_widget(struct objprop *op) case OPID_PLAYER_SELECT_WEIGHT: case OPID_PLAYER_SCIENCE: case OPID_PLAYER_GOLD: + case OPID_PLAYER_INFRAPOINTS: spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0); gtk_widget_set_hexpand(spin, TRUE); gtk_widget_set_halign(spin, GTK_ALIGN_END); @@ -3245,6 +3260,7 @@ static void objprop_refresh_widget(struct objprop *op, case OPID_PLAYER_SELECT_WEIGHT: case OPID_PLAYER_SCIENCE: case OPID_PLAYER_GOLD: + case OPID_PLAYER_INFRAPOINTS: spin = objprop_get_child_widget(op, "spin"); if (pv) { disable_gobject_callback(G_OBJECT(spin), @@ -4582,6 +4598,9 @@ static void property_page_setup_objprops(struct property_page *pp) ADDPROP(OPID_PLAYER_GOLD, _("Gold"), NULL, OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_INT); + ADDPROP(OPID_PLAYER_INFRAPOINTS, _("Infrapoints"), NULL, + OPF_IN_LISTVIEW | OPF_HAS_WIDGET | OPF_EDITABLE, + VALTYPE_INT); return; case OBJTYPE_GAME: diff --git a/common/networking/packets.def b/common/networking/packets.def index 78ef2dda0c..f62ab425a6 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -2345,6 +2345,7 @@ PACKET_EDIT_PLAYER = 216; cs, handle-per-conn, lsend BV_PLAYER embassy; GOLD gold; + UINT32 infrapoints; PERCENT tax, science, luxury; UINT16 future_tech; diff --git a/server/edithand.c b/server/edithand.c index 3edee4c618..0772f9b63f 100644 --- a/server/edithand.c +++ b/server/edithand.c @@ -1118,6 +1118,20 @@ void handle_edit_player(struct connection *pc, } } + /* Handle a change in the player's infrapoints. */ + if (packet->infrapoints != pplayer->economic.infra_points) { + if (!(0 <= packet->infrapoints && packet->infrapoints <= 1000000)) { + notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor, + _("Cannot set infrapoints for player %d (%s) because " + "the value %d is outside the allowed range."), + player_number(pplayer), player_name(pplayer), + packet->infrapoints); + } else { + pplayer->economic.infra_points = packet->infrapoints; + changed = TRUE; + } + } + /* Handle a change in the player's autoselect weight. */ if (packet->autoselect_weight != pplayer->autoselect_weight) { pplayer->autoselect_weight = packet->autoselect_weight; -- 2.45.2