Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions src/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void Animation::load_animation()
std::string line;
std::ifstream meta_file;
this->current_frame_number = 0;
this->total_frames_number = 0;
this->total_frames_files = 0;
this->time_at_last_frame = std::chrono::system_clock::now();
meta_file.open((this->anim_folder + std::string("meta.txt")).c_str());
Expand Down Expand Up @@ -54,11 +53,11 @@ void Animation::load_animation()
{
try
{
std::string raw_frames_order((line.substr(13, line.length() - 13)).c_str());
std::string raw_frames_order((line.substr(14, line.length() - 14)).c_str());

size_t start;
size_t end = 0;

while((start = raw_frames_order.find_first_not_of(' ', end)) != std::string::npos)
{
end = raw_frames_order.find(' ', start);
Expand All @@ -77,10 +76,37 @@ void Animation::load_animation()
}
catch(const std::exception& e) {}
}

// Passive frames
found = line.find("Passive frames: ");
if (found != std::string::npos)
{
try
{
this->passive_frames = std::stoi(line.substr(16, line.length() - 16).c_str());
}
catch(const std::exception& e) {}
}

// Active frames
found = line.find("Active frames: ");
if (found != std::string::npos)
{
try
{
this->active_frames = std::stoi(line.substr(15, line.length() - 15).c_str());
}
catch(const std::exception& e) {}
}
}

// Check frames order = passive + active frames
if (this->frames_order.size() != this->passive_frames + this->active_frames) {
fprintf(stderr, "Warning: Animation `%s` frames order size(%d) is different than passive(%d) + active(%d) frames!\n", this->anim_name.c_str(), (int)this->frames_order.size(), this->passive_frames, this->active_frames);
}

meta_file.close();

if(total_frames_ok && time_per_frame_ok && frames_ok)
this->valid_animation = 1;
else
Expand Down Expand Up @@ -114,11 +140,9 @@ Animation::~Animation()

void Animation::next_frame()
{
this->current_frame_number+= 1;
if(this->current_frame_number >= (int)this->frames_order.size())
{
this->current_frame_number += 1;
if((this->active && this->current_frame_number >= (int)this->passive_frames + (int)this->active_frames) || (!this->active && this->current_frame_number >= (int)this->passive_frames))
this->current_frame_number = 0;
}
}

bool Animation::read_frames_from_files()
Expand Down Expand Up @@ -334,7 +358,10 @@ int Animation::get_current_frame_number()

int Animation::get_total_frames_number()
{
return this->total_frames_number;
if (this->active)
return this->passive_frames + this->active_frames;
else
return this->passive_frames;
}

int Animation::get_total_frames_files()
Expand Down
5 changes: 4 additions & 1 deletion src/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ class Animation
private:
bool valid_animation = false;
int current_frame_number = 0;
int total_frames_number = 0;
int total_frames_files = 0;
GLuint* frames = NULL;
uint8_t** frames_pixels = NULL;
float time_per_frame;
std::vector<int> frames_order;
std::chrono::system_clock::time_point time_at_last_frame;

uint passive_frames = 0;
uint active_frames = 0;

public:
bool selected = false;
bool active = false;

int min_butthurt = 0;
int max_butthurt = 14;
Expand Down
6 changes: 6 additions & 0 deletions src/AnimationWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,9 @@ void AnimationWallet::replace_min_max_butthurt(int new_min_butthurt, int new_max
anim->max_butthurt = new_max_butthurt;
}
}

void AnimationWallet::set_active(bool active)
{
for(Animation* anim : this->animations)
anim->active = active;
}
1 change: 1 addition & 0 deletions src/AnimationWallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AnimationWallet
void replace_weight(int new_weight, int old_weight);
void replace_min_max_level(int new_min_level, int new_max_level);
void replace_min_max_butthurt(int new_min_butthurt, int new_max_butthurt);
void set_active(bool active);
};

#endif
22 changes: 20 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ int main(int argc, char* argv[])

// popup modal for animation preview
bool not_used_popup_modal_preview = true;
bool active_frames = animations_wallet->animations.at(current_anim)->active;
if(ImGui::BeginPopupModal(animations_wallet->animations.at(current_anim)->anim_name.c_str(), &not_used_popup_modal_preview, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar))
{
ImGui::Image((void*)(intptr_t)animations_wallet->animations.at(current_anim)->get_frame(), ImVec2(image_width*7.f, image_height*7.f));
Expand Down Expand Up @@ -353,7 +354,14 @@ int main(int argc, char* argv[])
}
}
ImGui::SameLine();
ImGui::Text("Frame %d/%d", animations_wallet->animations.at(current_anim)->get_current_frame_number() + 1, animations_wallet->animations.at(current_anim)->get_total_frames_files());
ImGui::Text("Frame %03d/%03d", animations_wallet->animations.at(current_anim)->get_current_frame_number() + 1, animations_wallet->animations.at(current_anim)->get_total_frames_number());
ImGui::SameLine();
if(ImGui::Checkbox("Active frames", &active_frames)) {
if (active_frames)
animations_wallet->animations.at(current_anim)->active = true;
else
animations_wallet->animations.at(current_anim)->active = false;
}
ImGui::Separator();
// level sliders
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.385f);
Expand Down Expand Up @@ -517,10 +525,20 @@ int main(int argc, char* argv[])
ImGui::MenuItem("Change level...");
if(ImGui::IsItemClicked())
ImGui::OpenPopup("Change level");

ImGui::MenuItem("Change butthurt...");
if(ImGui::IsItemClicked())
ImGui::OpenPopup("Change butthurt");
ImGui::MenuItem("Show only passive frames...");
if(ImGui::IsItemClicked()) {
animations_wallet->set_active(false);
notifications.add_notification(NOTIF_SUCCESS, "Success", "Show only passive frames for every animations.");
}
ImGui::MenuItem("Show active frames...");
if(ImGui::IsItemClicked()) {
animations_wallet->set_active(true);
notifications.add_notification(NOTIF_SUCCESS, "Success", "Show active frames for every animations.");
}

bool change_weight_popup = true;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(30, 20));
Expand Down