The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
edit_unit.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 - 2025
3 by Subhraman Sarkar (babaissarkar) <sbmskmm@protonmail.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 "game_config_view.hpp"
20#include "gui/widgets/group.hpp"
24
25#include <boost/dynamic_bitset.hpp>
26
27namespace gui2::dialogs
28{
29/**
30 * Dialog that allows user to create custom unit types.
31 */
33{
34public:
35 editor_edit_unit(const game_config_view& game_config, const std::string& addon_id);
36
37 /** The execute function. See @ref modal_dialog for more information. */
39
40 /** Write the cfg file */
41 void write();
42
43private:
45 const std::string& addon_id_;
46
49
50 /**
51 * Used to control checkboxes for various resistances, defences, etc.
52 * so that only specific values are overridden.
53 */
54 boost::dynamic_bitset<> res_toggles_, def_toggles_, move_toggles_;
55
57 std::vector<config> specials_list_, abilities_list_;
58
59 std::vector<std::pair<boost::dynamic_bitset<>, config>> attacks_;
60
61 /** Generated WML */
62 std::string generated_wml;
63
64 /** 0 means there are no attacks. 1 is the first attack, and so on.*/
65 unsigned int selected_attack_ = 0;
66
67 virtual void pre_show() override;
68
69 virtual const std::string& window_id() const override;
70
71 /** Load Unit Type data from cfg */
72 void load_unit_type();
73
74 /** Save Unit Type data to cfg */
75 void save_unit_type();
76
77 /** Update wml preview */
78 void update_wml_view();
79
80 /** Callback for loading movetype data in UI */
81 void load_movetype();
82
83 /** Callback for resistance list */
84 void update_resistances();
85 void store_resistances();
87
88 /** Callbacks for defense list */
89 void update_defenses();
90 void store_defenses();
92
93 /** Callbacks for movement list */
97
98 /** Callbacks for attack page */
99 void store_attack();
100 void update_attacks();
101 void add_attack();
102 void delete_attack();
103 void update_index();
104 void next_attack();
105 void prev_attack();
106 void select_attack();
107
108 /** Callback when an tab item in the "page" listbox is selected */
109 void on_page_select();
110
111 /** Callback for file select button */
112 void select_file(const std::string& default_dir, const std::string& id_stem);
113
114 /** Callback for image update */
115 void update_image(const std::string& id_stem);
116
117 /** Callback to enable/disable OK button if ID/Name is invalid */
118 void button_state_change();
119
120 /** Quit confirmation */
121 void quit_confirmation();
122
123 /** Utility method to check if ID contains any invalid characters */
124 bool check_id(const std::string& id);
125
126 void set_selected_from_string(menu_button& list, std::vector<config> values, const std::string& item) {
127 for (unsigned i = 0; i < values.size(); ++i) {
128 if(values.at(i)["label"] == item) {
129 list.set_selected(i);
130 break;
131 }
132 }
133 }
134
135 void set_selected_from_string(combobox& list, std::vector<config> values, const std::string& item) {
136 for (unsigned i = 0; i < values.size(); ++i) {
137 if(values.at(i)["label"] == item) {
138 list.set_selected(i);
139 break;
140 }
141 }
142 list.set_value(item);
143 }
144
145 /* signal handler for Ctrl+O shorcut */
147 const event::ui_event /*event*/,
148 bool& handled,
149 const SDL_Keycode key,
150 SDL_Keymod modifier);
151};
152
153} // namespace gui2::dialogs
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
A class grating read only view to a vector of config objects, viewed as one config with all children ...
Class for a combobox.
Definition combobox.hpp:37
void set_selected(unsigned selected, bool fire_event=true)
Definition combobox.cpp:300
Dialog that allows user to create custom unit types.
Definition edit_unit.hpp:33
unsigned int selected_attack_
0 means there are no attacks.
Definition edit_unit.hpp:65
void write()
Write the cfg file.
void quit_confirmation()
Quit confirmation.
void set_selected_from_string(menu_button &list, std::vector< config > values, const std::string &item)
std::vector< config > defense_list_
Definition edit_unit.hpp:56
boost::dynamic_bitset res_toggles_
Used to control checkboxes for various resistances, defences, etc.
Definition edit_unit.hpp:54
const game_config_view & game_config_
Definition edit_unit.hpp:44
std::vector< std::pair< boost::dynamic_bitset<>, config > > attacks_
Definition edit_unit.hpp:59
std::vector< config > abilities_list_
Definition edit_unit.hpp:57
void store_attack()
Callbacks for attack page.
std::vector< config > movetype_list_
Definition edit_unit.hpp:56
std::vector< config > race_list_
Definition edit_unit.hpp:56
void update_defenses()
Callbacks for defense list.
std::string generated_wml
Generated WML.
Definition edit_unit.hpp:62
void save_unit_type()
Save Unit Type data to cfg.
std::vector< config > align_list_
Definition edit_unit.hpp:56
void button_state_change()
Callback to enable/disable OK button if ID/Name is invalid.
void signal_handler_sdl_key_down(const event::ui_event, bool &handled, const SDL_Keycode key, SDL_Keymod modifier)
void select_file(const std::string &default_dir, const std::string &id_stem)
Callback for file select button.
virtual const std::string & window_id() const override
The ID of the window to build.
boost::dynamic_bitset move_toggles_
Definition edit_unit.hpp:54
void update_movement_costs()
Callbacks for movement list.
std::vector< config > resistances_list_
Definition edit_unit.hpp:56
void on_page_select()
Callback when an tab item in the "page" listbox is selected.
void update_resistances()
Callback for resistance list.
bool check_id(const std::string &id)
Utility method to check if ID contains any invalid characters.
void set_selected_from_string(combobox &list, std::vector< config > values, const std::string &item)
const std::string & addon_id_
Definition edit_unit.hpp:45
std::vector< config > specials_list_
Definition edit_unit.hpp:57
boost::dynamic_bitset def_toggles_
Definition edit_unit.hpp:54
void load_unit_type()
Load Unit Type data from cfg.
virtual void pre_show() override
Actions to be taken before showing the window.
Definition edit_unit.cpp:74
void update_wml_view()
Update wml preview.
std::vector< config > usage_type_list_
Definition edit_unit.hpp:56
DEFINE_SIMPLE_EXECUTE_WRAPPER(editor_edit_unit)
The execute function.
void load_movetype()
Callback for loading movetype data in UI.
void update_image(const std::string &id_stem)
Callback for image update.
Abstract base class for all modal dialogs.
void set_selected(unsigned selected, bool fire_event=true)
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
Game configuration data as global variables.
ui_event
The event sent to the dispatcher.
Definition handler.hpp:115
#define i