From 1b99f132d6abbd719cf8d3b22e6ba433db52227d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 7 Apr 2023 20:51:15 +0300 Subject: [PATCH 27/27] Add support for second alt gfx tag for units See osdn #47753 Signed-off-by: Marko Lindqvist --- client/packhand.c | 1 + client/tilespec.c | 9 ++++++--- common/networking/packets.def | 1 + common/unittype.h | 1 + data/alien/units.ruleset | 1 + data/civ1/units.ruleset | 1 + data/civ2/units.ruleset | 1 + data/civ2civ3/units.ruleset | 1 + data/classic/units.ruleset | 3 ++- data/goldkeep/units.ruleset | 1 + data/granularity/units.ruleset | 1 + data/multiplayer/units.ruleset | 1 + data/ruledit/comments-3.3.txt | 1 + data/sandbox/units.ruleset | 1 + data/stub/units.ruleset | 1 + data/webperimental/units.ruleset | 1 + server/ruleset.c | 4 ++++ tools/ruledit/edit_utype.cpp | 21 +++++++++++++++++++++ tools/ruledit/edit_utype.h | 2 ++ tools/ruleutil/rulesave.c | 3 +++ 20 files changed, 52 insertions(+), 4 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index a4713baa6e..eb14a48a06 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -3574,6 +3574,7 @@ void handle_ruleset_unit(const struct packet_ruleset_unit *p) names_set(&u->name, NULL, p->name, p->rule_name); sz_strlcpy(u->graphic_str, p->graphic_str); sz_strlcpy(u->graphic_alt, p->graphic_alt); + sz_strlcpy(u->graphic_alt2, p->graphic_alt2); sz_strlcpy(u->sound_move, p->sound_move); sz_strlcpy(u->sound_move_alt, p->sound_move_alt); sz_strlcpy(u->sound_fight, p->sound_fight); diff --git a/client/tilespec.c b/client/tilespec.c index 440d821d24..c439a03160 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -3792,10 +3792,13 @@ void tileset_setup_unit_type(struct tileset *t, struct unit_type *ut) int uidx = utype_index(ut); if (!tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_str) - && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt)) { + && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt) + && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt2)) { tileset_error(LOG_FATAL, tileset_name_get(t), - _("Missing %s unit sprite for tags \"%s\" and alternative \"%s\"."), - utype_rule_name(ut), ut->graphic_str, ut->graphic_alt); + _("Missing %s unit sprite for tags \"%s\" and alternatives " + "\"%s\" and \"%s\"."), + utype_rule_name(ut), ut->graphic_str, + ut->graphic_alt, ut->graphic_alt2); } if (!t->sprites.units.icon[uidx][ACTIVITY_IDLE]) { diff --git a/common/networking/packets.def b/common/networking/packets.def index 47626a6ebb..7048ce4a77 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -1394,6 +1394,7 @@ PACKET_RULESET_UNIT = 140; sc, lsend STRING rule_name[MAX_LEN_NAME]; STRING graphic_str[MAX_LEN_NAME]; STRING graphic_alt[MAX_LEN_NAME]; + STRING graphic_alt2[MAX_LEN_NAME]; STRING sound_move[MAX_LEN_NAME]; STRING sound_move_alt[MAX_LEN_NAME]; STRING sound_fight[MAX_LEN_NAME]; diff --git a/common/unittype.h b/common/unittype.h index 48fa18249d..0ee9cebcc7 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -502,6 +502,7 @@ struct unit_type { void *ruledit_dlg; char graphic_str[MAX_LEN_NAME]; char graphic_alt[MAX_LEN_NAME]; + char graphic_alt2[MAX_LEN_NAME]; char sound_move[MAX_LEN_NAME]; char sound_move_alt[MAX_LEN_NAME]; char sound_fight[MAX_LEN_NAME]; diff --git a/data/alien/units.ruleset b/data/alien/units.ruleset index c515a42e3c..fd0dd16f4a 100644 --- a/data/alien/units.ruleset +++ b/data/alien/units.ruleset @@ -211,6 +211,7 @@ flags = "Missile", "DoesntOccupyTile" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/civ1/units.ruleset b/data/civ1/units.ruleset index f386e9ae5d..8cef493931 100644 --- a/data/civ1/units.ruleset +++ b/data/civ1/units.ruleset @@ -186,6 +186,7 @@ flags = "Missile", "Unreachable", "HutNothing" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/civ2/units.ruleset b/data/civ2/units.ruleset index 857779d9a2..217481e157 100644 --- a/data/civ2/units.ruleset +++ b/data/civ2/units.ruleset @@ -204,6 +204,7 @@ flags = "Unreachable", "DoesntOccupyTile", "HutFrighten" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/civ2civ3/units.ruleset b/data/civ2civ3/units.ruleset index 1f27ae149e..4d0fb849b4 100644 --- a/data/civ2civ3/units.ruleset +++ b/data/civ2civ3/units.ruleset @@ -245,6 +245,7 @@ flags = "Unreachable", "DoesntOccupyTile", "CanPillage", ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/classic/units.ruleset b/data/classic/units.ruleset index 88607de20d..8be62a75f2 100644 --- a/data/classic/units.ruleset +++ b/data/classic/units.ruleset @@ -213,8 +213,9 @@ flags = "Unreachable", "DoesntOccupyTile", "HutFrighten" ; graphic = tag specifying preferred graphic ; graphic_alt = tag for alternate graphic if preferred graphic is not ; present; especially if preferred graphic is non-standard, -; this should be a standard tag. Otherwise can use eg "-" +; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/goldkeep/units.ruleset b/data/goldkeep/units.ruleset index bd9fff4226..5c6e865b14 100644 --- a/data/goldkeep/units.ruleset +++ b/data/goldkeep/units.ruleset @@ -227,6 +227,7 @@ flags = "Unreachable", "DoesntOccupyTile", "HutFrighten" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/granularity/units.ruleset b/data/granularity/units.ruleset index 81e893d085..8a40542f0f 100644 --- a/data/granularity/units.ruleset +++ b/data/granularity/units.ruleset @@ -162,6 +162,7 @@ flags = "TerrainSpeed" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/multiplayer/units.ruleset b/data/multiplayer/units.ruleset index 601aba90b8..29bc0b030b 100644 --- a/data/multiplayer/units.ruleset +++ b/data/multiplayer/units.ruleset @@ -215,6 +215,7 @@ flags = "Unreachable", "DoesntOccupyTile", "HutFrighten" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/ruledit/comments-3.3.txt b/data/ruledit/comments-3.3.txt index 59e3aff41c..88a76b61d4 100644 --- a/data/ruledit/comments-3.3.txt +++ b/data/ruledit/comments-3.3.txt @@ -329,6 +329,7 @@ utypes = "\ ; present; especially if preferred graphic is non-standard,\n\ ; this should be a standard tag. Otherwise can use eg \"-\"\n\ ; for no alternate graphic.\n\ +; graphic_alt2 = tag for second alternative graphic.\n\ ; reqs = requirements to build the unit (see effects.ruleset\n\ ; and README.effects for help on requirements)\n\ ; obsolete_by = can be upgraded to and made obsolete by another unit by name\n\ diff --git a/data/sandbox/units.ruleset b/data/sandbox/units.ruleset index 72326bedd7..6172b8e05b 100644 --- a/data/sandbox/units.ruleset +++ b/data/sandbox/units.ruleset @@ -258,6 +258,7 @@ flags = "Unreachable", "DoesntOccupyTile", "CanPillage", ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/stub/units.ruleset b/data/stub/units.ruleset index a6a0b93506..46f0c32f0e 100644 --- a/data/stub/units.ruleset +++ b/data/stub/units.ruleset @@ -144,6 +144,7 @@ flags = "" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/data/webperimental/units.ruleset b/data/webperimental/units.ruleset index 9f7ca807f4..1cdef54c30 100644 --- a/data/webperimental/units.ruleset +++ b/data/webperimental/units.ruleset @@ -219,6 +219,7 @@ flags = "Unreachable", "DoesntOccupyTile", "HutFrighten" ; present; especially if preferred graphic is non-standard, ; this should be a standard tag. Otherwise can use eg "-" ; for no alternate graphic. +; graphic_alt2 = tag for second alternative graphic. ; reqs = requirements to build the unit (see effects.ruleset ; and README.effects for help on requirements) ; obsolete_by = can be upgraded to and made obsolete by another unit by name diff --git a/server/ruleset.c b/server/ruleset.c index 80df66b92e..37a08e9911 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -2234,6 +2234,9 @@ static bool load_ruleset_units(struct section_file *file, sz_strlcpy(u->graphic_alt, secfile_lookup_str_default(file, "-", "%s.graphic_alt", sec_name)); + sz_strlcpy(u->graphic_alt2, + secfile_lookup_str_default(file, "-", "%s.graphic_alt2", + sec_name)); if (!secfile_lookup_int(file, &u->build_cost, "%s.build_cost", sec_name) @@ -7922,6 +7925,7 @@ static void send_ruleset_units(struct conn_list *dest) sz_strlcpy(packet.sound_fight_alt, u->sound_fight_alt); sz_strlcpy(packet.graphic_str, u->graphic_str); sz_strlcpy(packet.graphic_alt, u->graphic_alt); + sz_strlcpy(packet.graphic_alt2, u->graphic_alt2); packet.unit_class_id = uclass_number(utype_class(u)); packet.build_cost = u->build_cost; packet.pop_cost = u->pop_cost; diff --git a/tools/ruledit/edit_utype.cpp b/tools/ruledit/edit_utype.cpp index adf8b2eb23..0f5cadfc86 100644 --- a/tools/ruledit/edit_utype.cpp +++ b/tools/ruledit/edit_utype.cpp @@ -106,6 +106,15 @@ edit_utype::edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in) : QDialog unit_layout->addWidget(label, row, 0); unit_layout->addWidget(gfx_tag_alt, row++, 1); + label = new QLabel(QString::fromUtf8(R__("Second alt gfx tag"))); + label->setParent(this); + + gfx_tag_alt2 = new QLineEdit(this); + connect(gfx_tag_alt2, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt2_given())); + + unit_layout->addWidget(label, row, 0); + unit_layout->addWidget(gfx_tag_alt2, row++, 1); + refresh(); main_layout->addLayout(unit_layout); @@ -121,6 +130,7 @@ void edit_utype::closeEvent(QCloseEvent *cevent) // Save values from text fields. gfx_tag_given(); gfx_tag_alt_given(); + gfx_tag_alt2_given(); utype->ruledit_dlg = nullptr; } @@ -136,6 +146,7 @@ void edit_utype::refresh() move_rate->setValue(utype->move_rate); gfx_tag->setText(utype->graphic_str); gfx_tag_alt->setText(utype->graphic_alt); + gfx_tag_alt2->setText(utype->graphic_alt2); } /**********************************************************************//** @@ -189,3 +200,13 @@ void edit_utype::gfx_tag_alt_given() sz_strlcpy(utype->graphic_alt, tag_bytes); } + +/**********************************************************************//** + User entered new secondary alternative graphics tag. +**************************************************************************/ +void edit_utype::gfx_tag_alt2_given() +{ + QByteArray tag_bytes = gfx_tag_alt2->text().toUtf8(); + + sz_strlcpy(utype->graphic_alt2, tag_bytes); +} diff --git a/tools/ruledit/edit_utype.h b/tools/ruledit/edit_utype.h index ffccb26dcc..d8e2567fe9 100644 --- a/tools/ruledit/edit_utype.h +++ b/tools/ruledit/edit_utype.h @@ -44,6 +44,7 @@ class edit_utype : public QDialog QSpinBox *move_rate; QLineEdit *gfx_tag; QLineEdit *gfx_tag_alt; + QLineEdit *gfx_tag_alt2; protected: void closeEvent(QCloseEvent *cevent); @@ -55,6 +56,7 @@ class edit_utype : public QDialog void set_move_rate(int value); void gfx_tag_given(); void gfx_tag_alt_given(); + void gfx_tag_alt2_given(); }; #endif // FC__EDIT_UTYPE_H diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index fc954c3d7a..a2ff7480f7 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -3200,6 +3200,9 @@ static bool save_units_ruleset(const char *filename, const char *name) if (strcmp("-", put->graphic_alt)) { secfile_insert_str(sfile, put->graphic_alt, "%s.graphic_alt", path); } + if (strcmp("-", put->graphic_alt2)) { + secfile_insert_str(sfile, put->graphic_alt2, "%s.graphic_alt2", path); + } if (strcmp("-", put->sound_move)) { secfile_insert_str(sfile, put->sound_move, "%s.sound_move", path); } -- 2.39.2