Skip to content

Commit

Permalink
Editors now follow the same layout for the load dialog.
Browse files Browse the repository at this point in the history
- They all now have a dedicated "new" button, and a full list of items to load separated by packs and secondary categories.
- Creating a new item is currently not supported.
  • Loading branch information
Espyo committed Nov 10, 2024
1 parent efb17ee commit f6f0cc7
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 244 deletions.
3 changes: 3 additions & 0 deletions source/documents/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ Current tasks (tasks being worked on, but not yet committed)
Editor load dialogs
Load dialog should have:
History
The history should be saved as path;name, so the entry in the history can have a pretty name instead of a cryptic path
It should also list the item's pack
A button to create, which opens a new dialog
Selection of items
A way to show what pack it's from
A search filter, which is highlighted by default when the dialog opens
Mouse-overing the item should show the path
If you choose the base pack, complain
For loading, each editor has:
Anim: globals, mobs per category
Expand Down
1 change: 1 addition & 0 deletions source/source/content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
void content::load_metadata_from_data_node(data_node* node) {
reader_setter rs(node);

if(manifest) name = manifest->internal_name;
rs.set("name", name);
rs.set("description", description);
rs.set("tags", tags);
Expand Down
2 changes: 1 addition & 1 deletion source/source/content.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class plain_content {
//--- Members ---

//The content's manifest.
content_manifest* manifest;
content_manifest* manifest = nullptr;

};

Expand Down
18 changes: 13 additions & 5 deletions source/source/content_type_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ void global_anim_content_manager::load_all(CONTENT_LOAD_LEVEL level) {
void global_anim_content_manager::load_animation(content_manifest* manifest, CONTENT_LOAD_LEVEL level) {
data_node file(manifest->path);
animation_database db;
db.manifest = manifest;
db.load_from_data_node(&file);
list[manifest->internal_name] = db;
}
Expand Down Expand Up @@ -781,6 +782,7 @@ void mob_anim_content_manager::clear_manifests() {
*/
void mob_anim_content_manager::fill_manifests() {
for(size_t c = 0; c < N_MOB_CATEGORIES; c++) {
manifests.push_back(map<string, content_manifest>());
if(c == MOB_CATEGORY_NONE) continue;
mob_category* category = game.mob_categories.get((MOB_CATEGORY) c);
if(category->folder_name.empty()) return;
Expand All @@ -800,7 +802,7 @@ void mob_anim_content_manager::fill_cat_manifests_from_pack(
vector<string> type_folders = folder_to_vector_recursively(category_path, true);
for(size_t f = 0; f < type_folders.size(); f++) {
string internal_name = type_folders[f];
manifests[internal_name] = content_manifest(internal_name, category_path + "/" + internal_name + "/animations.txt", FOLDER_NAMES::BASE_PACK);
manifests[category->id][internal_name] = content_manifest(internal_name, category_path + "/" + internal_name + "/animations.txt", FOLDER_NAMES::BASE_PACK);
}
}

Expand Down Expand Up @@ -831,8 +833,11 @@ string mob_anim_content_manager::get_perf_mon_measurement_name() const {
* @param level Level to load at.
*/
void mob_anim_content_manager::load_all(CONTENT_LOAD_LEVEL level) {
for(auto &a : manifests) {
load_animation(&a.second, level);
for(size_t c = 0; c < N_MOB_CATEGORIES; c++) {
list.push_back(map<string, animation_database>());
for(auto &a : manifests[c]) {
load_animation(&a.second, level, (MOB_CATEGORY) c);
}
}
}

Expand All @@ -842,12 +847,14 @@ void mob_anim_content_manager::load_all(CONTENT_LOAD_LEVEL level) {
*
* @param manifest Manifest of the animation.
* @param level Level to load at.
* @param category_id Mob category ID.
*/
void mob_anim_content_manager::load_animation(content_manifest* manifest, CONTENT_LOAD_LEVEL level) {
void mob_anim_content_manager::load_animation(content_manifest* manifest, CONTENT_LOAD_LEVEL level, MOB_CATEGORY category_id) {
data_node file(manifest->path);
animation_database db;
db.manifest = manifest;
db.load_from_data_node(&file);
list[manifest->internal_name] = db;
list[category_id][manifest->internal_name] = db;
}


Expand Down Expand Up @@ -875,6 +882,7 @@ void mob_type_content_manager::clear_manifests() {
void mob_type_content_manager::fill_manifests() {
for(size_t c = 0; c < N_MOB_CATEGORIES; c++) {
manifests.push_back(map<string, content_manifest>());
if(c == MOB_CATEGORY_NONE) continue;
fill_manifests_map(
manifests[c],
FOLDER_PATHS_FROM_PACK::MOB_TYPES + "/" +
Expand Down
10 changes: 5 additions & 5 deletions source/source/content_type_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ class mob_anim_content_manager : public content_type_manager {

//--- Members ---

//List of animations.
map<string, animation_database> list;
//List of animations, by category.
vector<map<string, animation_database> > list;

//Manifests.
map<string, content_manifest> manifests;
//Manifests, by category.
vector<map<string, content_manifest> > manifests;


//--- Function declarations ---
Expand All @@ -369,7 +369,7 @@ class mob_anim_content_manager : public content_type_manager {
void fill_cat_manifests_from_pack(
mob_category* category, const string &pack_name
);
void load_animation(content_manifest* manifest, CONTENT_LOAD_LEVEL level);
void load_animation(content_manifest* manifest, CONTENT_LOAD_LEVEL level, MOB_CATEGORY category_id);

};

Expand Down
65 changes: 45 additions & 20 deletions source/source/game_states/animation_editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ const float ZOOM_MIN_LEVEL = 0.05f;
/**
* @brief Constructs a new animation editor object.
*/
animation_editor::animation_editor() {

animation_editor::animation_editor() :
load_dialog_picker(this) {

comparison_blink_timer =
timer(
0.6,
Expand Down Expand Up @@ -159,7 +160,7 @@ void animation_editor::change_state(const EDITOR_STATE new_state) {
* @brief Code to run when the load dialog is closed.
*/
void animation_editor::close_load_dialog() {
if(!loaded_content_yet && file_path.empty()) {
if(!loaded_content_yet && manifest.internal_name.empty()) {
//The user cancelled the load dialog
//presented when you enter the animation editor. Quit out.
leave();
Expand Down Expand Up @@ -270,7 +271,7 @@ string animation_editor::get_name() const {
* @return The name, or an empty string if none.
*/
string animation_editor::get_opened_file_name() const {
return file_path;
return manifest.internal_name;
}


Expand Down Expand Up @@ -429,7 +430,7 @@ void animation_editor::load() {

load_custom_mob_cat_types(false);

file_path.clear();
manifest.clear();
animation_exists_on_disk = false;
can_save = false;
loaded_content_yet = false;
Expand All @@ -450,7 +451,7 @@ void animation_editor::load() {

if(!auto_load_anim.empty()) {
loaded_mob_type = nullptr;
file_path = auto_load_anim;
manifest.fill_from_path(auto_load_anim);
load_animation_database(true);
} else {
open_load_dialog();
Expand All @@ -474,14 +475,13 @@ void animation_editor::load_animation_database(
game.cam.set_zoom(pre_sprite_bmp_cam_zoom);
}

file_path = standardize_path(file_path);

anims.destroy();

data_node file = data_node(file_path);
data_node file = data_node(manifest.path);
if(!file.file_was_opened) {
file.save_file(file_path, true);
file.save_file(manifest.path, true);
}
anims.manifest = &manifest;
anims.load_from_data_node(&file);

cur_anim_i.clear();
Expand Down Expand Up @@ -521,10 +521,10 @@ void animation_editor::load_animation_database(
last_spritesheet_used = file_uses_vector[0].second;
}

vector<string> file_path_parts = split(file_path, "/");
vector<string> file_path_parts = split(manifest.path, "/");

if(file_path.find(FOLDER_PATHS_FROM_PACK::MOB_TYPES + "/") != string::npos) {
vector<string> path_parts = split(file_path, "/");
if(manifest.path.find(FOLDER_PATHS_FROM_PACK::MOB_TYPES + "/") != string::npos) {
vector<string> path_parts = split(manifest.path, "/");
if(
path_parts.size() > 3 &&
path_parts[path_parts.size() - 1] == "animations.txt"
Expand Down Expand Up @@ -577,7 +577,7 @@ void animation_editor::load_animation_database(
if(loaded_mob_type) anims.fill_sound_idx_caches(loaded_mob_type);

if(should_update_history) {
update_history(file_path);
update_history(manifest.path);
save_options(); //Save the history in the options.
}

Expand Down Expand Up @@ -607,11 +607,14 @@ void animation_editor::pan_cam(const ALLEGRO_EVENT &ev) {
* @brief Callback for when the user picks an animation from the picker.
*
* @param name Name of the animation.
* @param category Unused.
* @param top_cat Unused.
* @param sec_cat Unused.
* @param info Unused.
* @param is_new Is this a new animation or an existing one?
*/
void animation_editor::pick_animation(
const string &name, const string &category, bool is_new
const string &name, const string &top_cat, const string &sec_cat,
void* info, bool is_new
) {
if(is_new) {
anims.animations.push_back(new animation(name));
Expand All @@ -629,11 +632,14 @@ void animation_editor::pick_animation(
* @brief Callback for when the user picks a sprite from the picker.
*
* @param name Name of the sprite.
* @param category Unused.
* @param top_cat Unused.
* @param sec_cat Unused.
* @param info Unused.
* @param is_new Is this a new sprite or an existing one?
*/
void animation_editor::pick_sprite(
const string &name, const string &category, bool is_new
const string &name, const string &top_cat, const string &sec_cat,
void* info, bool is_new
) {
if(is_new) {
if(anims.find_sprite(name) == INVALID) {
Expand Down Expand Up @@ -747,6 +753,25 @@ void animation_editor::mob_radius_toggle_cmd(float input_value) {
}


/**
* @brief Callback for when the user picks a file from the picker.
*
* @param name Name of the file.
* @param top_cat Unused.
* @param sec_cat Unused.
* @param info Pointer to the file's content manifest.
* @param is_new Unused.
*/
void animation_editor::pick_file(
const string &name, const string &top_cat, const string &sec_cat,
void* info, bool is_new
) {
manifest = *((content_manifest*) info);
load_animation_database(true);
close_top_dialog();
}


/**
* @brief Code to run for the play animation command.
*
Expand Down Expand Up @@ -1173,13 +1198,13 @@ bool animation_editor::save_animation_database() {
loaded_mob_type && loaded_mob_type->category->id == MOB_CATEGORY_PIKMIN
);

if(!file_node.save_file(file_path)) {
if(!file_node.save_file(manifest.path)) {
show_message_box(
nullptr, "Save failed!",
"Could not save the animation!",
(
"An error occured while saving the animation to the file \"" +
file_path + "\". Make sure that the folder it is saving to "
manifest.path + "\". Make sure that the folder it is saving to "
"exists and it is not read-only, and try again."
).c_str(),
nullptr,
Expand Down
24 changes: 12 additions & 12 deletions source/source/game_states/animation_editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class animation_editor : public editor {

//Does the animation exist on disk, or RAM only?
bool animation_exists_on_disk = false;

//Whether to use a background texture, if any.
ALLEGRO_BITMAP* bg = nullptr;

Expand Down Expand Up @@ -164,12 +164,6 @@ class animation_editor : public editor {
//The current transformation widget.
transformation_widget cur_transformation_widget;

//File path of the file currently being edited.
string file_path;

//Cache with the names of all global animation files (sans extension).
vector<string> global_anim_files_cache;

//Is the grid visible?
bool grid_visible = true;

Expand All @@ -179,6 +173,9 @@ class animation_editor : public editor {
//Last file used as for a spritesheet.
string last_spritesheet_used;

//Picker info for the picker in the "load" dialog.
picker_info load_dialog_picker;

//Mob type of the currently loaded animation file, if any.
mob_type* loaded_mob_type = nullptr;

Expand All @@ -194,9 +191,6 @@ class animation_editor : public editor {
//Before entering the sprite bitmap state, this was the camera zoom.
float pre_sprite_bmp_cam_zoom = 1.0f;

//Should the load dialog's GUI variables be reset?
bool reset_load_dialog = true;

//Is side view on?
bool side_view = false;

Expand Down Expand Up @@ -238,6 +232,10 @@ class animation_editor : public editor {
void import_sprite_transformation_data(const string &name);
bool is_cursor_in_timeline();
void load_animation_database(bool should_update_history);
void pick_file(
const string &name, const string &top_cat, const string &sec_cat,
void* info, bool is_new
);
void play_sound(size_t sound_idx);
void rename_animation(animation* anim, const string &new_name);
void rename_body_part(body_part* part, const string &new_name);
Expand Down Expand Up @@ -274,10 +272,12 @@ class animation_editor : public editor {
void open_load_dialog();
void open_options_dialog();
void pick_animation(
const string &name, const string &category, bool is_new
const string &name, const string &top_cat, const string &sec_cat,
void* info, bool is_new
);
void pick_sprite(
const string &name, const string &category, bool is_new
const string &name, const string &top_cat, const string &sec_cat,
void* info, bool is_new
);
void grid_toggle_cmd(float input_value);
void hitboxes_toggle_cmd(float input_value);
Expand Down
Loading

0 comments on commit f6f0cc7

Please sign in to comment.