|
2 | 2 |
|
3 | 3 | 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. |
4 | 4 |
|
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 |
6 | 11 |
|
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 [](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 | + } |
9 | 66 |
|
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 | +``` |
12 | 85 |
|
13 | 86 | ## Dev and build requirements |
14 | 87 | - CMake 3.23+ |
|
21 | 94 | - Address library (https://www.nexusmods.com/skyrimspecialedition/mods/32444) |
22 | 95 | - SKSE (https://skse.silverlock.org/) |
23 | 96 |
|
| 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 [](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 | +
|
24 | 109 | ### License |
25 | 110 | MIT |
0 commit comments