|
4 | 4 | #include "OpenFunscripter.h"
|
5 | 5 | #include "OFS_EventSystem.h"
|
6 | 6 | #include "OFS_VideoplayerEvents.h"
|
| 7 | +#include "OFS_Localization.h" |
7 | 8 |
|
8 |
| -inline float randf() noexcept |
9 |
| -{ |
10 |
| - return (float)rand() / (float)RAND_MAX; |
11 |
| -} |
| 9 | +#include "imgui.h" |
| 10 | +#include "imgui_stdlib.h" |
12 | 11 |
|
13 | 12 | OFS_ChapterManager::OFS_ChapterManager() noexcept
|
14 | 13 | {
|
15 | 14 | stateHandle = OFS_ProjectState<ChapterState>::Register(ChapterState::StateName);
|
16 |
| - EV::Queue().appendListener(DurationChangeEvent::EventType, |
17 |
| - DurationChangeEvent::HandleEvent( |
18 |
| - [this](const DurationChangeEvent* ev) noexcept |
19 |
| - { |
20 |
| - auto& state = ChapterState::State(stateHandle); |
21 |
| - #if 0 |
22 |
| - |
23 |
| - // Generate random chapters |
24 |
| - float duration = ev->duration; |
25 |
| - state.chapters.clear(); |
26 |
| - state.bookmarks.clear(); |
27 |
| - |
28 |
| - |
29 |
| - srand(SDL_GetTicks()); |
30 |
| - |
31 |
| - float minChapterLen = duration * 0.01f; |
32 |
| - float maxChapterLen = duration * 0.05f; |
33 |
| - |
34 |
| - float currentTime = 0.f; |
35 |
| - |
36 |
| - while(currentTime < duration) |
37 |
| - { |
38 |
| - float newChapterLen = minChapterLen + ((maxChapterLen - minChapterLen) * randf()); |
39 |
| - |
40 |
| - if(currentTime + newChapterLen > duration) |
41 |
| - { |
42 |
| - newChapterLen -= (currentTime + newChapterLen) - duration; |
43 |
| - } |
44 |
| - |
45 |
| - Chapter newChapter |
46 |
| - { |
47 |
| - currentTime, |
48 |
| - currentTime + newChapterLen, |
49 |
| - FMT("%.1f", newChapterLen) |
50 |
| - }; |
51 |
| - state.chapters.emplace_back(std::move(newChapter)); |
52 |
| - currentTime += newChapterLen; |
53 |
| - } |
54 |
| - |
55 |
| - for(int i=0; i < 10; i += 1) |
56 |
| - { |
57 |
| - float bookmarkTime = duration * randf(); |
58 |
| - Bookmark bookmark |
59 |
| - { |
60 |
| - bookmarkTime, |
61 |
| - FMT("%.1f", bookmarkTime) |
62 |
| - }; |
63 |
| - state.bookmarks.emplace_back(std::move(bookmark)); |
64 |
| - } |
65 |
| - |
66 |
| - LOGF_DEBUG("Generated %lld random chapters", state.chapters.size()); |
67 |
| - #endif |
68 |
| - } |
69 |
| - ) |
70 |
| - ); |
71 | 15 | }
|
72 | 16 |
|
73 | 17 | OFS_ChapterManager::~OFS_ChapterManager() noexcept
|
74 | 18 | {
|
75 | 19 |
|
76 | 20 | }
|
77 | 21 |
|
| 22 | +void OFS_ChapterManager::ShowWindow(bool* open) noexcept |
| 23 | +{ |
| 24 | + if(!*open) return; |
| 25 | + auto& chapterState = ChapterState::State(stateHandle); |
| 26 | + ImGui::Begin(TR_ID("ChapterManager", Tr::CHAPTERS), open); |
| 27 | + |
| 28 | + if(ImGui::BeginTable("##chapterTable", 4, ImGuiTableFlags_Resizable)) |
| 29 | + { |
| 30 | + ImGui::TableSetupColumn(TR(CHAPTER), ImGuiTableColumnFlags_None); |
| 31 | + ImGui::TableSetupColumn(TR(BEGIN), ImGuiTableColumnFlags_None); |
| 32 | + ImGui::TableSetupColumn(TR(END), ImGuiTableColumnFlags_None); |
| 33 | + ImGui::TableSetupColumn("##controls", ImGuiTableColumnFlags_WidthFixed); |
| 34 | + ImGui::TableHeadersRow(); |
| 35 | + |
| 36 | + int deleteIdx = -1; |
| 37 | + char timeBuf[16]; |
| 38 | + for(int i=0, size=chapterState.chapters.size(); i < size; i += 1) |
| 39 | + { |
| 40 | + auto& chapter = chapterState.chapters[i]; |
| 41 | + ImGui::PushID(i); |
| 42 | + |
| 43 | + ImGui::TableNextRow(); |
| 44 | + ImGui::TableSetColumnIndex(0); |
| 45 | + ImGui::ColorEdit3("##chapterColorPicker", &chapter.color.Value.x, ImGuiColorEditFlags_NoInputs); |
| 46 | + ImGui::SameLine(); |
| 47 | + ImGui::InputText("##chapterName", &chapter.name); |
| 48 | + ImGui::TableNextColumn(); |
| 49 | + |
| 50 | + Util::FormatTime(timeBuf, sizeof(timeBuf), chapter.startTime, true); |
| 51 | + ImGui::TextUnformatted(timeBuf); |
| 52 | + |
| 53 | + ImGui::TableNextColumn(); |
| 54 | + Util::FormatTime(timeBuf, sizeof(timeBuf), chapter.endTime, true); |
| 55 | + ImGui::TextUnformatted(timeBuf); |
| 56 | + |
| 57 | + ImGui::TableNextColumn(); |
| 58 | + if (ImGui::Button(TR(DELETE))) |
| 59 | + { |
| 60 | + deleteIdx = i; |
| 61 | + } |
| 62 | + ImGui::PopID(); |
| 63 | + } |
| 64 | + |
| 65 | + if(deleteIdx >= 0 && deleteIdx < chapterState.chapters.size()) |
| 66 | + { |
| 67 | + auto it = chapterState.chapters.begin() + deleteIdx; |
| 68 | + chapterState.chapters.erase(it); |
| 69 | + EV::Enqueue<ChapterStateChanged>(); |
| 70 | + } |
| 71 | + |
| 72 | + ImGui::EndTable(); |
| 73 | + } |
| 74 | + |
| 75 | + ImGui::End(); |
| 76 | +} |
| 77 | + |
78 | 78 | bool OFS_ChapterManager::ExportClip(const Chapter& chapter, const std::string& outputDirStr) noexcept
|
79 | 79 | {
|
80 | 80 | auto app = OpenFunscripter::ptr;
|
|
0 commit comments