Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 888566c

Browse files
add basic chapter window #69
1 parent 5e96ec9 commit 888566c

File tree

5 files changed

+69
-62
lines changed

5 files changed

+69
-62
lines changed

localization/localization.csv

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,7 @@ REMOVE_BOOKMARK_MSG,Do you want to remove the bookmark?,Do you want to remove th
527527
ADD_NEW_CHAPTER,Add chapter,Add chapter
528528
ADD_NEW_BOOKMARK,Add bookmark,Add bookmark
529529
SET_CHAPTER_SIZE,Set size,Set size
530-
SAVE_HEATMAP_WITH_CHAPTERS,Save heatmap with chapters,Save heatmap with chapters
530+
SAVE_HEATMAP_WITH_CHAPTERS,Save heatmap with chapters,Save heatmap with chapters
531+
CHAPTERS,Chapters,Chapters
532+
CHAPTER,Chapter,Chapter
533+
BEGIN,Begin,Begin

src/OpenFunscripter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,10 +1575,9 @@ void OpenFunscripter::Step() noexcept
15751575
LoadedProject->ShowProjectWindow(&ShowProjectEditor);
15761576

15771577
extensions->ShowExtensions();
1578-
15791578
OFS_FileLogger::DrawLogWindow(&ofsState.showDebugLog);
1580-
15811579
keys->RenderKeybindingWindow();
1580+
chapterMgr->ShowWindow(&ofsState.showChapterManager);
15821581

15831582
if (preferences->ShowPreferenceWindow()) {}
15841583

@@ -2452,6 +2451,7 @@ void OpenFunscripter::ShowMainMenuBar() noexcept
24522451
if (ImGui::MenuItem(TR(ACTION_EDITOR), NULL, &ofsState.showActionEditor)) {}
24532452
if (ImGui::MenuItem(TR(SPECIAL_FUNCTIONS), NULL, &ofsState.showSpecialFunctions)) {}
24542453
if (ImGui::MenuItem(TR(WEBSOCKET_API), NULL, &ofsState.showWsApi)) {}
2454+
if (ImGui::MenuItem(TR(CHAPTERS), NULL, &ofsState.showChapterManager)) {}
24552455

24562456

24572457
ImGui::Separator();

src/UI/OFS_ChapterManager.cpp

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,77 @@
44
#include "OpenFunscripter.h"
55
#include "OFS_EventSystem.h"
66
#include "OFS_VideoplayerEvents.h"
7+
#include "OFS_Localization.h"
78

8-
inline float randf() noexcept
9-
{
10-
return (float)rand() / (float)RAND_MAX;
11-
}
9+
#include "imgui.h"
10+
#include "imgui_stdlib.h"
1211

1312
OFS_ChapterManager::OFS_ChapterManager() noexcept
1413
{
1514
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-
);
7115
}
7216

7317
OFS_ChapterManager::~OFS_ChapterManager() noexcept
7418
{
7519

7620
}
7721

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+
7878
bool OFS_ChapterManager::ExportClip(const Chapter& chapter, const std::string& outputDirStr) noexcept
7979
{
8080
auto app = OpenFunscripter::ptr;

src/UI/OFS_ChapterManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ class OFS_ChapterManager
1515
~OFS_ChapterManager() noexcept;
1616

1717
static bool ExportClip(const class Chapter& chapter, const std::string& outputDirStr) noexcept;
18+
19+
void ShowWindow(bool* open) noexcept;
1820
};

src/state/OpenFunscripterState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct OpenFunscripterState
4040
bool showSimulator = true;
4141
bool showSpecialFunctions = false;
4242
bool showWsApi = false;
43+
bool showChapterManager = false;
4344

4445
inline static OpenFunscripterState& State(uint32_t stateHandle) noexcept
4546
{
@@ -67,4 +68,5 @@ REFL_TYPE(OpenFunscripterState)
6768
REFL_FIELD(showSimulator)
6869
REFL_FIELD(showSpecialFunctions)
6970
REFL_FIELD(showWsApi)
71+
REFL_FIELD(showChapterManager)
7072
REFL_END

0 commit comments

Comments
 (0)