19 #include <QCommandLinkButton>
20 #include <QMouseEvent>
78 for (
auto qgilles : qAsConst(
king()->trade_gen.lines)) {
93 if (qgilles.autocaravan !=
nullptr) {
98 pen.setStyle(Qt::DashLine);
101 painter->setPen(pen);
102 if (x2 - x1 == w && y2 - y1 == h) {
116 for (
auto *pcity : qAsConst(
king()->trade_gen.virtual_cities)) {
117 float canvas_x, canvas_y;
118 if (pcity->tile !=
nullptr
120 painter->drawPixmap(
static_cast<int>(canvas_x),
121 static_cast<int>(canvas_y),
131 : QWidget(), m_renderer(new
freeciv::renderer(this)),
133 std::make_unique<QPropertyAnimation>(m_renderer,
"origin")),
134 m_scale_animation(std::make_unique<QPropertyAnimation>(this,
"scale"))
137 qOverload<const QRegion &>(&map_view::update));
140 QTimer *timer =
new QTimer(
this);
141 setAttribute(Qt::WA_OpaquePaintEvent,
true);
145 setMouseTracking(
true);
146 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
157 setCursor(Qt::ArrowCursor);
162 i =
static_cast<int>(ct);
164 setCursor(*(
king()->fc_cursors[i][0]));
172 QList<fcwidget *>
fcl = this->findChildren<fcwidget *>();
173 for (
auto *widget : qAsConst(
fcl)) {
174 if (widget->isVisible()) {
219 float diff_x, diff_y;
315 ||
queen()->top_bar_wdg->underMouse()) {
375 auto delta =
event->angleDelta();
377 if (
event->modifiers() == Qt::NoModifier) {
380 }
else if (
event->modifiers() == Qt::ShiftModifier) {
384 }
else if (
event->modifiers() == Qt::ControlModifier) {
388 }
else if (delta.y() < 0) {
406 auto candidate = QRect(QPoint(),
size);
408 const auto children = findChildren<QWidget *>();
409 while (candidate.bottom() < height()) {
411 if (!std::any_of(children.begin(), children.end(),
412 [candidate](
const QWidget *child) {
413 return child->isVisible()
414 && candidate.intersects(child->rect());
417 return candidate.topLeft();
421 if (candidate.right() +
step < width()) {
423 candidate.moveTo(candidate.left() +
step, candidate.top());
426 candidate.moveTo(0, candidate.top() +
step);
448 if (
queen()->unitinfo_wdg->isVisible()) {
487 dirty |= QRect(canvas_x * scale, canvas_y * scale, pixel_width * scale,
488 pixel_height * scale);
499 dirty |= QRect(QPoint(),
queen()->mapview_wdg->size());
521 const QPixmap *ssprite)
535 float canvas_x, canvas_y;
561 if (
auto debugger =
queen()->mapview_wdg->debugger();
562 debugger !=
nullptr) {
571 if (
queen()->isRepoDlgOpen(QStringLiteral(
"SCI"))) {
584 QMessageBox *ask =
new QMessageBox(
king()->central_wdg);
585 ask->setWindowTitle(
_(
"Error loading tileset"));
586 ask->setAttribute(Qt::WA_DeleteOnClose);
589 QString(
_(
"There was an error loading tileset \"%1\". You can still "
590 "use it, but it might be incomplete."))
592 ask->setIcon(QMessageBox::Warning);
593 ask->setStandardButtons(QMessageBox::Close);
596 ask->addButton(
_(
"Open tileset &debugger"), QMessageBox::AcceptRole);
597 QObject::connect(button, &QPushButton::clicked,
queen()->mapview_wdg,
613 : QLabel(parent), itile(ptile)
627 auto size = sizeHint();
630 QFontMetrics fm = fontMetrics();
631 const auto max_width = fm.averageCharWidth() * 70;
632 if (
size.width() > max_width) {
633 size.setWidth(max_width + 10);
634 size.setHeight(heightForWidth(
size.width()) + 10);
643 if (y - height() > 0) {
649 x = std::clamp(
int(x), 0, parentWidget()->width() - width());
684 struct unit *punit =
nullptr;
734 struct city *pcity,
int *width,
int *height)
747 auto rect = painter->paint(p, QPointF(canvas_x, canvas_y), pcity);
748 *width = rect.width();
749 *height = rect.height();
struct city * is_any_city_dialog_open()
void popdown_city_dialog()
Closes the city overlay.
static citybar_painter * current()
Returns the current painter (never null).
static fcFont * instance()
Returns instance of fc_font.
void repaint_needed(const QRegion &where)
void set_viewport_size(const QSize &size)
Instructs the renderer to draw a viewport with a different size.
void set_scale(double scale)
Changes the scale of the rendering (zooms in or out).
void set_origin(const QPointF &origin)
Changes the origin of the canvas (the point at the top left of the view).
void render(QPainter &painter, const QRegion ®ion) const
Renders the specified region of the visible portion of the map on painter.
A dialog to perform debugging of the tileset.
void tile_picking_requested(bool active)
void update_actions()
Update possible action for given units.
static info_tile * m_instance
static void drop()
Deletes current instance.
void calc_size()
Calculates size of info_tile and moves it to be fully visible.
static info_tile * i(struct tile *p=nullptr)
Returns given instance.
info_tile(struct tile *ptile, QWidget *parent=0)
Constructor for info_tile.
static bool shown()
Check if the info tile is currently shown.
void paintEvent(QPaintEvent *event) override
Slot inherited from QPixamp.
void scale_changed(double scale) const
void resizeEvent(QResizeEvent *event) override
The widget has been resized.
void set_scale_now(double scale)
Sets the map scale immediately without doing any animation.
std::unique_ptr< QPropertyAnimation > m_scale_animation
void timer_event()
Timer for cursor.
map_view()
Constructor for map.
void zoom_out()
Zooms out by 20%.
void center_on_tile(tile *tile, bool animate=true)
Centers the view on a tile.
void update_cursor(enum cursor_type)
Updates cursor.
void zoom_reset()
Resets the zoom level.
std::vector< QPointer< fcwidget > > m_hidden_fcwidgets
void hide_all_fcwidgets()
Hides all fcwidgets (reports etc).
void focusOutEvent(QFocusEvent *event) override
Focus lost event.
freeciv::renderer * m_renderer
QPoint find_place(const QSize &size) const
Finds a suitable location for a widget of the given size, avoiding overlap with other widgets.
void show_all_fcwidgets()
Shows all fcwidgets (reports etc).
void leaveEvent(QEvent *event) override
Leave event.
void show_debugger()
Opens the tileset debugger.
void wheelEvent(QWheelEvent *event) override
The user wants to scroll.
void hide_debugger()
Closes the tileset debugger if it is open.
std::unique_ptr< QPropertyAnimation > m_origin_animation
void set_scale(double scale, bool animate=true)
Sets the map scale.
void zoom_in()
Zooms in by 20%.
QPointer< freeciv::tileset_debugger > m_debugger
The panel at the bottom right of the game screen, holding the minimap and the Turn Done button.
int gimmeIndexOf(const QString &str)
Returns index on game tab page of given report dialog.
fc_game_tab_widget * game_tab_widget
void update_report()
Updates all important widgets on science_report.
void reset_tree()
Recalculates research diagram again and updates science report.
bool can_client_control()
Returns TRUE iff the client can control player.
enum known_type client_tile_get_known(const struct tile *ptile)
A tile's "known" field is used by the server to store whether each player knows the tile.
QColor get_color(const struct tileset *t, enum color_std stdcolor)
Return a pointer to the given "standard" color.
std::vector< unit * > & get_units_in_focus()
Returns list of units currently in focus.
unit * find_visible_unit(const ::tile *ptile)
Return a pointer to a visible unit, if there is one.
enum cursor_hover_state hover_state
void set_hover_state(const std::vector< unit * > &units, enum cursor_hover_state state, enum unit_activity activity, struct extra_type *tgt, int last_tgt, int last_sub_tgt, action_id action, enum unit_orders order)
Enter the given hover state.
void clear_hover_state()
Clear current hover state (go to HOVER_NONE).
class fc_client * king()
Return fc_client instance.
#define fc_assert_ret(condition)
#define fc_assert(condition)
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
Finds the difference between the two (unnormalized) positions, in cartesian (map) coordinates.
#define index_to_map_pos(pmap_x, pmap_y, mindex)
bool get_turn_done_button_state()
Return TRUE iff the turn done button should be enabled.
const char *const notify_label
client_options * gui_options
pageGame * queen()
Return game instandce.
static void static sol::state * fcl
Lua virtual machine state.
int smooth_center_slide_msec
bool draw_city_trade_routes
const QString popup_info_text(struct tile *ptile)
Text to popup on a middle-click in the mapview.
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
const char * tileset_name_get(const struct tileset *t)
Return tileset name.
const QPixmap * get_attention_crosshair_sprite(const struct tileset *t)
Returns a sprite with the "user-attention" crosshair graphic.
int tileset_citybar_offset_y(const struct tileset *t)
Return the offset from the origin of the city tile at which to place the city bar text.
int tileset_tile_height(const struct tileset *t)
Return the tile height of the current tileset.
double tileset_preferred_scale(const struct tileset *t)
Returns the preferred scale (zoom level) of the tileset.
bool tileset_has_error(const struct tileset *t)
Checks if the tileset had any error message (LOG_ERROR).
int tileset_tile_width(const struct tileset *t)
Return the tile width of the current tileset.
#define NUM_CURSOR_FRAMES
bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
Check if cities have an established trade route.
bool unit_has_orders(const struct unit *punit)
Return TRUE iff the unit is following client-side orders.
void update_turn_done_button(bool do_restore)
If do_restore is false it should change the turn button style (to draw the user's attention to it).
void dirty_all(void)
Mark the entire screen area as "dirty" so that we can flush it later.
void popup_tile_info(struct tile *ptile)
Popups information label tile.
void tileset_changed(void)
This function is called when the tileset is changed.
void put_cross_overlay_tile(struct tile *ptile)
Draw a cross-hair overlay on a tile.
void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
Area Selection.
void dirty_rect(int canvas_x, int canvas_y, int pixel_width, int pixel_height)
Mark the rectangular region as "dirty" so that we know to flush it later.
bool mapview_is_frozen()
Return whether the map should be drawn or not.
void popdown_tile_info()
Popdowns information label tile.
void show_city_desc(QPixmap *pcanvas, int canvas_x, int canvas_y, struct city *pcity, int *width, int *height)
Draw a description for the given city.
int last_center_player_city
void debug_tile(tile *tile)
Callback to set the tile being debugged.
int last_center_enemy_city
void draw_calculated_trade_routes(QPainter *painter)
Draws calculated trade routes.
static int mapview_frozen_level
void start_turn()
New turn callback.
void flush_dirty()
Flush all regions that have been previously marked as dirty.
void update_unit_info_label(const std::vector< unit * > &unit_list)
Update the information label which gives info on the current unit and the tile under the current unit...
void pixmap_put_overlay_tile(int canvas_x, int canvas_y, const QPixmap *ssprite)
Put overlay tile to pixmap.
void update_mouse_cursor(enum cursor_type new_cursor_type)
Update the mouse cursor.
void destroy_city_dialog()
void map_to_gui_vector(const struct tileset *t, float *gui_dx, float *gui_dy, int map_dx, int map_dy)
Translate from a cartesian system to the GUI system.
void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair)
Marks the given tile as having a "crosshair" map decoration.
void mapdeco_clear_crosshairs()
Clears all previous set tile crosshair decorations.
void mapdeco_set_gotoroute(const struct unit *punit)
Set the map decorations for the given unit's goto route.
void map_to_gui_pos(const struct tileset *t, float *gui_x, float *gui_y, int map_x, int map_y)
Translate from map to gui coordinate systems.
void gui_distance_vector(const struct tileset *t, float *gui_dx, float *gui_dy, float gui_x0, float gui_y0, float gui_x1, float gui_y1)
Find the vector with minimum "real" distance between two GUI positions.
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, const tile *ptile)
Finds the canvas coordinates for a map position.
void mapdeco_clear_gotoroutes()
Clear all goto line map decorations and queues mapview updates for the affected tiles.
static void swap(struct reqtree *tree, int layer, int order1, int order2)
Swap positions of two nodes on the same layer.