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

Finish migrating tileset layers to classes #2346

Merged
merged 50 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9a41709
Make is_extra_drawing_enabled const-correct
lmoureaux Aug 6, 2024
c0feba8
Allow class-based layers to use info about extras
lmoureaux Aug 6, 2024
6e77596
Use extrastyle_id in estyle_hash
lmoureaux Aug 6, 2024
e2eefe6
Tilespec: expose make_tag_terrain_list
lmoureaux Aug 6, 2024
9f1a857
Tilespec: expose dir_get_tileset_name
lmoureaux Aug 6, 2024
72eb60f
Tilespec: Create a load_sprite() overload taking a list of possible tags
lmoureaux Aug 6, 2024
7f20455
Tilespec: move extra-related definitions to layer.h
lmoureaux Aug 6, 2024
e1cf358
Move water drawing (CARDINAL/RIVER extras) to layer_water
lmoureaux Aug 6, 2024
2cea04d
Make layer_darkness load its own sprites
lmoureaux Aug 6, 2024
2b0048b
Migrate loading special sprites to layer_special
lmoureaux Aug 6, 2024
9183b45
Add a draw_sprite constructor taking QPoint offsets
lmoureaux Aug 7, 2024
250442f
Move layer_units drawing and initialization to the class
lmoureaux Aug 7, 2024
7c5dcc3
Use QPoint-based offsets more consistently
lmoureaux Aug 7, 2024
942725d
Move LAYER_FOG to a class
lmoureaux Aug 7, 2024
578d9c7
Standardize layer::load_sprites()
lmoureaux Aug 7, 2024
8c2ecd5
Move LAYER_GRID1 and 2 to class layer_grid
lmoureaux Aug 7, 2024
bfa4c16
Move LAYER_EDITOR to class layer_editor
lmoureaux Aug 7, 2024
f2e2460
Move LAYER_GOTO to class layer_goto
lmoureaux Aug 7, 2024
c8a6cf0
Migrate LAYER_CITY2 to class layer_city_size
lmoureaux Aug 7, 2024
91ab41f
Migrate LAYER_CITY1 to class layer_city
lmoureaux Aug 7, 2024
a09846b
Migrate LAYER_OVERLAYS to class layer_overlays
lmoureaux Aug 7, 2024
c9ceebe
Add a common base for layers using activity sprites
lmoureaux Aug 8, 2024
d37e1e8
Fix trying to fetch goto state on unknown tiles
lmoureaux Aug 8, 2024
f77c1d0
Port LAYER_INFRAWORK to class layer_infrawork
lmoureaux Aug 8, 2024
b9052c5
Port LAYER_ROADS to class layer_roads
lmoureaux Aug 9, 2024
ac8eb0c
Fix some offsets in city layers
lmoureaux Aug 10, 2024
16cdaba
Expose valid tileset directions
lmoureaux Aug 10, 2024
f21b5f0
Move road drawing to layer_roads
lmoureaux Aug 10, 2024
445fffd
Remove fill_sprite_array() from tilespec.cpp
lmoureaux Aug 10, 2024
335e672
Remove unused includes from tilespec.cpp
lmoureaux Aug 10, 2024
e4cba69
Update POTFILES
lmoureaux Aug 10, 2024
ce57556
Use QPoint in drawn_sprite and related APIs
lmoureaux Aug 10, 2024
3363dc7
Remove ADD_SPRITE_FULL
lmoureaux Aug 10, 2024
030cee0
Fix make_tag_terrain_list when the terrain has no graphic_alt
lmoureaux Aug 10, 2024
f431bef
Fix initializing tileset extra data after terrains
lmoureaux Aug 10, 2024
004aaaa
Use std::vector::insert more now that drawn_sprite is assignable
lmoureaux Aug 10, 2024
0b23b0a
Replace sprite_vector with vector<QPixmap *>
lmoureaux Aug 10, 2024
a47eb4c
Add a function in the layer class to load a sprite
lmoureaux Aug 10, 2024
5b42d04
Don't use tiles_lookup_sprite_tag_alt in helpdlg
lmoureaux Aug 10, 2024
d648de8
Use QSize for sprite sizes in tilespec.cpp
lmoureaux Aug 10, 2024
3a2b056
clang-format
lmoureaux Aug 12, 2024
0ad45cb
Add missing <array> includes
lmoureaux Aug 14, 2024
49328e8
Check that at least one unit.hp_ sprite is present
lmoureaux Aug 14, 2024
51ff22c
Tidy up layer_fog a little
lmoureaux Aug 14, 2024
5e4e707
Add a silent mode when loading optional sprites
lmoureaux Aug 14, 2024
f3245dd
Direct all tileset-related messages to a logging category
lmoureaux Aug 14, 2024
63d7383
Switch "already have a sprite for" to a qCWarning
lmoureaux Aug 14, 2024
204a0de
Disable tileset INFO messages by default
lmoureaux Aug 14, 2024
6ff7183
Don't show the "city is occupied" sprite in city_icon_widget
lmoureaux Aug 14, 2024
f7febe4
city_size_offset is relative to full_tile_offset
lmoureaux Aug 14, 2024
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
16 changes: 16 additions & 0 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,36 @@ target_sources(

audio/audio.cpp
audio/audio_none.cpp

tileset/drawn_sprite.cpp
tileset/layer_abstract_activities.cpp
tileset/layer_background.cpp
tileset/layer_base_flags.cpp
tileset/layer_city.cpp
tileset/layer_city_size.cpp
tileset/layer_darkness.cpp
tileset/layer_infrawork.cpp
tileset/layer_editor.cpp
tileset/layer_fog.cpp
tileset/layer_goto.cpp
tileset/layer_grid.cpp
tileset/layer_overlays.cpp
tileset/layer_roads.cpp
tileset/layer_special.cpp
tileset/layer_terrain.cpp
tileset/layer_units.cpp
tileset/layer_water.cpp
tileset/layer_workertask.cpp
tileset/layer.cpp
tileset/sprite.cpp
tileset/tilespec.cpp

utils/collated_sort_proxy.cpp
utils/colorizer.cpp
utils/improvement_seller.cpp
utils/unit_quick_menu.cpp
utils/unit_utils.cpp

views/view_cities.cpp
views/view_cities_data.cpp
views/view_economics.cpp
Expand All @@ -136,6 +151,7 @@ target_sources(
views/view_research.cpp
views/view_research_reqtree.cpp
views/view_units.cpp

widgets/decorations.cpp
widgets/city/city_icon_widget.cpp
widgets/city/governor_widget.cpp
Expand Down
17 changes: 9 additions & 8 deletions client/citybar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ QRect traditional_citybar_painter::paint(QPainter &painter,
unsigned long count = unit_list_size(pcity->tile->units);
count =
qBound(0UL, count,
static_cast<unsigned long>(citybar->occupancy.size - 1));
first.add_icon(citybar->occupancy.p[count]);
static_cast<unsigned long>(citybar->occupancy.size() - 1));
first.add_icon(citybar->occupancy[count]);
} else {
if (pcity->client.occupied) {
first.add_icon(citybar->occupied);
} else {
first.add_icon(citybar->occupancy.p[0]);
first.add_icon(citybar->occupancy[0]);
}
}

Expand Down Expand Up @@ -642,7 +642,7 @@ QRect polished_citybar_painter::paint(QPainter &painter,
// Decide on the target height. It's the max of the font sizes and the
// occupied indicator (we assume all indicators have the same size).
// It's used to scale the flag, progress bars and production.
double target_height = citybar->occupancy.p[0]->height();
double target_height = citybar->occupancy[0]->height();
target_height = std::max(target_height,
QFontMetricsF(get_font(FONT_CITY_NAME)).height());
target_height = std::max(target_height,
Expand Down Expand Up @@ -717,14 +717,15 @@ QRect polished_citybar_painter::paint(QPainter &painter,
// Occupied indicator
if (can_player_see_units_in_city(client.conn.playing, pcity)) {
unsigned long count = unit_list_size(pcity->tile->units);
count = qBound(0UL, count,
static_cast<unsigned long>(citybar->occupancy.size - 1));
line.add_icon(citybar->occupancy.p[count]);
count =
qBound(0UL, count,
static_cast<unsigned long>(citybar->occupancy.size() - 1));
line.add_icon(citybar->occupancy[count]);
} else {
if (pcity->client.occupied) {
line.add_icon(citybar->occupied);
} else {
line.add_icon(citybar->occupancy.p[0]);
line.add_icon(citybar->occupancy[0]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/citydlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ QPixmap unit_list_widget::create_unit_image(const unit *punit)
}

unit_pixmap.fill(Qt::transparent);
put_unit(punit, &unit_pixmap, 0, 0);
put_unit(punit, &unit_pixmap, QPoint());

if (m_show_upkeep) {
put_unit_city_overlays(punit, &unit_pixmap, 0,
Expand Down
16 changes: 13 additions & 3 deletions client/client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ int client_main(int argc, char *argv[])
{{"S", "Sound"}, _("Read sound tags from FILE."), "FILE"},
{{"m", "music"}, _("Read music tags from FILE."), "FILE"},
{{"t", "tiles"}, _("Use data file FILE.tilespec for tiles."), "FILE"},
{{"w", "warnings"}, _("Warn about deprecated modpack constructs.")}});
{{"w", "warnings"}, _("Warn about deprecated modpack constructs.")},
{"debug-tileset", _("Prints tileset debugging information.")}});
jwrober marked this conversation as resolved.
Show resolved Hide resolved

parser.addPositionalArgument(
_("url"), _("Server information in URL format."), _("[url]"));
if (!ok) {
Expand All @@ -384,8 +386,16 @@ int client_main(int argc, char *argv[])
parser.process(app);

// Process the parsed options
if (!log_init(parser.value(QStringLiteral("debug")))) {
exit(EXIT_FAILURE);

// Init log level
{
QStringList extra;
if (!parser.isSet(QStringLiteral("debug-tileset"))) {
extra.push_back(QStringLiteral("freeciv.tileset.info = false"));
}
if (!log_init(parser.value(QStringLiteral("debug")), extra)) {
exit(EXIT_FAILURE);
}
}
if (parser.isSet(QStringLiteral("version"))) {
fc_fprintf(stderr, "%s %s\n", freeciv_name_version(), client_string);
Expand Down
17 changes: 7 additions & 10 deletions client/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "page_game.h"
#include "qtg_cxxside.h"
#include "text.h"
#include "tileset/sprite.h"
#include "tileset/layer_city.h"
#include "tileset/tilespec.h"
#include "unithudselector.h"
#include "unitselect.h"
Expand Down Expand Up @@ -372,7 +372,6 @@ races_dialog::races_dialog(struct player *pplayer, QWidget *parent)
QGroupBox *no_name;
QTableWidgetItem *item;
QHeaderView *header;
QSize size;
QString title;
QLabel *ns_label;

Expand Down Expand Up @@ -452,12 +451,10 @@ races_dialog::races_dialog(struct player *pplayer, QWidget *parent)
if (i >= 0) {
item = new QTableWidgetItem;
styles->insertRow(i);
auto pix = get_sample_city_sprite(tileset, i);
item->setData(Qt::DecorationRole, *pix);
auto pix = tileset_layer_city(tileset)->sample_sprite(i);
item->setData(Qt::DecorationRole, pix);
item->setData(Qt::UserRole, style_number(pstyle));
size.setWidth(pix->width());
size.setHeight(pix->height());
item->setSizeHint(size);
item->setSizeHint(pix.size());
styles->setItem(i, 0, item);
item = new QTableWidgetItem;
item->setText(style_name_translation(pstyle));
Expand Down Expand Up @@ -1212,7 +1209,7 @@ void choice_dialog::set_layout()
pix = new QPixmap(tileset_unit_width(tileset),
tileset_unit_height(tileset));
pix->fill(Qt::transparent);
put_unit(targeted_unit, pix, 0, 0);
put_unit(targeted_unit, pix, QPoint());
target_unit_button->setIcon(QIcon(*pix));
delete pix;
target_unit_button->setIconSize(QSize(96, 96));
Expand Down Expand Up @@ -1364,7 +1361,7 @@ void choice_dialog::next_unit()
pix =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
pix->fill(Qt::transparent);
put_unit(targeted_unit, pix, 0, 0);
put_unit(targeted_unit, pix, QPoint());
target_unit_button->setIcon(QIcon(*pix));
delete pix;
switch_target();
Expand Down Expand Up @@ -1395,7 +1392,7 @@ void choice_dialog::prev_unit()
pix =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
pix->fill(Qt::transparent);
put_unit(targeted_unit, pix, 0, 0);
put_unit(targeted_unit, pix, QPoint());
target_unit_button->setIcon(QIcon(*pix));
delete pix;
switch_target();
Expand Down
1 change: 1 addition & 0 deletions client/goto.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PFPath;
struct tile;
struct unit;
struct unit_list;
struct unit_order;

enum goto_tile_state {
GTS_TURN_STEP,
Expand Down
21 changes: 7 additions & 14 deletions client/helpdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "fc_client.h"
#include "fonts.h"
#include "helpdlg.h"
#include "tileset/sprite.h"
#include "tileset/tilespec.h"
#include "views/view_map_common.h"

Expand Down Expand Up @@ -1170,7 +1169,7 @@ QPixmap *terrain_canvas(struct terrain *terrain,
for (i = 0; i < 3; ++i) {
auto sprites =
fill_basic_terrain_layer_sprite_array(tileset, i, terrain);
put_drawn_sprites(canvas, 0, canvas_y, sprites, false);
put_drawn_sprites(canvas, QPoint(0, canvas_y), sprites, false);
}

pextra = nullptr;
Expand All @@ -1183,12 +1182,12 @@ QPixmap *terrain_canvas(struct terrain *terrain,
extra_type_by_cause_iterate_end;
fc_assert_ret_val(pextra, nullptr);
auto sprites = fill_basic_extra_sprite_array(tileset, pextra);
put_drawn_sprites(canvas, 0, canvas_y, sprites, false);
put_drawn_sprites(canvas, QPoint(0, canvas_y), sprites, false);
}

if (resource != nullptr) {
auto sprites = fill_basic_extra_sprite_array(tileset, resource);
put_drawn_sprites(canvas, 0, canvas_y, sprites, false);
put_drawn_sprites(canvas, QPoint(0, canvas_y), sprites, false);
}

return canvas;
Expand Down Expand Up @@ -1245,7 +1244,6 @@ QLayout *help_widget::create_terrain_widget(const QString &title,
{
QGraphicsDropShadowEffect *effect;
QLabel *label;
QPixmap *spr;
QHBoxLayout *layout = new QHBoxLayout();
QHBoxLayout *layout1 = new QHBoxLayout();
QHBoxLayout *layout2 = new QHBoxLayout();
Expand All @@ -1267,19 +1265,14 @@ QLayout *help_widget::create_terrain_widget(const QString &title,
make_helplabel(_("Output becomes: "), tooltip, layout2);
make_helplabel(QString::number(food), tooltip, layout2)
->setProperty("foodlab", "true");
spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "citybar.food",
"citybar.food", "", "", false);
make_helppiclabel(spr, tooltip, layout2);
auto sprites = get_citybar_sprites(tileset);
make_helppiclabel(sprites->food, tooltip, layout2);
make_helplabel(QString::number(sh), tooltip, layout2)
->setProperty("shieldlab", "true");
spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "citybar.shields",
"upkeep.shield", "", "", false);
make_helppiclabel(spr, tooltip, layout2);
make_helppiclabel(sprites->shields, tooltip, layout2);
make_helplabel(QString::number(eco), tooltip, layout2)
->setProperty("ecolab", "true");
spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "citybar.trade",
"upkeep.gold", "", "", false);
make_helppiclabel(spr, tooltip, layout2);
make_helppiclabel(sprites->trade, tooltip, layout2);
w2->setLayout(layout2);

layout->addWidget(w1, Qt::AlignVCenter);
Expand Down
8 changes: 4 additions & 4 deletions client/hudwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ void hud_units::update_actions()
unit_pixmap =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
unit_pixmap->fill(Qt::transparent);
put_unit(punit, unit_pixmap, 0, 0);
put_unit(punit, unit_pixmap, QPoint());
img = unit_pixmap->toImage();
crop = zealous_crop_rect(img);
cropped_img = img.copy(crop);
Expand Down Expand Up @@ -746,7 +746,7 @@ void hud_units::update_actions()
tileset_tile_height(tileset));
}
tile_pixmap->fill(QColor(0, 0, 0, 0));
put_terrain(punit->tile, tile_pixmap, 0, 0);
put_terrain(punit->tile, tile_pixmap, QPoint());
img = tile_pixmap->toImage();
crop = zealous_crop_rect(img);
cropped_img = img.copy(crop);
Expand Down Expand Up @@ -1406,7 +1406,7 @@ void hud_unit_combat::init_images(bool redraw)
defender_pixmap.fill(Qt::transparent);
if (defender != nullptr) {
if (!redraw) {
put_unit(defender, &defender_pixmap, 0, 0);
put_unit(defender, &defender_pixmap, QPoint());
} else {
defender_pixmap =
*get_unittype_sprite(tileset, type_defender, direction8_invalid());
Expand All @@ -1430,7 +1430,7 @@ void hud_unit_combat::init_images(bool redraw)
attacker_pixmap.fill(Qt::transparent);
if (attacker != nullptr) {
if (!redraw) {
put_unit(attacker, &attacker_pixmap, 0, 0);
put_unit(attacker, &attacker_pixmap, QPoint());
} else {
attacker_pixmap =
*get_unittype_sprite(tileset, type_attacker, direction8_invalid());
Expand Down
2 changes: 1 addition & 1 deletion client/overview_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static void put_overview_tile_area(QPixmap *pcanvas, const tile *ptile,
p.fillRect(x, y, w, h, overview_tile_color(ptile));
if (gui_options->overview.fog
&& TILE_KNOWN_UNSEEN == client_tile_get_known(ptile)) {
p.drawPixmap(x, y, w, h, *get_basic_fog_sprite(tileset));
p.fillRect(x, y, w, h, QColor(0, 0, 0, 128));
}
p.end();
}
Expand Down
12 changes: 5 additions & 7 deletions client/packhand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,6 @@ void handle_city_info(const struct packet_city_info *packet)
}

pcity->client.walls = packet->walls;
if (pcity->client.walls > NUM_WALL_TYPES) {
pcity->client.walls = NUM_WALL_TYPES;
}
pcity->style = packet->style;
pcity->capital = packet->capital;
if (packet->capital == CAPITAL_PRIMARY) {
Expand Down Expand Up @@ -3303,6 +3300,10 @@ void handle_ruleset_description_part(
*/
void handle_rulesets_ready()
{
// Init extras - has to come after terrain
extra_type_iterate(pextra) { tileset_setup_extra(tileset, pextra); }
extra_type_iterate_end;

// Setup extra hiders caches
extra_type_iterate(pextra)
{
Expand Down Expand Up @@ -3356,8 +3357,7 @@ void handle_rulesets_ready()
// Adjust editor for changed ruleset.
editor_ruleset_changed();

/* We are not going to crop any more sprites from big sprites, free them.
*/
// We are not going to crop any more sprites from big sprites, free them.
finish_loading_sprites(tileset);

game.client.ruleset_ready = true;
Expand Down Expand Up @@ -4039,8 +4039,6 @@ void handle_ruleset_extra(const struct packet_ruleset_extra *p)
pextra->conflicts = p->conflicts;

pextra->helptext = packet_strvec_extract(p->helptext);

tileset_setup_extra(tileset, pextra);
}

/**
Expand Down
14 changes: 11 additions & 3 deletions client/tileset/drawn_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,28 @@
drawn_sprite::drawn_sprite(const struct tileset *ts, const QPixmap *sprite,
bool foggable, int offset_x, int offset_y)
: sprite(sprite), foggable(foggable && tileset_use_hard_coded_fog(ts)),
offset_x(offset_x), offset_y(offset_y)
offset(offset_x, offset_y)
{
fc_assert(sprite);
}

/**
* Instantiates a drawn sprite, ensuring that it's never null.
*/
drawn_sprite::drawn_sprite(const struct tileset *ts, const QPixmap *sprite,
bool foggable, const QPoint &offset)
: drawn_sprite(ts, sprite, foggable, offset.x(), offset.y())
{
}

/**
* Calculates the bounding rectangle of the given sprite array.
*/
QRect sprite_array_bounds(const std::vector<drawn_sprite> &sprs)
{
QRect bounds;
for (const auto &sprite : sprs) {
bounds |= QRect(QPoint(sprite.offset_x, sprite.offset_y),
sprite.sprite->size());
bounds |= QRect(sprite.offset, sprite.sprite->size());
}
return bounds;
}
Loading
Loading