Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Commit 74f0261

Browse files
authored
Merge pull request #29 from chown2/the_table_epic_part_2
Table manager: add button to find current song
2 parents c2d1aab + 2341aa7 commit 74f0261

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/Helpers/Logger.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ void Logger::LogOut(std::string buffer) {
1010
std::time_t timeStamp = std::time(NULL);
1111
logFile << std::put_time(std::localtime(&timeStamp), "%D %T ") << buffer;
1212
logFile << std::endl << std::endl;
13-
logFile.close();
1413
}
1514

1615
void Logger::SetPath(std::string path) {
17-
mLogPath = path;
16+
mLogPath = std::move(path);
1817
}

src/LR2HackBox/Features/TableManager.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ void TableManager::Gui() {
349349
}
350350
ImGui::InputText("Symbol", &selectedTable->symbol);
351351

352+
static float tables_current_y{};
353+
static std::optional<float> tables_move_to_this_y;
352354
int flags = ImGuiTableFlags(ImGuiTableFlags_ScrollY) | ImGuiTableFlags(ImGuiTableFlags_RowBg)
353355
| ImGuiTableFlags(ImGuiTableFlags_BordersOuter) | ImGuiTableFlags(ImGuiTableFlags_Resizable)
354356
| ImGuiTableFlags(ImGuiTableFlags_SizingStretchSame) | ImGuiTableFlags(ImGuiTableFlags_Sortable)
@@ -373,11 +375,8 @@ void TableManager::Gui() {
373375
bool stringMode = false;
374376
int leftLevel{};
375377
int rightLevel{};
376-
377378
if (auto [ptr, ec] = std::from_chars(left.level.data(), left.level.data() + left.level.size(), leftLevel); ec != std::errc()) stringMode = true;
378-
379379
if (auto [ptr, ec] = std::from_chars(right.level.data(), right.level.data() + right.level.size(), rightLevel); ec != std::errc()) stringMode = true;
380-
381380
if (stringMode) {
382381
if (left.level != right.level)
383382
return spec.SortDirection == ImGuiSortDirection_Ascending ? left.level < right.level : left.level > right.level;
@@ -416,6 +415,11 @@ void TableManager::Gui() {
416415
ImGui::InputText(levelInputId.c_str(), &entry.level);
417416
}
418417
if (toDelete != selectedTable->entries.end()) selectedTable->entries.erase(toDelete);
418+
if (tables_move_to_this_y) {
419+
ImGui::SetScrollY(*tables_move_to_this_y);
420+
tables_move_to_this_y.reset();
421+
}
422+
tables_current_y = ImGui::GetScrollY();
419423
ImGui::EndTable();
420424
}
421425
if (ImGui::Button("Add Song")) {
@@ -426,6 +430,23 @@ void TableManager::Gui() {
426430
force_resort = true;
427431
}
428432
}
433+
ImGui::SameLine();
434+
if (ImGui::Button("Find")) {
435+
LR2::SONGSELECT& select = LR2HackBox::Get().GetGame()->sSelect;
436+
LR2::SONGDATA& curSong = select.bmsList[select.cur_song];
437+
std::string_view hash{ curSong.hash.body };
438+
auto lineSize = ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().ItemSpacing.y;
439+
auto curEntryIdx = std::min(static_cast<size_t>((tables_current_y + lineSize / 2) / lineSize), selectedTable->entries.size());
440+
// Doesn't work at the bottom of the list but whatever as that would require calculating lots of viewport things because ImGui lacks API to manipulate viewport position within table.
441+
auto it = std::ranges::find(selectedTable->entries.begin() + curEntryIdx + 1, selectedTable->entries.end(), hash, &Entry::md5);
442+
if (it == selectedTable->entries.end()) {
443+
it = std::ranges::find(selectedTable->entries.begin(), selectedTable->entries.begin() + curEntryIdx, hash, &Entry::md5);
444+
}
445+
if (it != selectedTable->entries.end()) {
446+
auto idxToMoveTo = std::distance(selectedTable->entries.begin(), it);
447+
tables_move_to_this_y = idxToMoveTo * lineSize;
448+
}
449+
}
429450

430451
if (ImGui::Button("Save")) {
431452
if (item_selected_idx == 0) {
@@ -509,6 +530,7 @@ void TableManager::Menu() {
509530
"To create a table, select 'NEW TABLE' at the top of table selector dropdown, specify its name and symbol, and press 'Save' button. If it succeeds, a new table will be available in the selector. Table won't be created if a table with same name already exists, or if the table folder with same name already exists in the output path.\n\n"
510531
"No changes to the table are written to its files before you press the 'Save' button.\n\n"
511532
"To add a song, hover over it in the LR2 song select wheel and press 'Add Song' button. It will appear in the list, and its level can be edited in the box right of its name. Song can be removed from the table with a double-click on its name.\n\n"
533+
"'Find' button scrolls to the next closest entry for the currently selected song.\n\n"
512534
"'Delete' button permanently deletes the table and its files. A confirmation is required after pressing it.\n\n"
513535
"'Reload' button reloads the contents of the current output path, resetting any unsaved changes to the tables.\n\n"
514536
"Table song list can be sorted by pressing the column header. If you want two-level sort, you can hold shift and click the second column header to sort against.\n\n"

src/LR2HackBox/Features/Unrandomizer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,7 @@ void Unrandomizer::Menu() {
376376
}
377377
ImGui::SameLine();
378378
HelpMarker("R-Random cyclically shifts the columns by a random amount, as well as has a chance to mirror them\n\nOnly this or random trainer can be enabled at a time");
379-
ImGui::Checkbox("##unrandomizer_isSeed", &mIsSeeded);
380-
ImGui::SameLine();
381-
ImGui::TextUnformatted("Force Seed:");
379+
ImGui::Checkbox("Force Seed:", &mIsSeeded);
382380
ImGui::SameLine();
383381
ImGui::SetNextItemWidth(ImGui::CalcTextSize("32767X").x);
384382
if (ImGui::InputInt("##unrandomizer_seed", &mSeed, 0)) {

0 commit comments

Comments
 (0)