Skip to content

Commit

Permalink
Show crude information in the tileset debugger
Browse files Browse the repository at this point in the history
The sprites drawn by each layer are shown. Offsets are not accounted for, and
no reason is given for which sprites were selected. Some layers do not work
(for instance, the grid); they probably require pedge or pcorner.

See #632.
lmoureaux committed Sep 12, 2021
1 parent bed608e commit def8e1d
Showing 6 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/control.cpp
Original file line number Diff line number Diff line change
@@ -802,7 +802,7 @@ void unit_focus_update()
/**
Return a pointer to a visible unit, if there is one.
*/
struct unit *find_visible_unit(struct tile *ptile)
unit *find_visible_unit(const ::tile *ptile)
{
struct unit *panyowned = NULL, *panyother = NULL, *ptptother = NULL;

2 changes: 1 addition & 1 deletion client/control.h
Original file line number Diff line number Diff line change
@@ -176,7 +176,7 @@ void unit_focus_update();
void auto_center_on_focus_unit();
void update_unit_pix_label(struct unit_list *punitlist);

struct unit *find_visible_unit(struct tile *ptile);
unit *find_visible_unit(const ::tile *ptile);
void set_units_in_combat(struct unit *pattacker, struct unit *pdefender);
int blink_active_unit();
int blink_turn_done_button();
47 changes: 45 additions & 2 deletions client/gui-qt/tileset_debugger.cpp
Original file line number Diff line number Diff line change
@@ -13,6 +13,11 @@
// client/include
#include "dialogs_g.h"

// client
#include "climap.h"
#include "editor.h"
#include "tilespec.h"

// common
#include "map.h"
#include "tile.h"
@@ -22,6 +27,7 @@

#include <QLabel>
#include <QToolBar>
#include <QTreeWidget>
#include <QVBoxLayout>

namespace freeciv {
@@ -36,6 +42,8 @@ namespace freeciv {
*/
tileset_debugger::tileset_debugger(QWidget *parent) : QDialog(parent)
{
setWindowTitle(_("Tileset debugger"));

auto layout = new QVBoxLayout;
setLayout(layout);

@@ -51,7 +59,12 @@ tileset_debugger::tileset_debugger(QWidget *parent) : QDialog(parent)
&tileset_debugger::pick_tile);

m_label = new QLabel;
layout->addWidget(m_label, 100, Qt::AlignCenter);
layout->addWidget(m_label);

m_content = new QTreeWidget;
m_content->setHeaderHidden(true);
m_content->setSelectionMode(QAbstractItemView::NoSelection);
layout->addWidget(m_content, 100);

set_tile(nullptr);
}
@@ -75,9 +88,39 @@ void tileset_debugger::set_tile(const ::tile *t)
return;
}

m_label->setText(QStringLiteral("%1 %2")
m_label->setText(QString(_("Tile at %1, %2"))
.arg(index_to_map_pos_x(tile_index(t)))
.arg(index_to_map_pos_y(tile_index(t))));

// Fill tile data
m_content->clear();

auto maxSize = QSize(); // Max sprite size
for (const auto &layer : tileset_get_layers(tileset)) {
auto item = new QTreeWidgetItem(m_content);

const auto name = mapview_layer_name(layer->type());
item->setText(0, name);

// Get the list of sprites for this layer
::unit *unit = nullptr;
if (client_tile_get_known(t) != TILE_UNKNOWN
|| (editor_is_active() && editor_tile_is_selected(t))) {
unit = get_drawable_unit(tileset, t);
}
const auto sprites = layer->fill_sprite_array(t, nullptr, nullptr, unit,
tile_city(t), nullptr);

// Add the sprites as children
for (const auto &ds : sprites) {
auto child = new QTreeWidgetItem(item);
child->setIcon(0, QIcon(*ds.sprite));
maxSize = maxSize.expandedTo(ds.sprite->size());
}
}

m_content->setIconSize(maxSize);
m_content->expandAll();
}

/**
2 changes: 2 additions & 0 deletions client/gui-qt/tileset_debugger.h
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@

class QAction;
class QLabel;
class QTreeWidget;

struct tile;

@@ -38,6 +39,7 @@ private slots:
const ::tile *m_tile;
QLabel *m_label;
QAction *m_pick_action;
QTreeWidget *m_content;
};

} // namespace freeciv
2 changes: 1 addition & 1 deletion client/tilespec.cpp
Original file line number Diff line number Diff line change
@@ -5240,7 +5240,7 @@ void toggle_focus_unit_state(struct tileset *t)
/**
Find unit that we can display from given tile.
*/
struct unit *get_drawable_unit(const struct tileset *t, struct tile *ptile)
struct unit *get_drawable_unit(const struct tileset *t, const ::tile *ptile)
{
struct unit *punit = find_visible_unit(ptile);

2 changes: 1 addition & 1 deletion client/tilespec.h
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ int get_focus_unit_toggle_timeout(const struct tileset *t);
void reset_focus_unit_state(struct tileset *t);
void focus_unit_in_combat(struct tileset *t);
void toggle_focus_unit_state(struct tileset *t);
struct unit *get_drawable_unit(const struct tileset *t, struct tile *ptile);
struct unit *get_drawable_unit(const struct tileset *t, const ::tile *ptile);
bool unit_drawn_with_city_outline(const struct unit *punit,
bool check_focus);

0 comments on commit def8e1d

Please sign in to comment.