Allow setting a custom snap value

This commit is contained in:
Stepland 2022-10-11 21:23:29 +02:00
parent 481f732bc2
commit 102c5d4915
7 changed files with 98 additions and 64 deletions

View File

@ -10,6 +10,7 @@
- The cursor height can now be changed in the settings - The cursor height can now be changed in the settings
- Frendlier error message when the UI font is not found in the assets folder - 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 - 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 🚧 ## 🚧 Small Changes 🚧
- Force using the asset folder next to the executable - Force using the asset folder next to the executable

View File

@ -325,7 +325,7 @@ void EditorState::display_playfield(Marker& marker, Judgement markerEndingState)
Toolbox::CustomConstraints::ContentSquare Toolbox::CustomConstraints::ContentSquare
); );
if (ImGui::Begin("Playfield", &showPlayfield, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { if (ImGui::Begin("Playfield", &show_playfield, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
if ( if (
not ImGui::IsWindowHovered() not ImGui::IsWindowHovered()
and chart_state and chart_state
@ -469,10 +469,10 @@ void EditorState::display_playfield(Marker& marker, Judgement markerEndingState)
/* /*
Display all metadata in an editable form Display all metadata in an editable form
*/ */
void EditorState::display_properties() { void EditorState::display_file_properties() {
if (ImGui::Begin( if (ImGui::Begin(
"Properties", "File Properties",
&showProperties, &show_file_properties,
ImGuiWindowFlags_NoResize ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_AlwaysAutoResize | 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 status of the editor. Will appear in the "Editor Status" window
*/ */
void EditorState::display_status() { void EditorState::display_status() {
ImGui::Begin("Status", &showStatus, ImGuiWindowFlags_AlwaysAutoResize); ImGui::Begin("Status", &show_status, ImGuiWindowFlags_AlwaysAutoResize);
{ {
if (not music.has_value()) { if (not music.has_value()) {
if (not song.metadata.audio.empty()) { if (not song.metadata.audio.empty()) {
@ -604,7 +604,7 @@ void EditorState::display_playback_status() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::Begin( ImGui::Begin(
"Playback Status", "Playback Status",
&showPlaybackStatus, &show_playback_status,
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs
| ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize); | 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::PushStyleColor(ImGuiCol_SliderGrabActive, ImVec4(0.240f, 0.520f, 0.880f, 0.700f));
ImGui::Begin( ImGui::Begin(
"Timeline", "Timeline",
&showTimeline, &show_timeline,
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration
| ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove); | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove);
{ {
@ -711,7 +711,7 @@ void EditorState::display_timeline() {
}; };
void EditorState::display_chart_list() { 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()) { if (this->song.charts.empty()) {
ImGui::Dummy({100, 0}); ImGui::Dummy({100, 0});
ImGui::SameLine(); ImGui::SameLine();
@ -752,7 +752,7 @@ void EditorState::display_linear_view() {
ImGui::SetNextWindowSizeConstraints(ImVec2(304, 304), ImVec2(FLT_MAX, FLT_MAX)); ImGui::SetNextWindowSizeConstraints(ImVec2(304, 304), ImVec2(FLT_MAX, FLT_MAX));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(2, 2)); 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) { if (chart_state) {
auto header_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.f; auto header_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.f;
ImGui::SetCursorPos({0, header_height}); ImGui::SetCursorPos({0, header_height});
@ -775,7 +775,7 @@ void EditorState::display_linear_view() {
}; };
void EditorState::display_sound_settings() { 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)) { if (ImGui::TreeNodeEx("Music", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::BeginDisabled(not music.has_value()); ImGui::BeginDisabled(not music.has_value());
{ {
@ -833,6 +833,23 @@ void EditorState::display_sound_settings() {
ImGui::End(); 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 { bool EditorState::needs_to_save() const {
if (chart_state) { if (chart_state) {
return not chart_state->history.current_state_is_saved(); return not chart_state->history.current_state_is_saved();
@ -1191,7 +1208,7 @@ void feis::save_close(std::optional<EditorState>& ed) {
std::optional<std::pair<std::string, better::Chart>> feis::NewChartDialog::display(EditorState& editorState) { std::optional<std::pair<std::string, better::Chart>> feis::NewChartDialog::display(EditorState& editorState) {
if (ImGui::Begin( if (ImGui::Begin(
"New Chart", "New Chart",
&editorState.showNewChartDialog, &editorState.show_new_chart_dialog,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) {
if (show_custom_dif_name) { if (show_custom_dif_name) {
combo_preview = "Custom"; combo_preview = "Custom";
@ -1270,7 +1287,7 @@ void feis::ChartPropertiesDialog::display(EditorState& editor_state) {
if (ImGui::Begin( if (ImGui::Begin(
"Chart Properties", "Chart Properties",
&editor_state.showChartProperties, &editor_state.show_chart_properties,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) {
if (show_custom_dif_name) { if (show_custom_dif_name) {
combo_preview = "Custom"; combo_preview = "Custom";

View File

@ -110,33 +110,36 @@ public:
sf::Time time_at(Fraction beat) const; sf::Time time_at(Fraction beat) const;
Fraction get_snap_step() const; Fraction get_snap_step() const;
bool showPlayfield = true; bool show_playfield = true;
void display_playfield(Marker& marker, Judgement markerEndingState); void display_playfield(Marker& marker, Judgement markerEndingState);
bool showProperties; bool show_file_properties = false;
void display_properties(); void display_file_properties();
bool showStatus; bool show_status = false;
void display_status(); void display_status();
bool showPlaybackStatus = true; bool show_playback_status = true;
void display_playback_status(); void display_playback_status();
bool showTimeline = true; bool show_timeline = true;
void display_timeline(); void display_timeline();
bool showChartList; bool show_chart_list = false;
void display_chart_list(); void display_chart_list();
bool showLinearView; bool show_linear_view = false;
void display_linear_view(); void display_linear_view();
bool showSoundSettings; bool show_sound_settings = false;
void display_sound_settings(); void display_sound_settings();
bool showNewChartDialog; bool show_editor_settings = false;
bool showChartProperties; void display_editor_settings();
bool showHistory;
bool show_new_chart_dialog = false;
bool show_chart_properties = false;
bool show_history = false;
enum class SaveOutcome { enum class SaveOutcome {
UserSaved, UserSaved,

View File

@ -69,3 +69,15 @@ bool feis::InputTextColored(
return return_value; 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();
}
}

View File

@ -12,6 +12,7 @@ namespace feis {
bool ColorEdit4(const char* label, sf::Color& col, ImGuiColorEditFlags flags = 0); bool ColorEdit4(const char* label, sf::Color& col, ImGuiColorEditFlags flags = 0);
bool InputDecimal(const char *label, Decimal* value); bool InputDecimal(const char *label, Decimal* value);
bool InputTextColored(const char* label, std::string* str, bool isValid, const std::string& hoverHelpText); bool InputTextColored(const char* label, std::string* str, bool isValid, const std::string& hoverHelpText);
void HelpMarker(const char* desc);
} }
namespace colors { namespace colors {

View File

@ -366,7 +366,7 @@ int main() {
break; break;
case sf::Keyboard::P: case sf::Keyboard::P:
if (event.key.shift) { if (event.key.shift) {
editor_state->showProperties = true; editor_state->show_file_properties = true;
} }
break; break;
case sf::Keyboard::S: case sf::Keyboard::S:
@ -437,38 +437,38 @@ int main() {
if (editor_state) { if (editor_state) {
window.clear(sf::Color(0, 0, 0)); window.clear(sf::Color(0, 0, 0));
if (editor_state->showHistory) { if (editor_state->show_history) {
editor_state->chart_state->history.display(editor_state->showHistory); 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); editor_state->display_playfield(marker, markerEndingState);
} }
if (editor_state->showLinearView) { if (editor_state->show_linear_view) {
editor_state->display_linear_view(); editor_state->display_linear_view();
} }
if (editor_state->linear_view.shouldDisplaySettings) { if (editor_state->linear_view.shouldDisplaySettings) {
editor_state->linear_view.display_settings(); editor_state->linear_view.display_settings();
} }
if (editor_state->showProperties) { if (editor_state->show_file_properties) {
editor_state->display_properties(); editor_state->display_file_properties();
} }
if (editor_state->showStatus) { if (editor_state->show_status) {
editor_state->display_status(); editor_state->display_status();
} }
if (editor_state->showPlaybackStatus) { if (editor_state->show_playback_status) {
editor_state->display_playback_status(); editor_state->display_playback_status();
} }
if (editor_state->showTimeline) { if (editor_state->show_timeline) {
editor_state->display_timeline(); editor_state->display_timeline();
} }
if (editor_state->showChartList) { if (editor_state->show_chart_list) {
editor_state->display_chart_list(); editor_state->display_chart_list();
} }
if (editor_state->showNewChartDialog) { if (editor_state->show_new_chart_dialog) {
auto pair = newChartDialog.display(*editor_state); auto pair = newChartDialog.display(*editor_state);
if (pair) { if (pair) {
auto& [dif_name, new_chart] = *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) { if (editor_state->song.charts.try_emplace(dif_name, new_chart).second) {
editor_state->open_chart(dif_name); editor_state->open_chart(dif_name);
} }
@ -476,14 +476,17 @@ int main() {
} else { } else {
newChartDialog.resetValues(); newChartDialog.resetValues();
} }
if (editor_state->showChartProperties) { if (editor_state->show_chart_properties) {
chartPropertiesDialog.display(*editor_state); chartPropertiesDialog.display(*editor_state);
} else { } else {
chartPropertiesDialog.should_refresh_values = true; chartPropertiesDialog.should_refresh_values = true;
} }
if (editor_state->showSoundSettings) { if (editor_state->show_sound_settings) {
editor_state->display_sound_settings(); editor_state->display_sound_settings();
} }
if (editor_state->show_editor_settings) {
editor_state->display_editor_settings();
}
} else { } else {
bg.render(window); bg.render(window);
} }
@ -535,7 +538,7 @@ int main() {
} }
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("Properties", "Shift+P", false, editor_state.has_value())) { if (ImGui::MenuItem("Properties", "Shift+P", false, editor_state.has_value())) {
editor_state->showProperties = true; editor_state->show_file_properties = true;
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -578,18 +581,18 @@ int main() {
} }
if (ImGui::BeginMenu("Chart", editor_state.has_value())) { if (ImGui::BeginMenu("Chart", editor_state.has_value())) {
if (ImGui::MenuItem("Chart List")) { if (ImGui::MenuItem("Chart List")) {
editor_state->showChartList = true; editor_state->show_chart_list = true;
} }
if (ImGui::MenuItem( if (ImGui::MenuItem(
"Properties##Chart", "Properties##Chart",
nullptr, nullptr,
false, false,
editor_state->chart_state.has_value())) { editor_state->chart_state.has_value())) {
editor_state->showChartProperties = true; editor_state->show_chart_properties = true;
} }
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("New Chart")) { if (ImGui::MenuItem("New Chart")) {
editor_state->showNewChartDialog = true; editor_state->show_new_chart_dialog = true;
} }
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem( if (ImGui::MenuItem(
@ -603,33 +606,36 @@ int main() {
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("View", editor_state.has_value())) { if (ImGui::BeginMenu("View", editor_state.has_value())) {
if (ImGui::MenuItem("Playfield", nullptr, editor_state->showPlayfield)) { if (ImGui::MenuItem("Playfield", nullptr, editor_state->show_playfield)) {
editor_state->showPlayfield = not editor_state->showPlayfield; editor_state->show_playfield = not editor_state->show_playfield;
} }
if (ImGui::MenuItem("Linear View", nullptr, editor_state->showLinearView)) { if (ImGui::MenuItem("Linear View", nullptr, editor_state->show_linear_view)) {
editor_state->showLinearView = not editor_state->showLinearView; editor_state->show_linear_view = not editor_state->show_linear_view;
} }
if (ImGui::MenuItem("Playback Status", nullptr, editor_state->showPlaybackStatus)) { if (ImGui::MenuItem("Playback Status", nullptr, editor_state->show_playback_status)) {
editor_state->showPlaybackStatus = not editor_state->showPlaybackStatus; editor_state->show_playback_status = not editor_state->show_playback_status;
} }
if (ImGui::MenuItem("Timeline", nullptr, editor_state->showTimeline)) { if (ImGui::MenuItem("Timeline", nullptr, editor_state->show_timeline)) {
editor_state->showTimeline = not editor_state->showTimeline; editor_state->show_timeline = not editor_state->show_timeline;
} }
if (ImGui::MenuItem("Editor Status", nullptr, editor_state->showStatus)) { if (ImGui::MenuItem("Editor Status", nullptr, editor_state->show_status)) {
editor_state->showStatus = not editor_state->showStatus; editor_state->show_status = not editor_state->show_status;
} }
if (ImGui::MenuItem("History", nullptr, editor_state->showHistory)) { if (ImGui::MenuItem("History", nullptr, editor_state->show_history)) {
editor_state->showHistory = not editor_state->showHistory; editor_state->show_history = not editor_state->show_history;
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Settings", editor_state.has_value())) { if (ImGui::BeginMenu("Settings", editor_state.has_value())) {
if (ImGui::MenuItem("Sound")) { if (ImGui::MenuItem("Sound")) {
editor_state->showSoundSettings = true; editor_state->show_sound_settings = true;
} }
if (ImGui::MenuItem("Linear View")) { if (ImGui::MenuItem("Linear View")) {
editor_state->linear_view.shouldDisplaySettings = true; editor_state->linear_view.shouldDisplaySettings = true;
} }
if (ImGui::MenuItem("Editor")) {
editor_state->show_editor_settings = true;
}
if (ImGui::BeginMenu("Marker")) { if (ImGui::BeginMenu("Marker")) {
int i = 0; int i = 0;
for (auto& tuple : markerPreviews) { for (auto& tuple : markerPreviews) {

View File

@ -80,10 +80,7 @@ float Toolbox::convertVolumeToNormalizedDB(int input) {
} }
int Toolbox::getNextDivisor(int number, int starting_point) { int Toolbox::getNextDivisor(int number, int starting_point) {
assert(number > 0); if (number <= 0 or starting_point <= 0 or starting_point >= number) {
assert(starting_point > 0 and starting_point <= number);
if (starting_point == number) {
return 1; return 1;
} else { } else {
do { do {
@ -95,10 +92,7 @@ int Toolbox::getNextDivisor(int number, int starting_point) {
} }
int Toolbox::getPreviousDivisor(int number, int starting_point) { int Toolbox::getPreviousDivisor(int number, int starting_point) {
assert(number > 0); if (number <= 0 or starting_point <= 1 or starting_point > number) {
assert(starting_point > 0 and starting_point <= number);
if (starting_point == 1) {
return number; return number;
} else { } else {
do { do {