Skip to content

Commit 7ea5df3

Browse files
committed
- Released version 1.0
- Modified README
1 parent d1846c7 commit 7ea5df3

12 files changed

Lines changed: 140 additions & 55 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ cmake_minimum_required(VERSION 3.23)
33
option(BUILD_AS_SHARED "Build as dll skse plugin else build as static lib" ON)
44

55
# Version
6-
set(LIB_MAJOR_VERSION 0)
7-
set(LIB_MINOR_VERSION 1)
8-
set(API_MAJOR_VERSION 0)
9-
set(API_MINOR_VERSION 1)
6+
set(LIB_MAJOR_VERSION 1)
7+
set(LIB_MINOR_VERSION 0)
8+
set(API_MAJOR_VERSION 1)
9+
set(API_MINOR_VERSION 0)
1010

1111
# VCPKG config
1212
string(REPLACE "\\" "/" ENV_VCPKG_ROOT "$ENV{VCPKG_ROOT}")

README.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,86 @@
22

33
UI platform for Skyrim with CEF (Chromium Embedded Framework) integration and more. You can create interface based on html5, css, javascript. This project is a part of NirnLab project.
44

5-
## NirnLab
5+
## Features
6+
- Chromium browser is rendered in Skyrim's native menu (can take screenshots, using native cursor)
7+
- Creating multiple browsers
8+
- Changing keyboard layout out of the box (SHIFT-CTRL or SHIFT-ALT) including console
9+
- Binding js to cpp function callbacks
10+
- Auto closing CEF processes in case of the game crash
611

7-
NirnLab is a competitive MMO-like mod for Skyrim which will be announced after the main part is completed.
8-
If you want to follow the progress and news, subscribe to [![Discord](https://img.shields.io/discord/1004071212361711678?label=Discord&logo=Discord)](https://discord.gg/3YDR4pDJYy).
12+
## Usage as skse plugin (preferred)
13+
You can find all public APIs in this [folder](https://github.com/kkEngine/NirnLabUIPlatform/tree/main/src/UIPlatform/NirnLabUIPlatformAPI). Copy and include the folder in your project (included in release).
14+
Test [examples](https://github.com/kkEngine/NirnLabUIPlatform/tree/main/src/UIPlatformTest)
15+
16+
# Get API (CommonLibSSE example)
17+
First of all we need to check the API version. If major versions are defferent i don't recommend continuing (may crash).
18+
19+
Send request version message when all plugin loaded (kPostPostLoad)
20+
```cpp
21+
SKSE::GetMessagingInterface()->Dispatch(NL::UI::APIMessageType::RequestVersion, nullptr, 0, LibVersion::PROJECT_NAME);
22+
```
23+
Response message will contain API and Lib versions
24+
```cpp
25+
SKSE::GetMessagingInterface()->RegisterListener(LibVersion::PROJECT_NAME, [](SKSE::MessagingInterface::Message* a_msg) {
26+
switch (a_msg->type)
27+
{
28+
case NL::UI::APIMessageType::ResponseVersion:
29+
// API and Lib versions
30+
const auto versionInfo = reinterpret_cast<NL::UI::ResponseVersionMessage*>(a_msg->data);
31+
break;
32+
}
33+
});
34+
```
35+
36+
Check the API version and if it's ok, request API
37+
```cpp
38+
SKSE::GetMessagingInterface()->Dispatch(NL::UI::APIMessageType::RequestAPI, nullptr, 0, NL::UI::LibVersion::PROJECT_NAME);
39+
```
40+
When a first plugin requests API, library and CEF will initialize
41+
Response message will contain API struct. You can save the API pointer and use it in the future.
42+
```cpp
43+
SKSE::GetMessagingInterface()->RegisterListener(LibVersion::PROJECT_NAME, [](SKSE::MessagingInterface::Message* a_msg) {
44+
switch (a_msg->type)
45+
{
46+
case NL::UI::APIMessageType::ResponseAPI:
47+
auto api = reinterpret_cast<NL::UI::ResponseAPIMessage*>(a_msg->data)->API;
48+
break;
49+
}
50+
});
51+
```
52+
53+
# Create browser
54+
```cpp
55+
NL::CEF::IBrowser* g_browser = nullptr;
56+
NL::UI::IUIPlatformAPI::BrowserRefHandle g_browserHandle = NL::UI::IUIPlatformAPI::InvalidBrowserRefHandle;
57+
58+
void CreateBrowser(NL::UI::IUIPlatformAPI* a_api)
59+
{
60+
g_browserHandle = a_api->AddOrGetBrowser("MyPluginCEF", nullptr, 0, "https://www.youtube.com", g_browser);
61+
if (g_browserHandle == NL::UI::IUIPlatformAPI::InvalidBrowserRefHandle)
62+
{
63+
spdlog::error("browser handle is invalid");
64+
return;
65+
}
966

10-
## Examples
11-
todo
67+
// Keep "g_browserHandle" util you need a browser
68+
// When the browser is no longer needed, release it using a_api->ReleaseBrowserHandle();
69+
// If this was the last browser handle, the browser will be deleted
70+
71+
// Check NL::CEF::IBrowser interface for more features
72+
m_browser->ToggleBrowserFocusByKeys(RE::BSKeyboardDevice::Keys::kF6, 0);
73+
g_browser->ToggleBrowserVisibleByKeys(RE::BSKeyboardDevice::Keys::kF7, 0);
74+
g_browser->SetBrowserFocused(true);
75+
g_browser->ExecuteJavaScript("window.myString = 'Hello CEF'");
76+
}
77+
78+
void ReleaseBrowser(NL::UI::IUIPlatformAPI::BrowserRefHandle a_handle)
79+
{
80+
g_browser = nullptr;
81+
a_api->ReleaseBrowserHandle(g_browserHandle);
82+
g_browserHandle = NL::UI::IUIPlatformAPI::InvalidBrowserRefHandle;
83+
}
84+
```
1285
1386
## Dev and build requirements
1487
- CMake 3.23+
@@ -21,5 +94,17 @@ todo
2194
- Address library (https://www.nexusmods.com/skyrimspecialedition/mods/32444)
2295
- SKSE (https://skse.silverlock.org/)
2396
97+
## NirnLab
98+
99+
NirnLab is a competitive MMO-like mod for Skyrim which will be announced after the main part is completed.
100+
If you want to follow the progress and news, subscribe to [![Discord](https://img.shields.io/discord/1004071212361711678?label=Discord&logo=Discord)](https://discord.gg/3YDR4pDJYy).
101+
102+
### Thanks to
103+
[@Pospelove](https://github.com/Pospelove)
104+
[Skymp](https://github.com/skyrim-multiplayer/skymp)
105+
[CommonLibSSE](https://github.com/Ryan-rsm-McKenzie/CommonLibSSE)
106+
[CommonLibSSE-NG](https://github.com/CharmedBaryon/CommonLibSSE-NG)
107+
Chromium Embedded Framework ([CEF](https://bitbucket.org/chromiumembedded/cef))
108+
24109
### License
25110
MIT

src/UIPlatform/Controllers/PublicAPIController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace NL::Controllers
1919
};
2020

2121
protected:
22-
NL::UI::ResponseVersionMessage m_rvMessage{LibVersion::AS_INT, APIVersion::AS_INT};
22+
NL::UI::ResponseVersionMessage m_rvMessage{NL::UI::LibVersion::AS_INT, NL::UI::APIVersion::AS_INT};
2323
NL::UI::ResponseAPIMessage m_rAPIMessage{this};
2424

2525
std::atomic<BrowserRefHandle> m_currentRefHandle{1};

src/UIPlatform/NirnLabUIPlatformAPI/API.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace NL::UI
4747

4848
/// <summary>
4949
/// Response with version info. See ResponseVersionMessage struct.
50-
/// You should check current API version (APIVersion::AS_INT) and version in response.
50+
/// You should check current API version (NL::UI::APIVersion::AS_INT) and version in response.
5151
/// It is not guaranteed that the major versions are compatible. In this case, I recommend not using the library.
5252
/// </summary>
5353
ResponseVersion,
@@ -69,12 +69,12 @@ namespace NL::UI
6969
/// <summary>
7070
/// NirnLabUIPlatform version
7171
/// </summary>
72-
std::uint32_t libVersion = LibVersion::AS_INT;
72+
std::uint32_t libVersion = NL::UI::LibVersion::AS_INT;
7373

7474
/// <summary>
7575
/// NirnLabUIPlatform API version
7676
/// </summary>
77-
std::uint32_t apiVersion = APIVersion::AS_INT;
77+
std::uint32_t apiVersion = NL::UI::APIVersion::AS_INT;
7878
};
7979

8080
struct ResponseAPIMessage

src/UIPlatform/NirnLabUIPlatformAPI/Version.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
#include <cstdint>
44

5-
namespace LibVersion
5+
namespace NL::UI::LibVersion
66
{
7-
inline constexpr std::uint32_t MAJOR = 0;
8-
inline constexpr std::uint32_t MINOR = 1;
7+
inline constexpr std::uint32_t MAJOR = 1;
8+
inline constexpr std::uint32_t MINOR = 0;
99
inline constexpr auto PROJECT_NAME = "NirnLabUIPlatform";
1010

1111
inline constexpr auto MAJOR_MULT = 100000;
12-
inline constexpr auto AS_STRING = "0.1";
12+
inline constexpr auto AS_STRING = "1.0";
1313
inline constexpr std::uint32_t AS_INT = (static_cast<std::uint32_t>(MAJOR * MAJOR_MULT + MINOR));
1414

1515
inline std::uint32_t GetMajorVersion(std::uint32_t a_version)
@@ -23,13 +23,13 @@ namespace LibVersion
2323
}
2424
}
2525

26-
namespace APIVersion
26+
namespace NL::UI::APIVersion
2727
{
28-
inline constexpr std::uint32_t MAJOR = 0;
29-
inline constexpr std::uint32_t MINOR = 1;
28+
inline constexpr std::uint32_t MAJOR = 1;
29+
inline constexpr std::uint32_t MINOR = 0;
3030

3131
inline constexpr auto MAJOR_MULT = 100000;
32-
inline constexpr auto AS_STRING = "0.1";
32+
inline constexpr auto AS_STRING = "1.0";
3333
inline constexpr std::uint32_t AS_INT = (static_cast<std::uint32_t>(MAJOR * MAJOR_MULT + MINOR));
3434

3535
inline std::uint32_t GetMajorVersion(std::uint32_t a_version)

src/UIPlatform/Utils/PathUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NL::Utils
99
{
1010
static inline std::filesystem::path GetTempAppDataPath()
1111
{
12-
auto appPath = std::filesystem::temp_directory_path() / LibVersion::PROJECT_NAME;
12+
auto appPath = std::filesystem::temp_directory_path() / NL::UI::LibVersion::PROJECT_NAME;
1313
CreateDirectoryW(appPath.wstring().c_str(), 0);
1414
return appPath;
1515
}
@@ -21,7 +21,7 @@ namespace NL::Utils
2121

2222
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &pwStr)))
2323
{
24-
fsPath = std::filesystem::path(pwStr) / LibVersion::PROJECT_NAME;
24+
fsPath = std::filesystem::path(pwStr) / NL::UI::LibVersion::PROJECT_NAME;
2525
}
2626
CoTaskMemFree(pwStr);
2727
return fsPath;

src/UIPlatform/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void InitDefaultLog()
1919
SKSE::stl::report_and_fail("Failed to find standard logging directory"sv);
2020
}
2121

22-
*path /= fmt::format("{}.log"sv, LibVersion::PROJECT_NAME);
22+
*path /= fmt::format("{}.log"sv, NL::UI::LibVersion::PROJECT_NAME);
2323
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);
2424
#endif
2525

@@ -58,8 +58,8 @@ void InitCefSubprocessLog()
5858

5959
extern "C" DLLEXPORT constinit auto SKSEPlugin_Version = []() {
6060
SKSE::PluginVersionData v{};
61-
v.pluginVersion = LibVersion::AS_INT;
62-
v.PluginName(LibVersion::PROJECT_NAME);
61+
v.pluginVersion = NL::UI::LibVersion::AS_INT;
62+
v.PluginName(NL::UI::LibVersion::PROJECT_NAME);
6363
v.AuthorName("kkEngine"sv);
6464
v.CompatibleVersions({SKSE::RUNTIME_SSE_1_6_640, REL::Version(1, 6, 1170, 0)});
6565
v.UsesAddressLibrary(true);

src/UIPlatformTest/NirnLabUIPlatformAPI/API.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace NL::UI
4747

4848
/// <summary>
4949
/// Response with version info. See ResponseVersionMessage struct.
50-
/// You should check current API version (APIVersion::AS_INT) and version in response.
50+
/// You should check current API version (NL::UI::APIVersion::AS_INT) and version in response.
5151
/// It is not guaranteed that the major versions are compatible. In this case, I recommend not using the library.
5252
/// </summary>
5353
ResponseVersion,
@@ -69,12 +69,12 @@ namespace NL::UI
6969
/// <summary>
7070
/// NirnLabUIPlatform version
7171
/// </summary>
72-
std::uint32_t libVersion = LibVersion::AS_INT;
72+
std::uint32_t libVersion = NL::UI::LibVersion::AS_INT;
7373

7474
/// <summary>
7575
/// NirnLabUIPlatform API version
7676
/// </summary>
77-
std::uint32_t apiVersion = APIVersion::AS_INT;
77+
std::uint32_t apiVersion = NL::UI::APIVersion::AS_INT;
7878
};
7979

8080
struct ResponseAPIMessage

src/UIPlatformTest/NirnLabUIPlatformAPI/Version.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
#include <cstdint>
44

5-
namespace LibVersion
5+
namespace NL::UI::LibVersion
66
{
7-
inline constexpr std::uint32_t MAJOR = 0;
8-
inline constexpr std::uint32_t MINOR = 1;
7+
inline constexpr std::uint32_t MAJOR = 1;
8+
inline constexpr std::uint32_t MINOR = 0;
99
inline constexpr auto PROJECT_NAME = "NirnLabUIPlatform";
1010

1111
inline constexpr auto MAJOR_MULT = 100000;
12-
inline constexpr auto AS_STRING = "0.1";
12+
inline constexpr auto AS_STRING = "1.0";
1313
inline constexpr std::uint32_t AS_INT = (static_cast<std::uint32_t>(MAJOR * MAJOR_MULT + MINOR));
1414

1515
inline std::uint32_t GetMajorVersion(std::uint32_t a_version)
@@ -23,13 +23,13 @@ namespace LibVersion
2323
}
2424
}
2525

26-
namespace APIVersion
26+
namespace NL::UI::APIVersion
2727
{
28-
inline constexpr std::uint32_t MAJOR = 0;
29-
inline constexpr std::uint32_t MINOR = 1;
28+
inline constexpr std::uint32_t MAJOR = 1;
29+
inline constexpr std::uint32_t MINOR = 0;
3030

3131
inline constexpr auto MAJOR_MULT = 100000;
32-
inline constexpr auto AS_STRING = "0.1";
32+
inline constexpr auto AS_STRING = "1.0";
3333
inline constexpr std::uint32_t AS_INT = (static_cast<std::uint32_t>(MAJOR * MAJOR_MULT + MINOR));
3434

3535
inline std::uint32_t GetMajorVersion(std::uint32_t a_version)

src/UIPlatformTest/main.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,46 @@ SKSEPluginLoad(const SKSE::LoadInterface* a_skse)
5555
{
5656
case SKSE::MessagingInterface::kPostPostLoad:
5757
// All plugins are loaded. Request lib version.
58-
SKSE::GetMessagingInterface()->Dispatch(NL::UI::APIMessageType::RequestVersion, nullptr, 0, LibVersion::PROJECT_NAME);
58+
SKSE::GetMessagingInterface()->Dispatch(NL::UI::APIMessageType::RequestVersion, nullptr, 0, NL::UI::LibVersion::PROJECT_NAME);
5959
break;
6060
case SKSE::MessagingInterface::kInputLoaded:
6161
if (g_canUseAPI)
6262
{
6363
// API version is ok. Request interface.
64-
SKSE::GetMessagingInterface()->Dispatch(NL::UI::APIMessageType::RequestAPI, nullptr, 0, LibVersion::PROJECT_NAME);
64+
SKSE::GetMessagingInterface()->Dispatch(NL::UI::APIMessageType::RequestAPI, nullptr, 0, NL::UI::LibVersion::PROJECT_NAME);
6565
}
6666
break;
6767
default:
6868
break;
6969
}
7070
});
71-
SKSE::GetMessagingInterface()->RegisterListener(nullptr, [](SKSE::MessagingInterface::Message* a_msg) {
71+
SKSE::GetMessagingInterface()->RegisterListener(NL::UI::LibVersion::PROJECT_NAME, [](SKSE::MessagingInterface::Message* a_msg) {
7272
spdlog::info("Received message({}) from \"{}\"", a_msg->type, a_msg->sender ? a_msg->sender : "nullptr");
7373
switch (a_msg->type)
7474
{
7575
case NL::UI::APIMessageType::ResponseVersion: {
7676
const auto versionInfo = reinterpret_cast<NL::UI::ResponseVersionMessage*>(a_msg->data);
77-
spdlog::info("NirnLabUIPlatform version: {}.{}", LibVersion::GetMajorVersion(versionInfo->libVersion), LibVersion::GetMinorVersion(versionInfo->libVersion));
77+
spdlog::info("NirnLabUIPlatform version: {}.{}", NL::UI::LibVersion::GetMajorVersion(versionInfo->libVersion), NL::UI::LibVersion::GetMinorVersion(versionInfo->libVersion));
7878

79-
const auto majorAPIVersion = APIVersion::GetMajorVersion(versionInfo->apiVersion);
79+
const auto majorAPIVersion = NL::UI::APIVersion::GetMajorVersion(versionInfo->apiVersion);
8080
// If the major version is different from ours, then using the API may cause problems
81-
if (majorAPIVersion != APIVersion::MAJOR)
81+
if (majorAPIVersion != NL::UI::APIVersion::MAJOR)
8282
{
8383
g_canUseAPI = false;
8484
spdlog::error("Can't using this API version of NirnLabUIPlatform. We have {}.{} and installed is {}.{}",
85-
APIVersion::MAJOR,
86-
APIVersion::MINOR,
87-
APIVersion::GetMajorVersion(versionInfo->apiVersion),
88-
APIVersion::GetMinorVersion(versionInfo->apiVersion));
85+
NL::UI::APIVersion::MAJOR,
86+
NL::UI::APIVersion::MINOR,
87+
NL::UI::APIVersion::GetMajorVersion(versionInfo->apiVersion),
88+
NL::UI::APIVersion::GetMinorVersion(versionInfo->apiVersion));
8989
}
9090
else
9191
{
9292
g_canUseAPI = true;
9393
spdlog::info("API version is ok. We have {}.{} and installed is {}.{}",
94-
APIVersion::MAJOR,
95-
APIVersion::MINOR,
96-
APIVersion::GetMajorVersion(versionInfo->apiVersion),
97-
APIVersion::GetMinorVersion(versionInfo->apiVersion));
94+
NL::UI::APIVersion::MAJOR,
95+
NL::UI::APIVersion::MINOR,
96+
NL::UI::APIVersion::GetMajorVersion(versionInfo->apiVersion),
97+
NL::UI::APIVersion::GetMinorVersion(versionInfo->apiVersion));
9898
}
9999
break;
100100
}

0 commit comments

Comments
 (0)