Skip to content

Commit

Permalink
Ability to have interface styles
Browse files Browse the repository at this point in the history
You should place them into gamedata/configs/ui/styles/
Basically, it's just new UI folder in old UI folder
  • Loading branch information
Xottab-DUTY committed Jul 8, 2018
1 parent 9bf69e5 commit e5113e2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/xrCore/XML/XMLDocument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#endif
#include "xrCore/xrstring.h"

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

class XML_NODE
{
Expand Down
58 changes: 58 additions & 0 deletions src/xrGame/GamePersistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,62 @@
#include "ai_debug.h"
#endif // _EDITOR

u32 UIStyleID = 0;
xr_vector<xr_token> UIStyleToken;

void FillUIStyleToken()
{
UIStyleToken.emplace_back("ui_style_default", 0);

string_path path;
strconcat(sizeof(path), path, UI_PATH, "\\styles\\");
FS.update_path(path, _game_config_, path);
auto styles = FS.file_list_open(path, FS_ListFolders | FS_RootOnly);
if (styles != nullptr)
{
int i = 1; // It's 1, because 0 is default style
for (const auto& style : *styles)
{
const auto pos = strchr(style, '\\');
*pos = '\0'; // we don't need that backslash in the end
UIStyleToken.emplace_back(xr_strdup(style), i++); // It's important to have postfix increment!
}
FS.file_list_close(styles);
}

UIStyleToken.emplace_back(nullptr, -1);
}

bool defaultUIStyle = true;

void SetupUIStyle()
{
if (UIStyleID == 0)
return;

pcstr selectedStyle = nullptr;
for (const auto& token : UIStyleToken)
if (token.id == UIStyleID)
selectedStyle = token.name;

string128 selectedStylePath;
strconcat(sizeof(selectedStylePath), selectedStylePath, UI_PATH, "\\styles\\", selectedStyle);

UI_PATH = xr_strdup(selectedStylePath);
defaultUIStyle = false;
}

void CleanupUIStyleToken()
{
for (auto& token : UIStyleToken)
{
if (token.name && token.id != 0)
xr_free(token.name);
}
UIStyleToken.clear();
if (!defaultUIStyle)
xr_free(UI_PATH);
}

CGamePersistent::CGamePersistent(void)
{
Expand Down Expand Up @@ -145,6 +200,8 @@ extern void init_game_globals();

void CGamePersistent::OnAppStart()
{
SetupUIStyle();

// load game materials
GMLib.Load();
init_game_globals();
Expand All @@ -166,6 +223,7 @@ void CGamePersistent::OnAppEnd()
clean_game_globals();

GMLib.Unload();
CleanupUIStyleToken();
}

void CGamePersistent::Start(LPCSTR op) { inherited::Start(op); }
Expand Down
7 changes: 5 additions & 2 deletions src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ extern BOOL g_show_wnd_rect2;
//-----------------------------------------------------------
extern float g_fTimeFactor;
extern BOOL b_toggle_weapon_aim;
// extern BOOL g_old_style_ui_hud;

extern u32 UIStyleID;
extern xr_vector<xr_token> UIStyleToken;

extern float g_smart_cover_factor;
extern int g_upgrades_log;
Expand Down Expand Up @@ -2095,7 +2097,8 @@ void CCC_RegisterCommands()
#endif
CMD4(CCC_Float, "con_sensitive", &g_console_sensitive, 0.01f, 1.0f);
CMD4(CCC_Integer, "wpn_aim_toggle", &b_toggle_weapon_aim, 0, 1);
// CMD4(CCC_Integer, "hud_old_style", &g_old_style_ui_hud, 0, 1);

CMD3(CCC_Token, "ui_style", &UIStyleID, UIStyleToken.data());

#ifdef DEBUG
CMD4(CCC_Float, "ai_smart_cover_animation_speed_factor", &g_smart_cover_animation_speed_factor, .1f, 10.f);
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/ui_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "GamePersistent.h"
#include "UICursor.h"

pcstr UI_PATH = "ui";

CUICursor& GetUICursor() { return UI().GetUICursor(); };
ui_core& UI() { return *GamePersistent().m_pUI_core; };
extern ENGINE_API Fvector2 g_current_font_scale;
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/ui_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "xrCommon/xr_vector.h"
#include "xrCommon/xr_stack.h"

extern pcstr UI_PATH;

class CUICursor;
class CUIGameCustom;

Expand Down
4 changes: 4 additions & 0 deletions src/xrGame/xrGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "xr_level_controller.h"
#include "xrEngine/profiler.h"

extern void FillUIStyleToken();

extern "C" {
DLL_API IFactoryObject* __cdecl xrFactory_Create(CLASS_ID clsid)
{
Expand All @@ -36,6 +38,8 @@ BOOL APIENTRY DllMain(HANDLE hModule, u32 ul_reason_for_call, LPVOID lpReserved)
{
case DLL_PROCESS_ATTACH:
{
// Fill ui style token
FillUIStyleToken();
// register console commands
CCC_RegisterCommands();
// keyboard binding
Expand Down

0 comments on commit e5113e2

Please sign in to comment.