Skip to content

Commit

Permalink
Do not require 'originFile' and 'line' parameters of PanoramaUiEngine…
Browse files Browse the repository at this point in the history
…::runScript(). Add a comment explaining the default value of 'line'.
  • Loading branch information
danielkrupinski committed Jan 9, 2025
1 parent 9281744 commit 72efaa9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Source/Features/Hud/DefusingAlert/DefusingAlertContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ class DefusingAlertContext {
text: '5.0'
});
})();
)"
, "", 1);
)");

const auto defusingAlertContainer = hudTeamCounter.findChildInLayoutFile("DefusingAlertContainer");
if (!defusingAlertContainer)
Expand Down
8 changes: 6 additions & 2 deletions Source/GameClasses/PanoramaUiEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class PanoramaUiEngine {
{
}

void runScript(cs2::CUIPanel* contextPanel, const char* scriptSource, const char* originFile, std::uint64_t line) noexcept
void runScript(cs2::CUIPanel* contextPanel, const char* scriptSource) noexcept
{
// Game update on 3 October 2024 added panorama script caching (panorama_script_cache_enabled convar)
// By setting 'line' to non-zero value we disable caching so we don't have to specify different file path for different scripts
constexpr auto originFile{'\0'};
constexpr auto line{1};
if (hookContext.panoramaPatternSearchResults().template get<RunScriptFunctionPointer>() && thisptr())
hookContext.panoramaPatternSearchResults().template get<RunScriptFunctionPointer>()(*thisptr(), contextPanel, scriptSource, originFile, line);
hookContext.panoramaPatternSearchResults().template get<RunScriptFunctionPointer>()(*thisptr(), contextPanel, scriptSource, &originFile, line);
}

[[nodiscard]] decltype(auto) getPanelFromHandle(cs2::PanelHandle handle) noexcept
Expand Down
6 changes: 3 additions & 3 deletions Source/UI/Panorama/PanoramaGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class PanoramaGUI {

// ensure settings tab is loaded because we use CSS classes from settings
// TODO: replace use of settings CSS classes with raw style properties
uiEngine().runScript(mainMenu, "if (!$('#JsSettings')) MainMenu.NavigateToTab('JsSettings', 'settings/settings');", "", 1);
uiEngine().runScript(mainMenu, "if (!$('#JsSettings')) MainMenu.NavigateToTab('JsSettings', 'settings/settings');");

const auto settings = mainMenu.findChildInLayoutFile("JsSettings");
if (settings)
state().settingsPanelHandle = settings.getHandle();

uiEngine().runScript(settings, reinterpret_cast<const char*>(
#include "CreateGUI.js"
), "", 1);
));

uiEngine().runScript(mainMenu, R"(
(function () {
Expand All @@ -52,7 +52,7 @@ class PanoramaGUI {
$.DispatchEvent('Activated', $.GetContextPanel().FindChildTraverse("MainMenuNavBarHome"), 'mouse');
})();
)", "", 1);
)");

if (const auto guiButtonPanel = mainMenu.findChildInLayoutFile("OsirisOpenMenuButton"))
state().guiButtonHandle = guiButtonPanel.getHandle();
Expand Down
2 changes: 1 addition & 1 deletion Source/UI/Panorama/PanoramaGuiUnloadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct PanoramaGuiUnloadHandler {
uiEngine.deletePanelByHandle(state().guiPanelHandle);

if (auto&& settingsPanel = uiEngine.getPanelFromHandle(state().settingsPanelHandle))
uiEngine.runScript(settingsPanel, "delete $.Osiris", "", 1);
uiEngine.runScript(settingsPanel, "delete $.Osiris");
}

private:
Expand Down

0 comments on commit 72efaa9

Please sign in to comment.