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

Initial tileset debugger #633

Merged
merged 12 commits into from
Sep 12, 2021
18 changes: 16 additions & 2 deletions client/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void set_hover_state(struct unit_list *punits, enum cursor_hover_state state,
enum unit_orders order)
{
fc_assert_ret((punits && unit_list_size(punits) > 0)
|| state == HOVER_NONE);
|| (state == HOVER_NONE || state == HOVER_DEBUG_TILE));
fc_assert_ret(state == HOVER_CONNECT || activity == ACTIVITY_LAST);
fc_assert_ret((state == HOVER_GOTO || state == HOVER_GOTO_SEL_TGT)
|| order == ORDER_LAST);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1285,6 +1285,7 @@ void control_mouse_cursor(struct tile *ptile)
break;
case HOVER_ACT_SEL_TGT:
case HOVER_GOTO_SEL_TGT:
case HOVER_DEBUG_TILE:
/* Select a tile to target / find targets on. */
mouse_cursor_type = CURSOR_SELECT;
break;
Expand Down Expand Up @@ -2748,6 +2749,16 @@ void do_map_click(struct tile *ptile, enum quickselect_type qtype)
fc_assert(action_id_exists(goto_last_action));
do_unit_goto(ptile);
break;
case HOVER_DEBUG_TILE:
// This function is called twice, once on mouse press and once on mouse
// release. We get SELECT_POPUP the second time.
// We don't want to do anything the first time we're called to avoid
// selecting units or opening the tile dialog.
if (qtype == SELECT_POPUP) {
debug_tile(ptile);
clear_hover_state();
}
return;
}

clear_hover_state();
Expand Down Expand Up @@ -3032,6 +3043,9 @@ void key_cancel_action()
keyboardless_goto_active = false;
keyboardless_goto_start_tile = NULL;
break;
case HOVER_DEBUG_TILE:
clear_hover_state();
break;
case HOVER_NONE:
break;
};
Expand Down
3 changes: 2 additions & 1 deletion client/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum cursor_hover_state {
HOVER_PATROL,
HOVER_ACT_SEL_TGT,
HOVER_GOTO_SEL_TGT,
HOVER_DEBUG_TILE,
};

// Selecting unit from a stack without popup.
Expand Down Expand Up @@ -175,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();
Expand Down
1 change: 1 addition & 0 deletions client/goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ static void goto_fill_parameter_full(struct goto_map *goto_map,
case HOVER_NONE:
case HOVER_PARADROP:
case HOVER_ACT_SEL_TGT:
case HOVER_DEBUG_TILE:
fc_assert_msg(hover_state != HOVER_NONE, "Goto with HOVER_NONE?");
fc_assert_msg(hover_state != HOVER_PARADROP,
"Goto with HOVER_PARADROP?");
Expand Down
1 change: 1 addition & 0 deletions client/gui-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ add_library(
spaceshipdlg.cpp
sprite.cpp
themes.cpp
tileset_debugger.cpp
tradecalculation.cpp
tooltips.cpp
unitreport.cpp
Expand Down
6 changes: 6 additions & 0 deletions client/gui-qt/fc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "page_scenario.h"
#include "sidebar.h"
#include "sprite.h"
#include "tileset_debugger.h"
#include "voteinfo_bar.h"

fcFont *fcFont::m_instance = 0;
Expand Down Expand Up @@ -256,6 +257,11 @@ void fc_client::switch_page(int new_pg)
set_client_page(PAGE_MAIN);
break;
}

// Maybe popdown the tileset debugger
if (page != PAGE_GAME) {
queen()->mapview_wdg->hide_debugger();
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions client/gui-qt/fc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QMainWindow>
#include <QPixmapCache>
#include <QStackedWidget>

// common
#include "packets.h"
// client
Expand All @@ -36,6 +37,10 @@ class QTimerEvent;
class choice_dialog;
struct server_scan;

namespace freeciv {
class tileset_debugger;
}

enum connection_state {
LOGIN_TYPE,
NEW_PASSWORD_TYPE,
Expand Down
43 changes: 43 additions & 0 deletions client/gui-qt/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,40 @@ void map_view::show_all_fcwidgets()
m_hidden_fcwidgets.clear();
}

/**
* Ppens the tileset debugger.
*/
void map_view::show_debugger()
{
if (!m_debugger) {
// We never destroy it once it's created.
m_debugger = new freeciv::tileset_debugger(this);
connect(m_debugger, &freeciv::tileset_debugger::tile_picking_requested,
[](bool active) {
if (active) {
set_hover_state(NULL, HOVER_DEBUG_TILE, ACTIVITY_LAST, NULL,
NO_TARGET, NO_TARGET, ACTION_NONE,
ORDER_LAST);
} else if (!active && hover_state == HOVER_DEBUG_TILE) {
clear_hover_state();
}
});
}

m_debugger->show();
}

/**
* Closes the tileset debugger if it is open.
*/
void map_view::hide_debugger()
{
if (m_debugger) {
m_debugger->set_tile(nullptr);
m_debugger->close();
}
}

/**
Timer for cursor
*/
Expand Down Expand Up @@ -773,3 +807,12 @@ void show_city_desc(QPixmap *pcanvas, int canvas_x, int canvas_y,

p.end();
}

/**
* Callback to set the tile being debugged.
*/
void debug_tile(tile *tile)
{
fc_assert_ret(queen()->mapview_wdg->m_debugger);
queen()->mapview_wdg->m_debugger->set_tile(tile);
}
14 changes: 14 additions & 0 deletions client/gui-qt/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
// Qt
#include <QFrame>
#include <QLabel>
#include <QPointer>
#include <QQueue>
#include <QThread>
#include <QTimer>

// gui-qt
#include "tileset_debugger.h"

// common
#include "tilespec.h"

Expand All @@ -37,6 +42,10 @@ void draw_calculated_trade_routes(QPainter *painter);
**************************************************************************/
class map_view : public QWidget {
Q_OBJECT

// Ought to be a private slot
friend void debug_tile(tile *tile);

void shortcut_pressed(int key);
void shortcut_released(Qt::MouseButton mb);

Expand All @@ -54,6 +63,10 @@ class map_view : public QWidget {

bool menu_click;

public slots:
void show_debugger();
void hide_debugger();

protected:
void paintEvent(QPaintEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
Expand All @@ -71,6 +84,7 @@ private slots:
bool stored_autocenter;
int cursor_frame{0};
int cursor;
QPointer<freeciv::tileset_debugger> m_debugger = nullptr;
std::vector<fcwidget *> m_hidden_fcwidgets;
};

Expand Down
3 changes: 3 additions & 0 deletions client/gui-qt/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ void mr_menu::setup_menus()
connect(act, &QAction::triggered, this, &mr_menu::shortcut_options);
act = menu->addAction(_("Load another tileset"));
connect(act, &QAction::triggered, this, &mr_menu::tileset_custom_load);
act = menu->addAction(_("Tileset debugger"));
connect(act, &QAction::triggered, queen()->mapview_wdg,
&map_view::show_debugger);
act = menu->addAction(_("Save Options Now"));
act->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
connect(act, &QAction::triggered, this, &mr_menu::save_options_now);
Expand Down
Loading