The Battle for Wesnoth  1.19.7+dev
editor_display.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "map/editor_map.hpp"
19 #include "display.hpp"
20 
21 namespace editor {
22 
23 class editor_display : public display
24 {
25 public:
27 
28  bool in_editor() const override { return true; }
29 
30  void add_brush_loc(const map_location& hex);
31  void set_brush_locs(const std::set<map_location>& hexes);
32  void clear_brush_locs();
33  void remove_brush_loc(const map_location& hex);
34  const editor_map& get_map() const { return static_cast<const editor_map&>(context().map()); }
35  void rebuild_terrain(const map_location &loc);
36 
37  /** Inherited from display. */
38  virtual const time_of_day& get_time_of_day(const map_location& loc = map_location::null_location()) const override;
39 
41  {
42  return controller_;
43  }
44 
45  /**
46  * TLD layout() override. Replaces old refresh_reports(). Be sure to
47  * call the base class method as well.
48  *
49  * This updates some reports that may need to be refreshed every frame.
50  */
51  virtual void layout() override;
52 
53  /** Sets texture to be drawn in hex under the mouse's location. */
55  {
57  }
58 
60  {
62  }
63 
64  /**
65  * Set a status text at the bottom left of the map area
66  *
67  * @param str The text to display.
68  * @param is_success Type of message.
69  * When true, message is shown in green with checkmark.
70  * When false, message is shown in red with cross mark
71  */
72  void set_status(const std::string& str, const bool is_success);
73 
74  /**
75  * Sets and shows the tooltip-like text at the top or bottom of the map area.
76  *
77  * @param str The text to display.
78  */
79  void set_help_string(const std::string& str);
80 
81  /** Removes the help string. */
82  void clear_help_string();
83 
84  /** Returns whether the help text is currently shown. */
85  bool help_string_enabled() const
86  {
87  return help_string_enabled_;
88  }
89 
90  /** Sets whether the help text should be shown. */
91  void set_help_string_enabled(bool value);
92 
93 protected:
94  void draw_hex(const map_location& loc) override;
95 
96  /** Inherited from display. */
97  virtual overlay_map& get_overlays() override;
98 
99  rect get_clip_rect() const override;
100 
101  std::set<map_location> brush_locations_;
102 
103  /* The controller that owns this display. */
105 
107 
108 private:
109  /** ID of the floating label that's controlled by set_help_string() / clear_help_string(). */
110  int help_handle_ = 0;
111 
112  /**
113  * Ignored when help_handle_ == 0. Othewise, true if the help label obscures the
114  * northern hexes in the map area, false if it's over the southern hexes instead.
115  */
116  bool help_string_at_top_ = false;
117 
118  /** Whether the help text is currently shown. */
119  bool help_string_enabled_ = true;
120 
121  /** Current help string, cached for easy visibility toggling. */
122  std::string help_string_;
123 };
124 
125 } //end namespace editor
map_location loc
Definition: move.cpp:172
virtual const gamemap & map() const =0
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:97
std::map< map_location, std::vector< overlay > > overlay_map
Definition: display.hpp:903
const display_context & context() const
Definition: display.hpp:193
The editor_controller class contains the mouse and keyboard event handling routines for the editor.
std::string help_string_
Current help string, cached for easy visibility toggling.
void set_mouseover_hex_overlay(const texture &image)
Sets texture to be drawn in hex under the mouse's location.
virtual overlay_map & get_overlays() override
Inherited from display.
virtual void layout() override
TLD layout() override.
bool help_string_enabled() const
Returns whether the help text is currently shown.
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const override
Inherited from display.
void set_help_string(const std::string &str)
Sets and shows the tooltip-like text at the top or bottom of the map area.
void rebuild_terrain(const map_location &loc)
int help_handle_
ID of the floating label that's controlled by set_help_string() / clear_help_string().
rect get_clip_rect() const override
Get the clipping rectangle for drawing.
std::set< map_location > brush_locations_
bool help_string_at_top_
Ignored when help_handle_ == 0.
bool help_string_enabled_
Whether the help text is currently shown.
void remove_brush_loc(const map_location &hex)
editor_controller & controller_
editor_controller & get_controller()
bool in_editor() const override
void set_help_string_enabled(bool value)
Sets whether the help text should be shown.
editor_display(editor_controller &controller, reports &reports_object)
void add_brush_loc(const map_location &hex)
void draw_hex(const map_location &loc) override
Redraws a single gamemap location.
void set_brush_locs(const std::set< map_location > &hexes)
const editor_map & get_map() const
void set_status(const std::string &str, const bool is_success)
Set a status text at the bottom left of the map area.
void clear_help_string()
Removes the help string.
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:33
void reset()
Releases ownership of the managed texture and resets the ptr to null.
Definition: texture.cpp:208
map_display and display: classes which take care of displaying the map and game-data on the screen.
Manage the empty-palette in the editor.
Definition: action.cpp:31
Functions to load and save images from/to disk.
Unit and team statistics.
Encapsulates the map of the game.
Definition: location.hpp:45
static const map_location & null_location()
Definition: location.hpp:102
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:47
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57