Skip to content

Commit

Permalink
Replace help tab with about tab, add about page draw callback
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeCrazyGuy committed Jun 20, 2024
1 parent 607590b commit 52c88a4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 35 deletions.
38 changes: 38 additions & 0 deletions src/about_tab.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "main.h"
#include "about_tab.h"
#include "callback.h"

static const auto SimpleDraw = GetBetterAPI()->SimpleDraw;

extern void draw_about_tab() {
uint32_t num_about;
const auto handles = CallbackGetHandles(CALLBACKTYPE_ABOUT, &num_about);

static const auto to_string = [](const void* handles, uint32_t index, char* fmt, uint32_t fmt_size) noexcept -> const char* {
const RegistrationHandle* hs = (const RegistrationHandle*)handles;
return CallbackGetName(hs[index]);
};

static uint32_t selected = UINT32_MAX;
SimpleDraw->HBoxLeft(0, 12.f);
SimpleDraw->SelectionList(&selected, handles, num_about, to_string);
SimpleDraw->HBoxRight();
if (selected < num_about) {
const auto cb = CallbackGetCallback(CALLBACKTYPE_ABOUT, handles[selected]);
ASSERT(cb.about_callback != NULL);
cb.about_callback(ImGui::GetCurrentContext());
}
SimpleDraw->HBoxEnd();
}

extern void AboutTabCallback(void*) {
char max_path[_MAX_PATH];
SimpleDraw->Text("BetterConsole Version %s", BETTERCONSOLE_VERSION);
SimpleDraw->Text("Build ID: %s - %s", __DATE__, __TIME__);
ImGui::SeparatorText("Help and Support");
SimpleDraw->LinkButton("BetterConsole on Nexusmods", "https://www.nexusmods.com/starfield/mods/3683");
SimpleDraw->LinkButton("Constellation by V2 (Discord)", "https://discord.gg/v2-s-collections-1076179431195955290");
SimpleDraw->LinkButton("Linuxversion on Reddit", "https://www.reddit.com/user/linuxversion/");
SimpleDraw->LinkButton("Open Log File", GetPathInDllDir(max_path, "BetterConsoleLog.txt"));
SimpleDraw->LinkButton("Open Config File", GetPathInDllDir(max_path, "BetterConsoleConfig.txt"));
}
4 changes: 4 additions & 0 deletions src/about_tab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

extern void draw_about_tab();
extern void AboutTabCallback(void*);
18 changes: 17 additions & 1 deletion src/callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ struct ModInfo {
DRAW_CALLBACK draw_callback;
CONFIG_CALLBACK config_callback;
HOTKEY_CALLBACK hotkey_callback;
DRAW_CALLBACK about_callback;
};


static std::vector<ModInfo> RegisteredMods{};
static std::vector<RegistrationHandle> DrawHandles{};
static std::vector<RegistrationHandle> ConfigHandles{};
static std::vector<RegistrationHandle> HotkeyHandles{};
static std::vector<RegistrationHandle> AboutHandles{};


extern const RegistrationHandle* CallbackGetHandles(CallbackType type, uint32_t* out_count) {
Expand All @@ -37,6 +39,10 @@ extern const RegistrationHandle* CallbackGetHandles(CallbackType type, uint32_t*
count = (uint32_t)HotkeyHandles.size();
ret = &HotkeyHandles[0];
break;
case CALLBACKTYPE_ABOUT:
count = (uint32_t)AboutHandles.size();
ret = &AboutHandles[0];
break;
default:
DEBUG("Invalid callback type %d", type);
ASSERT(false && "Invalid callback type");
Expand Down Expand Up @@ -72,6 +78,9 @@ extern CallbackFunction CallbackGetCallback(CallbackType type, RegistrationHandl
case CALLBACKTYPE_HOTKEY:
ret.hotkey_callback = RegisteredMods[handle].hotkey_callback;
break;
case CALLBACKTYPE_ABOUT:
ret.about_callback = RegisteredMods[handle].about_callback;
break;
default:
DEBUG("Invalid callback type %d", type);
ASSERT(false && "Invalid callback type");
Expand Down Expand Up @@ -116,6 +125,12 @@ static void RegisterHotkeyCallback(RegistrationHandle owner, HOTKEY_CALLBACK cal
HotkeyHandles.push_back(owner);
}

static void RegisterAboutCallback(RegistrationHandle owner, DRAW_CALLBACK callback) {
ASSERT(owner < RegisteredMods.size());
RegisteredMods[owner].about_callback = callback;
AboutHandles.push_back(owner);
}


// This function is best fit next to the hotkey callback registration, but all of the data
// is in the hotkeys.cpp file, so we forward the call to that function instead of trying to
Expand All @@ -136,7 +151,8 @@ static constexpr struct callback_api_t CallbackAPI {
RegisterDrawCallback,
RegisterConfigCallback,
RegisterHotkeyCallback,
RequestHotkey
RequestHotkey,
RegisterAboutCallback
};


Expand Down
4 changes: 4 additions & 0 deletions src/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ typedef enum CallbackType {
CALLBACKTYPE_DRAW,
CALLBACKTYPE_CONFIG,
CALLBACKTYPE_HOTKEY,
CALLBACKTYPE_ABOUT,

CALLBACKTYPE_COUNT
} CallbackType;


typedef union CallbackFunction {
DRAW_CALLBACK draw_callback;
CONFIG_CALLBACK config_callback;
HOTKEY_CALLBACK hotkey_callback;
DRAW_CALLBACK about_callback;
} CallbackFunction;


Expand Down
45 changes: 11 additions & 34 deletions src/gui.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#include "main.h"
#include "gui.h"
#include "hotkeys.h"
#include "about_tab.h"


// maybe more the shellopen stuff to a utility header?
#include <Windows.h>
#include <shellapi.h>


extern void draw_gui() {
// Allow focus of first registered tab (usually betterconsole)
ImGuiTabItemFlags default_tab = ImGuiTabItemFlags_None;

static bool once = false;
if (!once) {
const auto screen = ImGui::GetIO().DisplaySize;
ImGui::SetNextWindowPos(ImVec2{ screen.x / 4, screen.y / 4 });
ImGui::SetNextWindowSize(ImVec2{ screen.x / 2 , screen.y / 2 });
default_tab = ImGuiTabItemFlags_SetSelected;
once = true;
}

Expand Down Expand Up @@ -40,36 +43,9 @@ extern void draw_gui() {
draw_hotkeys_tab();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Help")) {
if (ImGui::Button("NexusMods")) {
ShellExecuteA(NULL, "open", "https://www.nexusmods.com/starfield/mods/3683", NULL, NULL, 1);
}
if (ImGui::Button("Reddit (not checked often)")) {
ShellExecuteA(NULL, "open", "https://www.reddit.com/user/linuxversion/", NULL, NULL, 1);
}
if (ImGui::Button("Constellation by V2 (discord)")) {
ShellExecuteA(NULL, "open", "https://discord.gg/v2-s-collections-1076179431195955290", NULL, NULL, 1);
}
if (ImGui::Button("Discord (not ready yet)")) {
ImGui::OpenPopup("NoDiscordServer");
}
if (ImGui::BeginPopup("NoDiscordServer")) {
char message[] = "Sorry, no discord server has been setup yet!\n"
"I wouldn't have the time to moderate it anyway.\n"
"But you can direct message me, my username is: linuxversion\n"
"If you installed this mod as part of the Constellation by V2 collection,\n"
"then you can report betterconsole issues on that discord server.";
ImGui::Text(message);
ImGui::EndPopup();
}
if (ImGui::Button("Open Log File")) {
char path[260];
ShellExecuteA(NULL, "open", GetPathInDllDir(path, "BetterConsoleLog.txt"), NULL, NULL, 1);
}
if (ImGui::Button("Open Config File")) {
char path[260];
ShellExecuteA(NULL, "open", GetPathInDllDir(path, "BetterConsoleConfig.txt"), NULL, NULL, 1);
}
if (ImGui::BeginTabItem("About")) {
// Implemented in about_tab.cpp
draw_about_tab();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
Expand All @@ -82,7 +58,8 @@ extern void draw_gui() {
for (uint32_t i = 0; i < draw_count; ++i) {
const auto handle = draw_callback[i];
ImGui::PushID(handle);
if (ImGui::BeginTabItem(CallbackGetName(handle))) {
if (ImGui::BeginTabItem(CallbackGetName(handle), nullptr, default_tab)) {
default_tab = ImGuiTabItemFlags_None;
CallbackGetCallback(CALLBACKTYPE_DRAW, handle).draw_callback(imgui_context);
ImGui::EndTabItem();
}
Expand Down

0 comments on commit 52c88a4

Please sign in to comment.