15 #define GETTEXT_DOMAIN "wesnoth-editor" 34 return str !=
"0" && std::find_if(str.begin(), str.end(), [](
char c) {
return !std::isdigit(
c); }) == str.end();
71 bool hit(
int x,
int y)
const 80 if (e.button == SDL_BUTTON_LEFT) {
83 if (e.button == SDL_BUTTON_RIGHT) {
101 case SDL_MOUSEBUTTONUP:
104 case SDL_MOUSEMOTION:
111 if (!(start_state ==
state_))
141 :
gui::button(video, text)
142 , callback_(callback)
148 virtual void mouse_up(
const SDL_MouseButtonEvent&
e)
override 152 if (this->pressed()) {
166 , item_space_(20 + 3)
180 for (
int i = 1;
i < 10; ++
i) {
181 items_.push_back(std::to_string(
i));
200 widget::hide(hidden);
205 palette_menu_button->set_overlay(
"");
206 palette_menu_button->enable(
false);
236 bool scrolled =
false;
252 const int button_height = 22;
253 const int button_y = 30;
254 int bottom = target.y + target.h;
265 if (gui2::dialogs::edit_text::execute(
_(
"New Location Identifier"),
"", newid)) {
266 static const std::regex valid_id(
"[a-zA-Z0-9_]+");
267 if(std::regex_match(newid, valid_id)) {
273 _(
"Invalid location id")
276 ERR_ED <<
"entered invalid location id\n";
283 button_goto_->set_location(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height });
284 button_add_->set_location(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height });
285 button_delete_->set_location(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height });
288 const int space_for_items = bottom - target.y;
289 const int items_fitting = space_for_items /
item_space_;
295 buttons_.resize(items_fitting, lpi);
337 upscroll_button->enable(starting != 0);
339 if (downscroll_button)
340 downscroll_button->enable(ending !=
num_items());
362 const std::string item_id =
items_[starting +
i];
364 std::stringstream tooltip_text;
387 std::vector<std::string> res;
389 res.push_back(
"editor-remove-location");
399 static bool loc_id_comp(
const std::string& lhs,
const std::string& rhs) {
402 return std::stoi(lhs) < std::stoi(rhs);
418 if(itor ==
items_.begin() || *(itor - 1) !=
id) {
419 pos = std::distance(
items_.begin(),
items_.insert(itor,
id));
421 pos = std::distance(
items_.begin(), itor);
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
std::vector< location_palette_item > buttons_
virtual bool can_scroll_up() override
std::map< std::string, t_string > string_map
std::vector< events::sdl_handler * > sdl_handler_vector
virtual bool can_scroll_down() override
bool hit(int x, int y) const
editor_toolkit & toolkit_
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, const bool restore_background)
Shows a transient message to the user.
virtual bool is_selected_item(const std::string &id)
virtual std::vector< std::string > action_pressed() const override
static std::string _(const char *str)
editor::location_palette * parent_
std::unique_ptr< location_palette_button > button_goto_
virtual void draw() override
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
static bool is_positive_integer(const std::string &str)
void draw_rectangle(const SDL_Rect &rect, const color_t &color)
Draw a rectangle outline.
virtual std::string get_help_string()
Manage the empty-palette in the editor.
int num_visible_items()
Return the maximum number of items shown at the same time.
void set_item_id(const std::string &id)
const color_t NORMAL_COLOR
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
void set_selected(bool selected)
Encapsulates the map of the game.
std::string selected_item_
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
location_palette_item(CVideo &video, editor::location_palette *parent)
void mouse_up(const SDL_MouseButtonEvent &e)
void add_item(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.
Main (common) editor header.
virtual void draw_contents() override
std::unique_ptr< location_palette_button > button_add_
int set_help_string(const std::string &str)
Displays a help string with the given text.
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
const gamemap & get_map() const
std::unique_ptr< location_palette_button > button_delete_
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const color_t &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
void fill_rectangle(const SDL_Rect &rect, const color_t &color)
Draws a filled rectangle.
CVideo & video()
Gets the underlying screen object.
void draw_contents() override
virtual void select_item(const std::string &item_id)
int num_items() override
Return the number of items in the palette.
static bool loc_id_comp(const std::string &lhs, const std::string &rhs)
void hide(bool hidden) override
void handle_event(const SDL_Event &e) override
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
map_location special_location(const std::string &id) const
friend bool operator==(state_t r, state_t l)
std::vector< std::string > items_
void clear_help_string(int handle)
Removes the help string with the given handle.
virtual sdl_handler_vector handler_members() override