From 2ddecd36e650919fa71a4287e28b5bd5d2148f20 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 22 Sep 2024 03:03:26 +0300 Subject: [PATCH 36/36] 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 +++++++++++++++++++ common/networking/packets.def | 1 + server/edithand.c | 14 ++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/client/gui-gtk-3.22/editprop.c b/client/gui-gtk-3.22/editprop.c index ac83279285..e67fb094b3 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, @@ -1801,6 +1802,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__, @@ -2025,6 +2029,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 */ @@ -2329,6 +2339,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. */ @@ -2571,6 +2582,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); @@ -3234,6 +3249,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), @@ -4572,6 +4588,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 359b138b0d..e0c0e57c7a 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, @@ -1801,6 +1802,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__, @@ -2025,6 +2029,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 */ @@ -2329,6 +2339,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. */ @@ -2571,6 +2582,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; } @@ -3028,6 +3042,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); @@ -3243,6 +3258,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), @@ -4580,6 +4596,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 64f401a55d..1c6912639d 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -2363,6 +2363,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 65518eb032..79c57146c9 100644 --- a/server/edithand.c +++ b/server/edithand.c @@ -1115,6 +1115,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