Skip to content

Commit 239f5c3

Browse files
committed
CourseEdit: allow stages section to be collapsible/hidden, reduce width
1 parent 15f06f0 commit 239f5c3

File tree

1 file changed

+119
-115
lines changed

1 file changed

+119
-115
lines changed

src/overlay/course_editor.cpp

Lines changed: 119 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -267,161 +267,165 @@ void Overlay_CourseEditor()
267267
ImGui::EndDisabled();
268268
}
269269

270-
// TODO: editor should be disabled if playing online, since our lobbyname hack to update clients probably won't update quick enough
271-
// should only really be enabled when in the lobby & user is host, or user is playing offline
270+
bool has_updated = false;
271+
bool editor_disabled = (Game::is_in_game() && Game::pl_car()->is_in_bunki()) || !Overlay::CourseReplacementEnabled;
272272

273-
StageTable_mb* stg_tbl = *Module::exe_ptr<StageTable_mb*>(0x3D3188); // stg_tbl only points to current stage
273+
if (ImGui::TreeNodeEx("Stages", ImGuiTreeNodeFlags_DefaultOpen))
274+
{
275+
// TODO: editor should be disabled if playing online, since our lobbyname hack to update clients probably won't update quick enough
276+
// should only really be enabled when in the lobby & user is host, or user is playing offline
274277

275-
int curPlayingColumn = -1;
276-
if (stg_tbl)
277-
curPlayingColumn = stg_tbl->StageTableIdx_4;
278+
StageTable_mb* stg_tbl = *Module::exe_ptr<StageTable_mb*>(0x3D3188); // stg_tbl only points to current stage
278279

279-
bool editor_disabled = (Game::is_in_game() && Game::pl_car()->is_in_bunki()) || !Overlay::CourseReplacementEnabled;
280-
if (editor_disabled)
281-
ImGui::BeginDisabled();
280+
int curPlayingColumn = -1;
281+
if (stg_tbl)
282+
curPlayingColumn = stg_tbl->StageTableIdx_4;
282283

283-
float comboHeight = ImGui::GetFrameHeight(); // Height of a single combobox
284-
float verticalSpacing = 10.0f; // Additional spacing between comboboxes
285-
float comboWidth = 225.0f; // Width of comboboxes
284+
if (editor_disabled)
285+
ImGui::BeginDisabled();
286286

287-
float windowHeight = ImGui::GetCursorPosY() + floor(comboHeight * 5 + (verticalSpacing * 6));
287+
float comboHeight = ImGui::GetFrameHeight(); // Height of a single combobox
288+
float verticalSpacing = 10.0f; // Additional spacing between comboboxes
289+
float comboWidth = 200.f; // Width of comboboxes
288290

289-
bool has_updated = false;
291+
float windowHeight = ImGui::GetCursorPosY() + (comboHeight * 3) + floor(comboHeight * 5 + (verticalSpacing * 6));
290292

291-
int num = 0;
292-
StageTable_mb* curStage = CustomStageTable.data();
293-
for (int col = 0; col < 5; ++col)
294-
{
295-
float columnHeight = floor((comboHeight + verticalSpacing) * (col + 1) - verticalSpacing);
293+
int num = 0;
294+
StageTable_mb* curStage = CustomStageTable.data();
295+
for (int col = 0; col < 5; ++col)
296+
{
297+
float columnHeight = floor((comboHeight + verticalSpacing) * (col + 1) - verticalSpacing);
296298

297-
// Start a new column for each level of the pyramid
298-
ImGui::BeginGroup();
299+
// Start a new column for each level of the pyramid
300+
ImGui::BeginGroup();
299301

300-
// Center the column vertically
301-
float startY = (windowHeight - columnHeight) * 0.5f;
302-
ImGui::SetCursorPosY(startY);
302+
// Center the column vertically
303+
float startY = (windowHeight - columnHeight) * 0.5f;
304+
ImGui::SetCursorPosY(startY);
303305

304-
// if player is already past this column (or playing it), disable dropdowns
305-
bool col_disabled = (curPlayingColumn >= num) && !editor_disabled && Game::is_in_game();
306+
// if player is already past this column (or playing it), disable dropdowns
307+
bool col_disabled = (curPlayingColumn >= num) && !editor_disabled && Game::is_in_game();
306308

307-
for (int row = 0; row <= col; ++row)
308-
{
309-
if (col_disabled)
310-
ImGui::BeginDisabled();
309+
for (int row = 0; row <= col; ++row)
310+
{
311+
if (col_disabled)
312+
ImGui::BeginDisabled();
311313

312-
bool playingThisStage = (curPlayingColumn == num) && Game::is_in_game();
314+
bool playingThisStage = (curPlayingColumn == num) && Game::is_in_game();
313315

314-
// Highlight the current track
315-
if (playingThisStage)
316-
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.0f, 0.75f, 0.0f, 0.75f));
316+
// Highlight the current track
317+
if (playingThisStage)
318+
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.0f, 0.75f, 0.0f, 0.75f));
317319

318-
ImGui::PushID(col * 10 + row);
319-
ImGui::SetNextItemWidth(comboWidth);
320+
ImGui::PushID(col * 10 + row);
321+
ImGui::SetNextItemWidth(comboWidth);
320322

321-
int selected = curStage->StageUniqueName_0;
323+
int selected = curStage->StageUniqueName_0;
322324

323-
std::string name = std::format("{}.{}", (col + 1), (row + 1));
324-
if (ImGui::Combo(name.c_str(), &selected, Game::StageNames, int(STAGE_COUNT)))
325-
has_updated |= update_stage(num, GameStage(selected));
325+
std::string name = std::format("##{}.{}", (col + 1), (row + 1));
326+
if (ImGui::Combo(name.c_str(), &selected, Game::StageNames, int(STAGE_COUNT)))
327+
has_updated |= update_stage(num, GameStage(selected));
326328

327-
curStage++;
329+
curStage++;
328330

329-
// Add vertical spacing between comboboxes
330-
if (row <= col)
331-
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + verticalSpacing);
331+
// Add vertical spacing between comboboxes
332+
if (row <= col)
333+
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + verticalSpacing);
332334

333-
ImGui::PopID();
335+
ImGui::PopID();
334336

335-
if (playingThisStage)
336-
ImGui::PopStyleColor();
337+
if (playingThisStage)
338+
ImGui::PopStyleColor();
337339

338-
if (col_disabled)
339-
ImGui::EndDisabled();
340+
if (col_disabled)
341+
ImGui::EndDisabled();
340342

341-
num++;
342-
}
343+
num++;
344+
}
343345

344-
ImGui::EndGroup();
346+
ImGui::EndGroup();
345347

346-
if (col + 1 < 5)
347-
ImGui::SameLine(0, 20.0f);
348-
}
348+
if (col + 1 < 5)
349+
ImGui::SameLine(0, 20.0f);
350+
}
349351

350-
char* ShareCode = Overlay::CourseReplacementCode;
352+
char* ShareCode = Overlay::CourseReplacementCode;
351353

352-
ImGui::Text("Share Code: ");
353-
ImGui::SameLine();
354-
ImGui::SetNextItemWidth(500.f);
355-
ImGui::InputText("##ShareCode", ShareCode, 256);
356-
ImGui::SameLine();
357-
if (ImGui::Button("Apply Code"))
358-
{
359-
has_updated = true;
360-
sharecode_apply();
361-
}
362-
ImGui::SameLine();
363-
if (ImGui::Button("Copy Code"))
364-
{
365-
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, strlen(ShareCode) + 1);
366-
if (hMem)
354+
ImGui::Text("Share Code: ");
355+
ImGui::SameLine();
356+
ImGui::SetNextItemWidth(500.f);
357+
ImGui::InputText("##ShareCode", ShareCode, 256);
358+
ImGui::SameLine();
359+
if (ImGui::Button("Apply Code"))
367360
{
368-
memcpy(GlobalLock(hMem), ShareCode, strlen(ShareCode) + 1);
369-
GlobalUnlock(hMem);
370-
OpenClipboard(0);
371-
EmptyClipboard();
372-
SetClipboardData(CF_TEXT, hMem);
373-
CloseClipboard();
361+
has_updated = true;
362+
sharecode_apply();
374363
}
375-
}
376-
ImGui::SameLine();
377-
if (ImGui::Button("Paste Code"))
378-
{
379-
if (OpenClipboard(0))
364+
ImGui::SameLine();
365+
if (ImGui::Button("Copy Code"))
380366
{
381-
HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT);
382-
if (hClipboardData == nullptr)
383-
hClipboardData = GetClipboardData(CF_TEXT);
384-
385-
if (hClipboardData != nullptr)
367+
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, strlen(ShareCode) + 1);
368+
if (hMem)
369+
{
370+
memcpy(GlobalLock(hMem), ShareCode, strlen(ShareCode) + 1);
371+
GlobalUnlock(hMem);
372+
OpenClipboard(0);
373+
EmptyClipboard();
374+
SetClipboardData(CF_TEXT, hMem);
375+
CloseClipboard();
376+
}
377+
}
378+
ImGui::SameLine();
379+
if (ImGui::Button("Paste Code"))
380+
{
381+
if (OpenClipboard(0))
386382
{
387-
void* clipboardData = GlobalLock(hClipboardData);
388-
if (clipboardData)
383+
HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT);
384+
if (hClipboardData == nullptr)
385+
hClipboardData = GetClipboardData(CF_TEXT);
386+
387+
if (hClipboardData != nullptr)
389388
{
390-
if (hClipboardData == GetClipboardData(CF_UNICODETEXT))
389+
void* clipboardData = GlobalLock(hClipboardData);
390+
if (clipboardData)
391391
{
392-
wchar_t* wideText = static_cast<wchar_t*>(clipboardData);
393-
394-
// Convert unicode to char
395-
int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wideText, -1, nullptr, 0, nullptr, nullptr);
396-
if (bufferSize > 0 && bufferSize < sizeof(ShareCode))
397-
WideCharToMultiByte(CP_UTF8, 0, wideText, -1, ShareCode, bufferSize, nullptr, nullptr);
398-
else
392+
if (hClipboardData == GetClipboardData(CF_UNICODETEXT))
399393
{
400-
// Handle the case where the buffer is too small, truncate if necessary
401-
WideCharToMultiByte(CP_UTF8, 0, wideText, -1, ShareCode, sizeof(ShareCode) - 1, nullptr, nullptr);
402-
ShareCode[sizeof(ShareCode) - 1] = '\0'; // Null-terminate
394+
wchar_t* wideText = static_cast<wchar_t*>(clipboardData);
395+
396+
// Convert unicode to char
397+
int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wideText, -1, nullptr, 0, nullptr, nullptr);
398+
if (bufferSize > 0 && bufferSize < sizeof(ShareCode))
399+
WideCharToMultiByte(CP_UTF8, 0, wideText, -1, ShareCode, bufferSize, nullptr, nullptr);
400+
else
401+
{
402+
// Handle the case where the buffer is too small, truncate if necessary
403+
WideCharToMultiByte(CP_UTF8, 0, wideText, -1, ShareCode, sizeof(ShareCode) - 1, nullptr, nullptr);
404+
ShareCode[sizeof(ShareCode) - 1] = '\0'; // Null-terminate
405+
}
403406
}
404-
}
405-
else if (hClipboardData == GetClipboardData(CF_TEXT))
406-
{
407-
char* asciiText = static_cast<char*>(clipboardData);
408-
409-
if (strlen(asciiText) < sizeof(ShareCode))
410-
strcpy(ShareCode, asciiText);
411-
else
407+
else if (hClipboardData == GetClipboardData(CF_TEXT))
412408
{
413-
// If the clipboard text is too large, truncate
414-
strncpy(ShareCode, asciiText, sizeof(ShareCode) - 1);
415-
ShareCode[sizeof(ShareCode) - 1] = '\0'; // Null-terminate
409+
char* asciiText = static_cast<char*>(clipboardData);
410+
411+
if (strlen(asciiText) < sizeof(ShareCode))
412+
strcpy(ShareCode, asciiText);
413+
else
414+
{
415+
// If the clipboard text is too large, truncate
416+
strncpy(ShareCode, asciiText, sizeof(ShareCode) - 1);
417+
ShareCode[sizeof(ShareCode) - 1] = '\0'; // Null-terminate
418+
}
416419
}
417-
}
418-
sharecode_apply();
420+
sharecode_apply();
419421

420-
GlobalUnlock(hClipboardData);
422+
GlobalUnlock(hClipboardData);
423+
}
421424
}
425+
CloseClipboard();
422426
}
423-
CloseClipboard();
424427
}
428+
ImGui::TreePop();
425429
}
426430

427431
if (ImGui::TreeNode("Randomizer"))

0 commit comments

Comments
 (0)