Skip to content

Commit 3c2ec03

Browse files
committed
main window draft
1 parent d9e65f2 commit 3c2ec03

File tree

7 files changed

+250
-16
lines changed

7 files changed

+250
-16
lines changed

src/Gui.cpp

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,116 @@
11
#include "stdafx.h"
22

3+
Gui::Gui()
4+
{
5+
}
6+
37
void Gui::init()
48
{
5-
//CHANGE ME
9+
toggleButton.init();
10+
mainWindow.init();
611
}
712

813
void Gui::draw()
14+
{
15+
toggleButton.act(*this);
16+
mainWindow.act();
17+
}
18+
19+
void Gui::deinit()
920
{
1021
//CHANGE ME
22+
}
1123

12-
ImGui::Begin("Hello world window");
13-
ImGui::Text("Hello world!");
24+
//main toggle button that should open up addon manager main menu
25+
//should be blended with game ui
26+
//and also maybe triggerable via hotkey
27+
28+
void Gui::ToggleButton::init()
29+
{
30+
//TODO: calculate from smth to fit into game UI
31+
size = ImVec2(10, 10);
32+
pos = ImVec2(0, 0);
33+
//TODO: load image (maybe via imgui_lib?)
34+
}
35+
36+
void Gui::ToggleButton::act(Gui & gui)
37+
{
38+
ImGui::Begin("main menu toggle button", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar);
39+
ImGui::SetWindowPos(pos);
40+
ImGui::SetWindowSize(size);
41+
//TODO: use image
42+
if (ImGui::Button("AM", size))
43+
gui.mainWindow.visible = !gui.mainWindow.visible;
1444
ImGui::End();
1545
}
1646

17-
void Gui::deinit()
47+
////////////////////
48+
49+
//Main window with addon listing/actions/etc
50+
//
51+
52+
void Gui::MainWindow::init()
1853
{
19-
//CHANGE ME
54+
visible = false;
55+
}
56+
57+
void Gui::MainWindow::act()
58+
{
59+
if (!visible)
60+
return;
61+
62+
gAddon().main.ensureActualAddonData();
63+
64+
ImGui::Begin("GW2 addon manager");
65+
66+
for (const auto& i : gAddon().main.GetAddonList())
67+
{
68+
ImGui::Text("%S", i.name);
69+
70+
if (i.status == GW2AL_OK)
71+
{
72+
ImGui::SameLine();
73+
if (!i.dsc)
74+
{
75+
ImGui::Text("E: [no description found]");
76+
continue;
77+
}
78+
79+
ImGui::Text("v%u.%u build %u", i.dsc->majorVer, i.dsc->minorVer, i.dsc->revision);
80+
//TODO: make it a hover popup
81+
ImGui::Text("%S", i.dsc->description);
82+
}
83+
else {
84+
ImGui::SameLine();
85+
switch (i.status)
86+
{
87+
case GW2AL_BAD_DLL:
88+
ImGui::Text("E: [missing one of export functions]");
89+
break;
90+
case GW2AL_NOT_FOUND:
91+
ImGui::Text("E: [dll not found]");
92+
break;
93+
case GW2AL_DEP_NOT_LOADED:
94+
ImGui::Text("E: [dependency missing]");
95+
break;
96+
case GW2AL_DEP_OUTDATED:
97+
ImGui::Text("E: [dependency outdated]");
98+
break;
99+
default:
100+
ImGui::Text("E: [general failure]");
101+
break;
102+
}
103+
}
104+
105+
//TODO: make this work
106+
ImGui::Button("Update");
107+
ImGui::SameLine();
108+
ImGui::Button("Reload");
109+
ImGui::SameLine();
110+
ImGui::Button("Disable");
111+
ImGui::SameLine();
112+
ImGui::Button("Open config menu");
113+
}
114+
115+
ImGui::End();
20116
}

src/Gui.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,24 @@
33

44
class Gui
55
{
6+
struct ToggleButton
7+
{
8+
void init();
9+
void act(Gui& gui);
10+
ImVec2 pos;
11+
ImVec2 size;
12+
} toggleButton;
13+
14+
struct MainWindow
15+
{
16+
bool visible;
17+
void init();
18+
void act();
19+
} mainWindow;
20+
621
public:
22+
Gui();
23+
724
void init();
825
void draw();
926
void deinit();

src/Main.cpp

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,91 @@
11
#include "stdafx.h"
22
#include "Main.h"
33

4-
//CHANGE_ME
4+
void Main::clearAddonList()
5+
{
6+
for (auto& i : addonList)
7+
free(i.name);
8+
addonList.clear();
9+
}
10+
11+
void Main::updateAddonList()
12+
{
13+
clearAddonList();
14+
15+
const wchar_t* dir = L"addons";
16+
17+
WIN32_FIND_DATA fdFile;
18+
HANDLE hFind = NULL;
19+
20+
wchar_t sPath[2048];
21+
wsprintf(sPath, L"%s\\*.*", dir);
22+
23+
LOG_INFO(L"addon_manager", L"Reading addons from \"./%s\" path", dir);
24+
25+
if ((hFind = FindFirstFile(sPath, &fdFile)) == INVALID_HANDLE_VALUE)
26+
return;
27+
28+
do
29+
{
30+
if (wcscmp(fdFile.cFileName, L".") != 0
31+
&& wcscmp(fdFile.cFileName, L"..") != 0)
32+
{
33+
if (fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
34+
{
35+
AddonListEntry item;
36+
item.name = _wcsdup(fdFile.cFileName);
37+
item.status = GW2AL_FAIL;
38+
item.hashedName = gAddon().api->hash_name(item.name);
39+
item.dsc = nullptr;
40+
41+
/*
42+
constexpr size_t mbstrSz = 4096;
43+
item.nameA = new char[mbstrSz];
44+
size_t unused;
45+
wcstombs_s(&unused, item.nameA, mbstrSz, item.name, mbstrSz - 1);
46+
*/
47+
48+
addonList.push_back(item);
49+
}
50+
}
51+
} while (FindNextFile(hFind, &fdFile));
52+
53+
FindClose(hFind);
54+
55+
LOG_INFO(L"addon_manager", L"Found %u possible addons", addonList.size());
56+
}
57+
58+
void Main::updateAddonStatuses()
59+
{
60+
for (AddonListEntry& i : addonList)
61+
{
62+
i.dsc = gAddon().api->query_addon(i.hashedName);
63+
64+
//if it is properly loaded just set status OK
65+
if (i.dsc)
66+
i.status = GW2AL_OK;
67+
else //otherwise try to load it again and store load error in status
68+
i.status = gAddon().api->load_addon(i.name);
69+
}
70+
}
71+
72+
void Main::ensureActualAddonData()
73+
{
74+
if (!shouldUpdateAddons)
75+
return;
76+
77+
updateAddonList();
78+
updateAddonStatuses();
79+
80+
shouldUpdateAddons = false;
81+
}
82+
83+
void Main::init()
84+
{
85+
shouldUpdateAddons = true;
86+
}
587

6-
void Main::doSomethingUsefull()
7-
{
88+
void Main::deinit()
89+
{
90+
clearAddonList();
891
}

src/Main.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,30 @@
33

44
class Main
55
{
6-
//CHANGE_ME
7-
void doSomethingUsefull();
8-
96
public:
10-
void init()
7+
struct AddonListEntry
118
{
12-
//do something usefull here
13-
doSomethingUsefull();
14-
}
9+
wchar_t* name;
10+
gw2al_api_ret status;
11+
gw2al_hashed_name hashedName;
12+
const gw2al_addon_dsc* dsc;
13+
};
14+
const std::vector<AddonListEntry>& GetAddonList() { return addonList; }
15+
16+
private:
17+
18+
void clearAddonList();
19+
void updateAddonList();
20+
void updateAddonStatuses();
21+
22+
std::vector<AddonListEntry> addonList;
23+
bool shouldUpdateAddons;
24+
25+
public:
26+
1527

16-
void deinit() { }
28+
void ensureActualAddonData();
29+
void init();
30+
void deinit();
1731
};
1832

src/addon.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ addon_instance& gAddon()
2222
return gInst;
2323
}
2424

25+
void log_text_fmt(gw2al_log_level level, const wchar_t* source, const wchar_t* fmt, ...)
26+
{
27+
static wchar_t buf[4096];
28+
29+
va_list arg;
30+
va_start(arg, fmt);
31+
32+
vswprintf(buf, 4096, fmt, arg);
33+
34+
va_end(arg);
35+
36+
gInst.api->log_text(level, (wchar_t*)source, buf);
37+
}
38+
2539
template<>
2640
inline lib_imgui<Gui>& lib_imgui<Gui>::instance()
2741
{

src/addon.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ struct addon_instance
99
};
1010

1111
addon_instance& gAddon();
12+
13+
void log_text_fmt(gw2al_log_level level, const wchar_t* source, const wchar_t* fmt, ...);
14+
15+
#define LOG_INFO(m, t, ...) log_text_fmt(LL_INFO, m, t, __VA_ARGS__)
16+
#define LOG_ERROR(m, t, ...) log_text_fmt(LL_ERR, m, t, __VA_ARGS__)
17+
#define LOG_WARNING(m, t, ...) log_text_fmt(LL_WARN, m, t, __VA_ARGS__)
18+
#define LOG_DEBUG(m, t, ...) log_text_fmt(LL_DEBUG, m, t, __VA_ARGS__)

src/stdafx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <windows.h>
77
#include <gw2al_api.h>
88
#include <gw2al_lib_imgui.h>
9+
#include "stdint.h"
10+
#include <stdarg.h>
11+
#include <vector>
912

1013
#include "Main.h"
1114
#include "Gui.h"

0 commit comments

Comments
 (0)