Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CGUI.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 1,204 Lines • ▼ Show 20 Lines | else if (element_name == elmt_include) | ||||
else if (!directory.empty()) | else if (!directory.empty()) | ||||
{ | { | ||||
if (nesting_depth+1 >= MAX_OBJECT_DEPTH) | if (nesting_depth+1 >= MAX_OBJECT_DEPTH) | ||||
{ | { | ||||
LOGERROR("GUI: Too many nested GUI includes. Probably caused by a recursive include attribute. Abort rendering '%s'.", utf8_from_wstring(directory)); | LOGERROR("GUI: Too many nested GUI includes. Probably caused by a recursive include attribute. Abort rendering '%s'.", utf8_from_wstring(directory)); | ||||
continue; | continue; | ||||
} | } | ||||
// Sort XML files, so that GUI objects are loaded and appear in the same order platform-independently. | |||||
VfsPaths pathnames; | VfsPaths pathnames; | ||||
vfs::GetPathnames(g_VFS, directory, L"*.xml", pathnames); | vfs::GetPathnames(g_VFS, directory, L"*.xml", pathnames, true); | ||||
for (const VfsPath& path : pathnames) | for (const VfsPath& path : pathnames) | ||||
{ | { | ||||
// as opposed to loading scripts, don't care if it's loaded before | // as opposed to loading scripts, don't care if it's loaded before | ||||
// one might use the same parts of the GUI in different situations | // one might use the same parts of the GUI in different situations | ||||
Paths.insert(path); | Paths.insert(path); | ||||
CXeromyces XeroIncluded; | CXeromyces XeroIncluded; | ||||
if (XeroIncluded.Load(g_VFS, path, "gui") != PSRETURN_OK) | if (XeroIncluded.Load(g_VFS, path, "gui") != PSRETURN_OK) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | if (!file.empty()) | ||||
} | } | ||||
} | } | ||||
// If it has a directory attribute, read all JS files in that directory | // If it has a directory attribute, read all JS files in that directory | ||||
CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8()); | CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8()); | ||||
if (!directory.empty()) | if (!directory.empty()) | ||||
{ | { | ||||
VfsPaths pathnames; | VfsPaths pathnames; | ||||
vfs::GetPathnames(g_VFS, directory, L"*.js", pathnames); | // Sort them, so that modders can extend code from previously loaded files. | ||||
vfs::GetPathnames(g_VFS, directory, L"*.js", pathnames, true); | |||||
for (const VfsPath& path : pathnames) | for (const VfsPath& path : pathnames) | ||||
{ | { | ||||
// Only load new files (so when the insert succeeds) | // Only load new files (so when the insert succeeds) | ||||
if (Paths.insert(path).second) | if (Paths.insert(path).second) | ||||
try | try | ||||
{ | { | ||||
m_ScriptInterface->LoadGlobalScriptFile(path); | m_ScriptInterface->LoadGlobalScriptFile(path); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 400 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator