Cinema Path GUI hiding and silhouettes fixes.

Let the JS GUI take care of hiding the GUI and silhouettes and remove
the according hardcoding in the engine following 89aef0b6eb.
Thereby fix some bugs (like not having hid the GUI if there was a
message box or different page shown while playing a path) and
fix these two hotkeys broken by 5d49e6c456.

Differential Revision: https://code.wildfiregames.com/D631
Fixes #4633
Reviewed By: Vladislav
This was SVN commit r19797.
This commit is contained in:
elexis 2017-06-17 14:17:30 +00:00
parent 2cd7c62c0f
commit cfd08bbf28
7 changed files with 40 additions and 42 deletions

View file

@ -16,6 +16,10 @@
<action on="Press">openChat(g_LastChatAddressee);</action>
</object>
<object hotkey="session.gui.toggle">
<action on="Press">g_ShowGUI = !g_ShowGUI;</action>
</object>
<object hotkey="session.gui.menu.toggle">
<action on="Press">toggleMenu();</action>
</object>
@ -25,10 +29,7 @@
</object>
<object hotkey="silhouettes">
<action on="Press">
var newSetting = !Engine.Renderer_GetSilhouettesEnabled();
Engine.Renderer_SetSilhouettesEnabled(newSetting);
</action>
<action on="Press">toggleConfigBool("silhouettes");</action>
</object>
<object hotkey="showsky">

View file

@ -128,6 +128,12 @@ var g_DevSettings = {
"controlAll": false
};
/**
* Whether the entire UI should be hidden (useful for promotional screenshots).
* Can be toggled with a hotkey.
*/
var g_ShowGUI = true;
/**
* Whether status bars should be shown for all of the player's units.
*/
@ -801,6 +807,7 @@ function onSimulationUpdate()
if (!g_SimState)
return;
updateCinemaPath();
handleNotifications();
updateGUIObjects();
@ -848,6 +855,14 @@ function confirmExit()
g_ConfirmExit = false;
}
function updateCinemaPath()
{
let isPlayingCinemaPath = GetSimState().cinemaPlaying;
Engine.GetGUIObjectByName("sn").hidden = !g_ShowGUI || isPlayingCinemaPath;
Engine.Renderer_SetSilhouettesEnabled(!isPlayingCinemaPath && Engine.ConfigDB_GetValue("user", "silhouettes") == "true");
}
function updateGUIObjects()
{
g_Selection.update();
@ -1268,16 +1283,25 @@ function recalculateStatusBarDisplay(remove = false)
});
}
/**
* Inverts the given configuration boolean and returns the current state.
* For example "silhouettes".
*/
function toggleConfigBool(configName)
{
let enabled = Engine.ConfigDB_GetValue("user", configName) != "true";
Engine.ConfigDB_CreateValue("user", configName, String(enabled));
Engine.ConfigDB_WriteValueToFile("user", configName, String(enabled), "config/user.cfg");
return enabled;
}
/**
* Toggles the display of range overlays of selected entities for the given range type.
* @param {string} type - for example "Aura"
*/
function toggleRangeOverlay(type)
{
let configString = "gui.session." + type.toLowerCase() + "range";
let enabled = Engine.ConfigDB_GetValue("user", configString) != "true";
Engine.ConfigDB_CreateValue("user", configString, String(enabled));
Engine.ConfigDB_WriteValueToFile("user", configString, String(enabled), "config/user.cfg");
let enabled = toggleConfigBool("gui.session." + type.toLowerCase() + "range");
Engine.GuiInterfaceCall("EnableVisualRangeOverlayType", {
"type": type,

View file

@ -16,7 +16,7 @@
<script directory="gui/session/"/>
<object name="sn" hotkey="session.gui.toggle">
<object name="sn">
<action on="Tick">
onTick();
</action>

View file

@ -149,6 +149,11 @@ GuiInterface.prototype.GetSimulationState = function()
ret.ceasefireTimeRemaining = ret.ceasefireActive ? cmpCeasefireManager.GetCeasefireStartedTime() + cmpCeasefireManager.GetCeasefireTime() - ret.timeElapsed : 0;
}
// Add cinema path info
let cmpCinemaManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CinemaManager);
if (cmpCinemaManager)
ret.cinemaPlaying = cmpCinemaManager.IsPlaying();
// Add the game type and allied victory
let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
ret.gameType = cmpEndGameManager.GetGameType();

View file

@ -62,9 +62,6 @@ void CCinemaManager::Update(const float deltaRealTime) const
if (!cmpCinemaManager)
return;
UpdateSessionVisibility();
UpdateSilhouettesVisibility();
if (IsPlaying())
cmpCinemaManager->PlayQueue(deltaRealTime, g_Game->GetView()->GetCamera());
}
@ -77,33 +74,6 @@ void CCinemaManager::Render() const
DrawPaths();
}
void CCinemaManager::UpdateSessionVisibility() const
{
// TODO: Enabling/Disabling does not work if the session GUI page is not the top page.
// This can happen in various situations, for example when the player wins/loses the game
// while the cinematic is running (a message box is the top page in this case).
IGUIObject *sn = g_GUI->FindObjectByName("sn");
if (!sn)
return;
bool hidden = false;
GUI<bool>::GetSetting(sn, "hidden", hidden);
if (hidden != IsPlaying())
sn->SetSetting("hidden", IsPlaying() ? L"true" : L"false");
}
void CCinemaManager::UpdateSilhouettesVisibility() const
{
if (!CRenderer::IsInitialised())
return;
bool silhouettes = false;
CFG_GET_VAL("silhouettes", silhouettes);
g_Renderer.SetOptionBool(CRenderer::Option::OPT_SILHOUETTES, !IsEnabled() && silhouettes);
}
void CCinemaManager::DrawPaths() const
{
CmpPtr<ICmpCinemaManager> cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity());

View file

@ -42,9 +42,6 @@ public:
void DrawSpline(const RNSpline& spline, const CColor& splineColor, int smoothness, bool lines) const;
void DrawNodes(const RNSpline& spline, const CColor& nodesColor) const;
void UpdateSessionVisibility() const;
void UpdateSilhouettesVisibility() const;
bool IsPlaying() const;
bool IsEnabled() const;

View file

@ -25,6 +25,7 @@ BEGIN_INTERFACE_WRAPPER(CinemaManager)
DEFINE_INTERFACE_METHOD_1("AddPath", void, ICmpCinemaManager, AddPath, CCinemaPath)
DEFINE_INTERFACE_METHOD_1("AddCinemaPathToQueue", void, ICmpCinemaManager, AddCinemaPathToQueue, CStrW)
DEFINE_INTERFACE_METHOD_1("DeletePath", void, ICmpCinemaManager, DeletePath, CStrW)
DEFINE_INTERFACE_METHOD_CONST_0("IsPlaying", bool, ICmpCinemaManager, IsEnabled)
DEFINE_INTERFACE_METHOD_0("Play", void, ICmpCinemaManager, Play)
DEFINE_INTERFACE_METHOD_0("Stop", void, ICmpCinemaManager, Stop)
END_INTERFACE_WRAPPER(CinemaManager)