Skip to content

Commit

Permalink
Preparations for UI restart (Part III)
Browse files Browse the repository at this point in the history
Second part: 685e47d
  • Loading branch information
Xottab-DUTY committed Nov 11, 2018
1 parent a4f3a0b commit 9d5e0fc
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 38 deletions.
2 changes: 0 additions & 2 deletions src/xrEngine/CustomHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ ENGINE_API CCustomHUD* g_hud = NULL;
CCustomHUD::CCustomHUD()
{
g_hud = this;
Device.seqResolutionChanged.Add(this);
}

CCustomHUD::~CCustomHUD()
{
g_hud = NULL;
Device.seqResolutionChanged.Remove(this);
}
3 changes: 2 additions & 1 deletion src/xrEngine/CustomHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ ENGINE_API extern Flags32 psHUD_Flags;

class IGameObject;

class ENGINE_API CCustomHUD : public FactoryObjectBase, public IEventReceiver, public pureScreenResolutionChanged
class ENGINE_API CCustomHUD : public FactoryObjectBase, public IEventReceiver,
public CUIResetAndResolutionNotifier
{
public:
CCustomHUD();
Expand Down
4 changes: 1 addition & 3 deletions src/xrEngine/XR_IOConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ CConsole::CConsole() : m_hShader_back(NULL)
m_cmd_history_max = cmd_history_max;
m_disable_tips = false;
Register_callbacks();
Device.seqResolutionChanged.Add(this);
}

void CConsole::Initialize()
Expand Down Expand Up @@ -134,7 +133,6 @@ CConsole::~CConsole()
xr_delete(m_hShader_back);
xr_delete(m_editor);
Destroy();
Device.seqResolutionChanged.Remove(this);
}

void CConsole::Destroy()
Expand Down Expand Up @@ -203,7 +201,7 @@ void CConsole::OutFont(LPCSTR text, float& pos_y)
}
}

void CConsole::OnScreenResolutionChanged()
void CConsole::OnUIReset()
{
xr_delete(pFont);
xr_delete(pFont2);
Expand Down
7 changes: 5 additions & 2 deletions src/xrEngine/XR_IOConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ struct TipString
IC bool operator==(shared_str const& tips_text) { return (text == tips_text); }
};

class ENGINE_API CConsole : public pureRender, public pureFrame, public pureScreenResolutionChanged
class ENGINE_API CConsole : public pureRender, public pureFrame,
public CUIResetAndResolutionNotifier
{
public:
struct str_pred
Expand Down Expand Up @@ -109,7 +110,9 @@ class ENGINE_API CConsole : public pureRender, public pureFrame, public pureScre

virtual void OnRender();
virtual void OnFrame();
virtual void OnScreenResolutionChanged();

void OnUIReset() override;

string64 ConfigFile;
bool bVisible;
vecCMD Commands;
Expand Down
36 changes: 36 additions & 0 deletions src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase

MessageRegistry<pureFrame> seqFrameMT;
MessageRegistry<pureDeviceReset> seqDeviceReset;
MessageRegistry<pureUIReset> seqUIReset;
xr_vector<fastdelegate::FastDelegate0<>> seqParallel;
CSecondVPParams m_SecondViewport; //--#SM+#-- +SecondVP+

Expand Down Expand Up @@ -347,4 +348,39 @@ class ENGINE_API CLoadScreenRenderer : public pureRender
};
extern ENGINE_API CLoadScreenRenderer load_screen_renderer;

class CDeviceResetNotifier : public pureDeviceReset
{
public:
CDeviceResetNotifier() { Device.seqDeviceReset.Add(this, REG_PRIORITY_NORMAL); }
virtual ~CDeviceResetNotifier() { Device.seqDeviceReset.Remove(this); }
void OnDeviceReset() override {}
};

class CUIResetNotifier : public pureUIReset
{
public:
CUIResetNotifier() { Device.seqUIReset.Add(this, REG_PRIORITY_NORMAL); }
virtual ~CUIResetNotifier() { Device.seqUIReset.Remove(this); }
void OnUIReset() override {}
};

class CUIResetAndResolutionNotifier : public pureUIReset, pureScreenResolutionChanged
{
public:
CUIResetAndResolutionNotifier()
{
Device.seqUIReset.Add(this, REG_PRIORITY_NORMAL);
Device.seqResolutionChanged.Add(this, REG_PRIORITY_NORMAL);
}

virtual ~CUIResetAndResolutionNotifier()
{
Device.seqUIReset.Remove(this);
Device.seqResolutionChanged.Remove(this);
}

void OnUIReset() override {}
void OnScreenResolutionChanged() override { OnUIReset(); }
};

#endif
1 change: 1 addition & 0 deletions src/xrEngine/pure.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DECLARE_MESSAGE(AppDeactivate);
DECLARE_MESSAGE(AppStart);
DECLARE_MESSAGE(AppEnd);
DECLARE_MESSAGE(DeviceReset);
DECLARE_MESSAGE(UIReset);
DECLARE_MESSAGE(ScreenResolutionChanged);

struct MessageObject
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/HUDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void CHUDManager::Load()
}
}

void CHUDManager::OnScreenResolutionChanged()
void CHUDManager::OnUIReset()
{
pUIGame->HideShownDialogs();

Expand Down
3 changes: 2 additions & 1 deletion src/xrGame/HUDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class CHUDManager : public CCustomHUD
void SetHitmarkType(LPCSTR tex_name);
void SetGrenadeMarkType(LPCSTR tex_name);

virtual void OnScreenResolutionChanged();
void OnUIReset() override;

virtual void Load();
virtual void OnDisconnected();
virtual void OnConnected();
Expand Down
5 changes: 2 additions & 3 deletions src/xrGame/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,10 @@ CMainMenu::CMainMenu()
}

Device.seqFrame.Add(this, REG_PRIORITY_LOW - 1000);
Device.seqResolutionChanged.Add(this);
}

CMainMenu::~CMainMenu()
{
Device.seqResolutionChanged.Remove(this);
Device.seqFrame.Remove(this);

xr_delete(g_btnHint);
Expand Down Expand Up @@ -765,8 +763,9 @@ void CMainMenu::OnDeviceReset()
SetNeedVidRestart();
}

void CMainMenu::OnScreenResolutionChanged()
void CMainMenu::OnUIReset()
{
CUIXmlInitBase::InitColorDefs();
ReadTextureInfo();
ReloadUI();
}
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CMainMenu : public IMainMenu,
public CDialogHolder,
public CUIWndCallback,
public CDeviceResetNotifier,
public pureScreenResolutionChanged
public CUIResetNotifier
{
CUIDialogWnd* m_startDialog;

Expand Down Expand Up @@ -193,7 +193,7 @@ class CMainMenu : public IMainMenu,
void Hide_CTMS_Dialog();
void SetNeedVidRestart();
virtual void OnDeviceReset();
void OnScreenResolutionChanged() override;
void OnUIReset() override;
LPCSTR GetGSVer();

bool IsCDKeyIsValid();
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/UIGameCustom.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CMapListHelper

extern CMapListHelper gMapListHelper;

class CUIGameCustom : public FactoryObjectBase, public CDialogHolder
class CUIGameCustom : public FactoryObjectBase, public CDialogHolder, public CUIResetNotifier
{
protected:
CUIWindow* Window;
Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/UIGameSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ void CUIGameSP::OnFrame()
}
}

void CUIGameSP::OnUIReset()
{
ReinitDialogs();
}

bool CUIGameSP::IR_UIOnKeyboardPress(int dik)
{
if (inherited::IR_UIOnKeyboardPress(dik))
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/UIGameSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CUIGameSP : public CUIGameCustom
virtual void SetClGame(game_cl_GameState* g);
virtual bool IR_UIOnKeyboardPress(int dik);
virtual void OnFrame();
void OnUIReset() override;

void StartTalk(bool disable_break);
void StartTrade(CInventoryOwner* pActorInv, CInventoryOwner* pOtherOwner);
Expand Down
4 changes: 1 addition & 3 deletions src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,9 +1325,7 @@ class CCC_UIRestart : public IConsole_Command

void Execute(pcstr /*args*/) override
{
Device.seqResolutionChanged.Process();
if (g_pGamePersistent && g_pGameLevel && Level().game)
CurrentGameUI()->ReinitDialogs();
Device.seqUIReset.Process();
}
};

Expand Down
4 changes: 1 addition & 3 deletions src/xrUICore/Cursor/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ CUICursor::CUICursor() : m_static(NULL), m_b_use_win_cursor(false)
vPos.set(0.f, 0.f);
InitInternal();
Device.seqRender.Add(this, -3 /*2*/);
Device.seqResolutionChanged.Add(this);
}
//--------------------------------------------------------------------
CUICursor::~CUICursor()
{
xr_delete(m_static);
Device.seqRender.Remove(this);
Device.seqResolutionChanged.Remove(this);
}

void CUICursor::OnScreenResolutionChanged()
void CUICursor::OnUIReset()
{
xr_delete(m_static);
InitInternal();
Expand Down
5 changes: 3 additions & 2 deletions src/xrUICore/Cursor/UICursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class CUIStatic;

class XRUICORE_API CUICursor : public pureRender, public pureScreenResolutionChanged
class XRUICORE_API CUICursor : public pureRender, public CUIResetAndResolutionNotifier
{
bool bVisible;
Fvector2 vPos;
Expand All @@ -21,7 +21,8 @@ class XRUICORE_API CUICursor : public pureRender, public pureScreenResolutionCha
Fvector2 GetCursorPosition();
void SetUICursorPosition(Fvector2 pos);
void UpdateCursorPosition(int _dx, int _dy);
virtual void OnScreenResolutionChanged();

void OnUIReset() override;

bool IsVisible() { return bVisible; }
void Show();
Expand Down
8 changes: 3 additions & 5 deletions src/xrUICore/XML/UIXmlInitBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,15 +1039,13 @@ bool CUIXmlInitBase::InitAlignment(CUIXml& xml_doc, const char* path, int index,

void CUIXmlInitBase::InitColorDefs()
{
if (NULL != m_pColorDefs)
return;

m_pColorDefs = new ColorDefs();
if (!m_pColorDefs)
m_pColorDefs = new ColorDefs();

CUIXml uiXml;
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, COLOR_DEFINITIONS);

int num = uiXml.GetNodesNum("colors", 0, "color");
const int num = uiXml.GetNodesNum("colors", 0, "color");

shared_str name;
int r, b, g, a;
Expand Down
8 changes: 0 additions & 8 deletions src/xrUICore/ui_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
class CUICursor;
class CUIGameCustom;

class CDeviceResetNotifier : public pureDeviceReset
{
public:
CDeviceResetNotifier() { Device.seqDeviceReset.Add(this, REG_PRIORITY_NORMAL); };
virtual ~CDeviceResetNotifier() { Device.seqDeviceReset.Remove(this); };
virtual void OnDeviceReset(){};
};

class XRUICORE_API UICore : public CDeviceResetNotifier
{
C2DFrustum m_2DFrustum;
Expand Down
2 changes: 1 addition & 1 deletion src/xrUICore/uiabstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum EWindowAlignment
waCenter = 16
};

class CUISimpleWindow : public Noncopyable
class CUISimpleWindow : public CUIResetNotifier, public Noncopyable
{
public:
CUISimpleWindow() : m_bShowMe(false)
Expand Down

0 comments on commit 9d5e0fc

Please sign in to comment.