16 #define GETTEXT_DOMAIN "wesnoth-editor"
30 #include <boost/regex.hpp>
33 return str !=
"0" && std::find_if(str.begin(), str.end(), [](
char c) { return !std::isdigit(c); }) == str.end();
70 bool hit(
int x,
int y)
const
79 if (
e.button == SDL_BUTTON_LEFT) {
82 if (
e.button == SDL_BUTTON_RIGHT) {
100 case SDL_MOUSEBUTTONUP:
103 case SDL_MOUSEMOTION:
110 if (!(start_state ==
state_))
147 virtual void mouse_up(
const SDL_MouseButtonEvent&
e)
override
164 , item_space_(20 + 3)
175 for (
int i = 1;
i < 10; ++
i) {
176 items_.push_back(std::to_string(
i));
200 palette_menu_button->set_overlay(
"");
201 palette_menu_button->enable(
false);
210 bool scrolled =
false;
231 bool scrolled =
false;
243 const int button_height = 22;
244 const int button_y = 30;
245 int bottom = target.y + target.h;
256 if (gui2::dialogs::edit_text::execute(
_(
"New Location Identifier"),
"", newid)) {
257 static const boost::regex valid_id(
"[a-zA-Z0-9_]+");
258 if(boost::regex_match(newid, valid_id)) {
264 _(
"Invalid location id")
267 ERR_ED <<
"entered invalid location id";
274 button_goto_->set_location(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height });
275 button_add_->set_location(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height });
276 button_delete_->set_location(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height });
279 const int space_for_items = bottom - target.y;
280 const int items_fitting = space_for_items /
item_space_;
284 if(items_fitting > 0) {
288 const std::size_t buttons_needed = items_fitting;
289 if(
buttons_.size() != buttons_needed) {
291 buttons_.resize(buttons_needed, lpi);
298 dstrect.w = target.w - 10;
301 dstrect.x = target.x;
302 dstrect.y = target.y +
static_cast<int>(
i) *
item_space_;
348 if(downscroll_button)
372 const std::string item_id =
items_[item_index];
376 std::stringstream tooltip_text;
399 std::vector<std::string> res;
401 res.push_back(
"editor-remove-location");
411 static bool loc_id_comp(
const std::string& lhs,
const std::string& rhs) {
427 decltype(
items_)::difference_type pos;
431 if(itor ==
items_.begin() || *(itor - 1) !=
id) {
432 pos = std::distance(
items_.begin(),
items_.insert(itor,
id));
434 pos = std::distance(
items_.begin(), itor);
440 const std::size_t unsigned_pos = pos;
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
void set_help_string(const std::string &str)
Sets and shows the tooltip-like text at the top or bottom of the map area.
const editor_map & get_map() const
void clear_help_string()
Removes the help string.
List of starting locations and location ids.
virtual bool can_scroll_down() override
std::unique_ptr< location_palette_button > button_goto_
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
std::vector< std::string > items_
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
virtual void layout() override
Called by draw_manager to validate layout before drawing.
void hide(bool hidden) override
std::vector< location_palette_item > buttons_
std::size_t num_items() override
Return the number of items in the palette.
virtual bool can_scroll_up() override
virtual void draw_contents() override
Called by widget::draw()
void add_item(const std::string &id)
virtual bool is_selected_item(const std::string &id)
std::string get_help_string() const
std::unique_ptr< location_palette_button > button_add_
editor_toolkit & toolkit_
virtual sdl_handler_vector handler_members() override
std::string selected_item_
virtual std::vector< std::string > action_pressed() const override
std::size_t num_visible_items()
Return the number of GUI elements that can show items.
virtual void select_item(const std::string &item_id)
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
std::unique_ptr< location_palette_button > button_delete_
location_palette(editor_display &gui, editor_toolkit &toolkit)
map_location special_location(const std::string &id) const
void mouse_up(const SDL_MouseButtonEvent &e)
void set_item_id(const std::string &id)
editor::location_palette * parent_
void set_selected(bool selected)
location_palette_item(editor::location_palette *parent)
bool hit(int x, int y) const
void handle_event(const SDL_Event &e) override
void draw_contents() override
Drawing functions, for drawing things on the screen.
Main (common) editor header.
std::vector< events::sdl_handler * > sdl_handler_vector
static std::string _(const char *str)
static bool is_positive_integer(const std::string &str)
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void rect(const SDL_Rect &rect)
Draw a rectangle.
Manage the empty-palette in the editor.
static bool loc_id_comp(const std::string &lhs, const std::string &rhs)
rect pango_draw_text(bool actually_draw, const rect &area, int size, const color_t &color, const std::string &text, int x, int y, bool use_tooltips, pango_text::FONT_STYLE style)
Draws text on the screen.
const color_t NORMAL_COLOR
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
int stoi(std::string_view str)
Same interface as std::stoi and meant as a drop in replacement, except:
std::map< std::string, t_string > string_map
Transitional API for porting SDL_ttf-based code to Pango.
friend bool operator==(state_t r, state_t l)
Encapsulates the map of the game.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.