Skip to content

Commit e5113e2

Browse files
committed
Ability to have interface styles
You should place them into gamedata/configs/ui/styles/ Basically, it's just new UI folder in old UI folder
1 parent 9bf69e5 commit e5113e2

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

src/xrCore/XML/XMLDocument.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#endif
1414
#include "xrCore/xrstring.h"
1515

16-
static constexpr pcstr CONFIG_PATH = "$game_config$";
17-
static constexpr pcstr UI_PATH = "ui";
16+
// XXX: interesting idea is to have variable configs folder. Need we?
17+
static constexpr pcstr CONFIG_PATH = _game_config_;
1818

1919
class XML_NODE
2020
{

src/xrGame/GamePersistent.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,62 @@
4343
#include "ai_debug.h"
4444
#endif // _EDITOR
4545

46+
u32 UIStyleID = 0;
47+
xr_vector<xr_token> UIStyleToken;
4648

49+
void FillUIStyleToken()
50+
{
51+
UIStyleToken.emplace_back("ui_style_default", 0);
52+
53+
string_path path;
54+
strconcat(sizeof(path), path, UI_PATH, "\\styles\\");
55+
FS.update_path(path, _game_config_, path);
56+
auto styles = FS.file_list_open(path, FS_ListFolders | FS_RootOnly);
57+
if (styles != nullptr)
58+
{
59+
int i = 1; // It's 1, because 0 is default style
60+
for (const auto& style : *styles)
61+
{
62+
const auto pos = strchr(style, '\\');
63+
*pos = '\0'; // we don't need that backslash in the end
64+
UIStyleToken.emplace_back(xr_strdup(style), i++); // It's important to have postfix increment!
65+
}
66+
FS.file_list_close(styles);
67+
}
68+
69+
UIStyleToken.emplace_back(nullptr, -1);
70+
}
71+
72+
bool defaultUIStyle = true;
73+
74+
void SetupUIStyle()
75+
{
76+
if (UIStyleID == 0)
77+
return;
78+
79+
pcstr selectedStyle = nullptr;
80+
for (const auto& token : UIStyleToken)
81+
if (token.id == UIStyleID)
82+
selectedStyle = token.name;
83+
84+
string128 selectedStylePath;
85+
strconcat(sizeof(selectedStylePath), selectedStylePath, UI_PATH, "\\styles\\", selectedStyle);
86+
87+
UI_PATH = xr_strdup(selectedStylePath);
88+
defaultUIStyle = false;
89+
}
90+
91+
void CleanupUIStyleToken()
92+
{
93+
for (auto& token : UIStyleToken)
94+
{
95+
if (token.name && token.id != 0)
96+
xr_free(token.name);
97+
}
98+
UIStyleToken.clear();
99+
if (!defaultUIStyle)
100+
xr_free(UI_PATH);
101+
}
47102

48103
CGamePersistent::CGamePersistent(void)
49104
{
@@ -145,6 +200,8 @@ extern void init_game_globals();
145200

146201
void CGamePersistent::OnAppStart()
147202
{
203+
SetupUIStyle();
204+
148205
// load game materials
149206
GMLib.Load();
150207
init_game_globals();
@@ -166,6 +223,7 @@ void CGamePersistent::OnAppEnd()
166223
clean_game_globals();
167224

168225
GMLib.Unload();
226+
CleanupUIStyleToken();
169227
}
170228

171229
void CGamePersistent::Start(LPCSTR op) { inherited::Start(op); }

src/xrGame/console_commands.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ extern BOOL g_show_wnd_rect2;
9090
//-----------------------------------------------------------
9191
extern float g_fTimeFactor;
9292
extern BOOL b_toggle_weapon_aim;
93-
// extern BOOL g_old_style_ui_hud;
93+
94+
extern u32 UIStyleID;
95+
extern xr_vector<xr_token> UIStyleToken;
9496

9597
extern float g_smart_cover_factor;
9698
extern int g_upgrades_log;
@@ -2095,7 +2097,8 @@ void CCC_RegisterCommands()
20952097
#endif
20962098
CMD4(CCC_Float, "con_sensitive", &g_console_sensitive, 0.01f, 1.0f);
20972099
CMD4(CCC_Integer, "wpn_aim_toggle", &b_toggle_weapon_aim, 0, 1);
2098-
// CMD4(CCC_Integer, "hud_old_style", &g_old_style_ui_hud, 0, 1);
2100+
2101+
CMD3(CCC_Token, "ui_style", &UIStyleID, UIStyleToken.data());
20992102

21002103
#ifdef DEBUG
21012104
CMD4(CCC_Float, "ai_smart_cover_animation_speed_factor", &g_smart_cover_animation_speed_factor, .1f, 10.f);

src/xrGame/ui_base.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "GamePersistent.h"
44
#include "UICursor.h"
55

6+
pcstr UI_PATH = "ui";
7+
68
CUICursor& GetUICursor() { return UI().GetUICursor(); };
79
ui_core& UI() { return *GamePersistent().m_pUI_core; };
810
extern ENGINE_API Fvector2 g_current_font_scale;

src/xrGame/ui_base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "xrCommon/xr_vector.h"
66
#include "xrCommon/xr_stack.h"
77

8+
extern pcstr UI_PATH;
9+
810
class CUICursor;
911
class CUIGameCustom;
1012

src/xrGame/xrGame.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "xr_level_controller.h"
1313
#include "xrEngine/profiler.h"
1414

15+
extern void FillUIStyleToken();
16+
1517
extern "C" {
1618
DLL_API IFactoryObject* __cdecl xrFactory_Create(CLASS_ID clsid)
1719
{
@@ -36,6 +38,8 @@ BOOL APIENTRY DllMain(HANDLE hModule, u32 ul_reason_for_call, LPVOID lpReserved)
3638
{
3739
case DLL_PROCESS_ATTACH:
3840
{
41+
// Fill ui style token
42+
FillUIStyleToken();
3943
// register console commands
4044
CCC_RegisterCommands();
4145
// keyboard binding

0 commit comments

Comments
 (0)