diff --git a/CHANGELOG.md b/CHANGELOG.md index e7b159d..3369ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - The cursor height can now be changed in the settings - Frendlier error message when the UI font is not found in the assets folder - Playback position is kept instead of being reset to zero when you change charts or reload the audio file +- New menu `Settings > Editor` allows setting a custom snap value ## 🚧 Small Changes 🚧 - Force using the asset folder next to the executable diff --git a/src/editor_state.cpp b/src/editor_state.cpp index 0d1c21c..834a8dc 100644 --- a/src/editor_state.cpp +++ b/src/editor_state.cpp @@ -325,7 +325,7 @@ void EditorState::display_playfield(Marker& marker, Judgement markerEndingState) Toolbox::CustomConstraints::ContentSquare ); - if (ImGui::Begin("Playfield", &showPlayfield, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + if (ImGui::Begin("Playfield", &show_playfield, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { if ( not ImGui::IsWindowHovered() and chart_state @@ -469,10 +469,10 @@ void EditorState::display_playfield(Marker& marker, Judgement markerEndingState) /* Display all metadata in an editable form */ -void EditorState::display_properties() { +void EditorState::display_file_properties() { if (ImGui::Begin( - "Properties", - &showProperties, + "File Properties", + &show_file_properties, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize )) { @@ -562,7 +562,7 @@ Display any information that would be useful for the user to troubleshoot the status of the editor. Will appear in the "Editor Status" window */ void EditorState::display_status() { - ImGui::Begin("Status", &showStatus, ImGuiWindowFlags_AlwaysAutoResize); + ImGui::Begin("Status", &show_status, ImGuiWindowFlags_AlwaysAutoResize); { if (not music.has_value()) { if (not song.metadata.audio.empty()) { @@ -604,7 +604,7 @@ void EditorState::display_playback_status() { ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); ImGui::Begin( "Playback Status", - &showPlaybackStatus, + &show_playback_status, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize); { @@ -682,7 +682,7 @@ void EditorState::display_timeline() { ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImVec4(0.240f, 0.520f, 0.880f, 0.700f)); ImGui::Begin( "Timeline", - &showTimeline, + &show_timeline, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove); { @@ -711,7 +711,7 @@ void EditorState::display_timeline() { }; void EditorState::display_chart_list() { - if (ImGui::Begin("Chart List", &showChartList, ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::Begin("Chart List", &show_chart_list, ImGuiWindowFlags_AlwaysAutoResize)) { if (this->song.charts.empty()) { ImGui::Dummy({100, 0}); ImGui::SameLine(); @@ -752,7 +752,7 @@ void EditorState::display_linear_view() { ImGui::SetNextWindowSizeConstraints(ImVec2(304, 304), ImVec2(FLT_MAX, FLT_MAX)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(2, 2)); - if (ImGui::Begin("Linear View", &showLinearView, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + if (ImGui::Begin("Linear View", &show_linear_view, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { if (chart_state) { auto header_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.f; ImGui::SetCursorPos({0, header_height}); @@ -775,7 +775,7 @@ void EditorState::display_linear_view() { }; void EditorState::display_sound_settings() { - if (ImGui::Begin("Sound Settings", &showSoundSettings, ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::Begin("Sound Settings", &show_sound_settings)) { if (ImGui::TreeNodeEx("Music", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::BeginDisabled(not music.has_value()); { @@ -833,6 +833,23 @@ void EditorState::display_sound_settings() { ImGui::End(); } +void EditorState::display_editor_settings() { + if (ImGui::Begin("Editor Settings", &show_editor_settings)) { + static const std::uint64_t step = 1; + if (ImGui::InputScalar("Snap", ImGuiDataType_U64, &snap, &step, nullptr, "%d")) { + snap = std::clamp(snap, 1UL, 1000UL); + }; + ImGui::SameLine(); + feis::HelpMarker( + "Change the underlying snap value, this allows setting snap " + "values that aren't a divisor of 240. " + "This changes the underlying value that's multiplied " + "by 4 before being shown in the status bar" + ); + } + ImGui::End(); +} + bool EditorState::needs_to_save() const { if (chart_state) { return not chart_state->history.current_state_is_saved(); @@ -1191,7 +1208,7 @@ void feis::save_close(std::optional& ed) { std::optional> feis::NewChartDialog::display(EditorState& editorState) { if (ImGui::Begin( "New Chart", - &editorState.showNewChartDialog, + &editorState.show_new_chart_dialog, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) { if (show_custom_dif_name) { combo_preview = "Custom"; @@ -1270,7 +1287,7 @@ void feis::ChartPropertiesDialog::display(EditorState& editor_state) { if (ImGui::Begin( "Chart Properties", - &editor_state.showChartProperties, + &editor_state.show_chart_properties, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) { if (show_custom_dif_name) { combo_preview = "Custom"; diff --git a/src/editor_state.hpp b/src/editor_state.hpp index 2981657..44db593 100644 --- a/src/editor_state.hpp +++ b/src/editor_state.hpp @@ -110,33 +110,36 @@ public: sf::Time time_at(Fraction beat) const; Fraction get_snap_step() const; - bool showPlayfield = true; + bool show_playfield = true; void display_playfield(Marker& marker, Judgement markerEndingState); - bool showProperties; - void display_properties(); + bool show_file_properties = false; + void display_file_properties(); - bool showStatus; + bool show_status = false; void display_status(); - bool showPlaybackStatus = true; + bool show_playback_status = true; void display_playback_status(); - bool showTimeline = true; + bool show_timeline = true; void display_timeline(); - bool showChartList; + bool show_chart_list = false; void display_chart_list(); - bool showLinearView; + bool show_linear_view = false; void display_linear_view(); - bool showSoundSettings; + bool show_sound_settings = false; void display_sound_settings(); - bool showNewChartDialog; - bool showChartProperties; - bool showHistory; + bool show_editor_settings = false; + void display_editor_settings(); + + bool show_new_chart_dialog = false; + bool show_chart_properties = false; + bool show_history = false; enum class SaveOutcome { UserSaved, diff --git a/src/imgui_extras.cpp b/src/imgui_extras.cpp index b497d9f..7aef1b8 100644 --- a/src/imgui_extras.cpp +++ b/src/imgui_extras.cpp @@ -69,3 +69,15 @@ bool feis::InputTextColored( return return_value; } } + +void feis::HelpMarker(const char* desc) { + ImGui::TextDisabled("(?)"); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(desc); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } +} diff --git a/src/imgui_extras.hpp b/src/imgui_extras.hpp index 44a63be..1e647b1 100644 --- a/src/imgui_extras.hpp +++ b/src/imgui_extras.hpp @@ -12,6 +12,7 @@ namespace feis { bool ColorEdit4(const char* label, sf::Color& col, ImGuiColorEditFlags flags = 0); bool InputDecimal(const char *label, Decimal* value); bool InputTextColored(const char* label, std::string* str, bool isValid, const std::string& hoverHelpText); + void HelpMarker(const char* desc); } namespace colors { diff --git a/src/main.cpp b/src/main.cpp index 4c17215..15bc2bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -366,7 +366,7 @@ int main() { break; case sf::Keyboard::P: if (event.key.shift) { - editor_state->showProperties = true; + editor_state->show_file_properties = true; } break; case sf::Keyboard::S: @@ -437,38 +437,38 @@ int main() { if (editor_state) { window.clear(sf::Color(0, 0, 0)); - if (editor_state->showHistory) { - editor_state->chart_state->history.display(editor_state->showHistory); + if (editor_state->show_history) { + editor_state->chart_state->history.display(editor_state->show_history); } - if (editor_state->showPlayfield) { + if (editor_state->show_playfield) { editor_state->display_playfield(marker, markerEndingState); } - if (editor_state->showLinearView) { + if (editor_state->show_linear_view) { editor_state->display_linear_view(); } if (editor_state->linear_view.shouldDisplaySettings) { editor_state->linear_view.display_settings(); } - if (editor_state->showProperties) { - editor_state->display_properties(); + if (editor_state->show_file_properties) { + editor_state->display_file_properties(); } - if (editor_state->showStatus) { + if (editor_state->show_status) { editor_state->display_status(); } - if (editor_state->showPlaybackStatus) { + if (editor_state->show_playback_status) { editor_state->display_playback_status(); } - if (editor_state->showTimeline) { + if (editor_state->show_timeline) { editor_state->display_timeline(); } - if (editor_state->showChartList) { + if (editor_state->show_chart_list) { editor_state->display_chart_list(); } - if (editor_state->showNewChartDialog) { + if (editor_state->show_new_chart_dialog) { auto pair = newChartDialog.display(*editor_state); if (pair) { auto& [dif_name, new_chart] = *pair; - editor_state->showNewChartDialog = false; + editor_state->show_new_chart_dialog = false; if (editor_state->song.charts.try_emplace(dif_name, new_chart).second) { editor_state->open_chart(dif_name); } @@ -476,14 +476,17 @@ int main() { } else { newChartDialog.resetValues(); } - if (editor_state->showChartProperties) { + if (editor_state->show_chart_properties) { chartPropertiesDialog.display(*editor_state); } else { chartPropertiesDialog.should_refresh_values = true; } - if (editor_state->showSoundSettings) { + if (editor_state->show_sound_settings) { editor_state->display_sound_settings(); } + if (editor_state->show_editor_settings) { + editor_state->display_editor_settings(); + } } else { bg.render(window); } @@ -535,7 +538,7 @@ int main() { } ImGui::Separator(); if (ImGui::MenuItem("Properties", "Shift+P", false, editor_state.has_value())) { - editor_state->showProperties = true; + editor_state->show_file_properties = true; } ImGui::EndMenu(); } @@ -578,18 +581,18 @@ int main() { } if (ImGui::BeginMenu("Chart", editor_state.has_value())) { if (ImGui::MenuItem("Chart List")) { - editor_state->showChartList = true; + editor_state->show_chart_list = true; } if (ImGui::MenuItem( "Properties##Chart", nullptr, false, editor_state->chart_state.has_value())) { - editor_state->showChartProperties = true; + editor_state->show_chart_properties = true; } ImGui::Separator(); if (ImGui::MenuItem("New Chart")) { - editor_state->showNewChartDialog = true; + editor_state->show_new_chart_dialog = true; } ImGui::Separator(); if (ImGui::MenuItem( @@ -603,33 +606,36 @@ int main() { ImGui::EndMenu(); } if (ImGui::BeginMenu("View", editor_state.has_value())) { - if (ImGui::MenuItem("Playfield", nullptr, editor_state->showPlayfield)) { - editor_state->showPlayfield = not editor_state->showPlayfield; + if (ImGui::MenuItem("Playfield", nullptr, editor_state->show_playfield)) { + editor_state->show_playfield = not editor_state->show_playfield; } - if (ImGui::MenuItem("Linear View", nullptr, editor_state->showLinearView)) { - editor_state->showLinearView = not editor_state->showLinearView; + if (ImGui::MenuItem("Linear View", nullptr, editor_state->show_linear_view)) { + editor_state->show_linear_view = not editor_state->show_linear_view; } - if (ImGui::MenuItem("Playback Status", nullptr, editor_state->showPlaybackStatus)) { - editor_state->showPlaybackStatus = not editor_state->showPlaybackStatus; + if (ImGui::MenuItem("Playback Status", nullptr, editor_state->show_playback_status)) { + editor_state->show_playback_status = not editor_state->show_playback_status; } - if (ImGui::MenuItem("Timeline", nullptr, editor_state->showTimeline)) { - editor_state->showTimeline = not editor_state->showTimeline; + if (ImGui::MenuItem("Timeline", nullptr, editor_state->show_timeline)) { + editor_state->show_timeline = not editor_state->show_timeline; } - if (ImGui::MenuItem("Editor Status", nullptr, editor_state->showStatus)) { - editor_state->showStatus = not editor_state->showStatus; + if (ImGui::MenuItem("Editor Status", nullptr, editor_state->show_status)) { + editor_state->show_status = not editor_state->show_status; } - if (ImGui::MenuItem("History", nullptr, editor_state->showHistory)) { - editor_state->showHistory = not editor_state->showHistory; + if (ImGui::MenuItem("History", nullptr, editor_state->show_history)) { + editor_state->show_history = not editor_state->show_history; } ImGui::EndMenu(); } if (ImGui::BeginMenu("Settings", editor_state.has_value())) { if (ImGui::MenuItem("Sound")) { - editor_state->showSoundSettings = true; + editor_state->show_sound_settings = true; } if (ImGui::MenuItem("Linear View")) { editor_state->linear_view.shouldDisplaySettings = true; } + if (ImGui::MenuItem("Editor")) { + editor_state->show_editor_settings = true; + } if (ImGui::BeginMenu("Marker")) { int i = 0; for (auto& tuple : markerPreviews) { diff --git a/src/toolbox.cpp b/src/toolbox.cpp index 32031f3..d998ced 100644 --- a/src/toolbox.cpp +++ b/src/toolbox.cpp @@ -80,10 +80,7 @@ float Toolbox::convertVolumeToNormalizedDB(int input) { } int Toolbox::getNextDivisor(int number, int starting_point) { - assert(number > 0); - assert(starting_point > 0 and starting_point <= number); - - if (starting_point == number) { + if (number <= 0 or starting_point <= 0 or starting_point >= number) { return 1; } else { do { @@ -95,10 +92,7 @@ int Toolbox::getNextDivisor(int number, int starting_point) { } int Toolbox::getPreviousDivisor(int number, int starting_point) { - assert(number > 0); - assert(starting_point > 0 and starting_point <= number); - - if (starting_point == 1) { + if (number <= 0 or starting_point <= 1 or starting_point > number) { return number; } else { do {