Editor: better default addon and schedule names
This commit is contained in:
parent
78f7703639
commit
6fb5488464
2 changed files with 16 additions and 8 deletions
|
@ -55,6 +55,7 @@
|
|||
#include "units/animation_component.hpp"
|
||||
#include "quit_confirmation.hpp"
|
||||
#include "sdl/input.hpp" // get_mouse_button_mask
|
||||
#include "serialization/chrono.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
@ -254,7 +255,8 @@ void editor_controller::custom_tods_dialog()
|
|||
tod_dlg.register_callback(update_func);
|
||||
|
||||
/* Autogenerate schedule id */
|
||||
std::int64_t current_millis = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
static constexpr std::string_view ts_format = "%Y-%m-%d_%H-%M-%S";
|
||||
std::string timestamp = chrono::format_local_timestamp(std::chrono::system_clock::now(), ts_format);
|
||||
std::string sch_id = current_addon_id_+"-schedule";
|
||||
/* Set correct textdomain */
|
||||
t_string sch_name("", "wesnoth-"+current_addon_id_);
|
||||
|
@ -272,14 +274,14 @@ void editor_controller::custom_tods_dialog()
|
|||
|
||||
/* In case the ID or Name field is blank and user presses OK */
|
||||
if (sch_id.empty()) {
|
||||
sch_id = current_addon_id_+"-schedule-"+std::to_string(current_millis);
|
||||
sch_id = current_addon_id_ + "-schedule-" + timestamp;
|
||||
} else {
|
||||
/* Check if the id entered is same as any of the existing ids
|
||||
* If so, replace */
|
||||
// TODO : Notify the user if they enter an already existing schedule ID
|
||||
for (auto map_elem : tods_) {
|
||||
if (sch_id == map_elem.first) {
|
||||
sch_id = current_addon_id_+"-schedule-"+std::to_string(current_millis);
|
||||
sch_id = current_addon_id_ + "-schedule-" + timestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "gui/dialogs/prompt.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "editor/action/action_base.hpp"
|
||||
#include "serialization/chrono.hpp"
|
||||
|
||||
lg::log_domain log_editor("editor");
|
||||
|
||||
|
@ -42,11 +43,16 @@ std::string initialize_addon()
|
|||
}
|
||||
|
||||
if(addon_id == "///newaddon///") {
|
||||
std::string& addon_id_new = addon_id;
|
||||
std::int64_t current_millis = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
addon_id = "MyAwesomeAddon-"+std::to_string(current_millis);
|
||||
if (gui2::dialogs::prompt::execute(addon_id_new)) {
|
||||
addon_id = !addon_filename_legal(addon_id_new) ? "MyAwesomeAddon-"+std::to_string(current_millis) : addon_id_new;
|
||||
static constexpr std::string_view ts_format = "%Y-%m-%d_%H-%M-%S";
|
||||
std::string timestamp = chrono::format_local_timestamp(std::chrono::system_clock::now(), ts_format);
|
||||
|
||||
addon_id = "MyAwesomeAddon-" + timestamp;
|
||||
std::string addon_id_new = addon_id;
|
||||
|
||||
if(gui2::dialogs::prompt::execute(addon_id_new)) {
|
||||
if(addon_filename_legal(addon_id_new)) {
|
||||
addon_id = addon_id_new;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue