Make it easier to add different backgrounds
This was SVN commit r16747.
This commit is contained in:
parent
61f3d80ab0
commit
fd3d697edf
BIN
binaries/data/mods/public/art/textures/ui/pregame/backgrounds/hellenes1-2.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/ui/pregame/backgrounds/hellenes1-2.png
(Stored with Git LFS)
Binary file not shown.
BIN
binaries/data/mods/public/art/textures/ui/pregame/backgrounds/hellenes1-3.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/ui/pregame/backgrounds/hellenes1-3.png
(Stored with Git LFS)
Binary file not shown.
@ -11,6 +11,7 @@
|
||||
<include>common/common_styles.xml</include>
|
||||
<include>common/init.xml</include>
|
||||
|
||||
<include>pregame/backgrounds/</include>
|
||||
<include>pregame/sprites.xml</include>
|
||||
<include>pregame/styles.xml</include>
|
||||
<include>pregame/mainmenu.xml</include>
|
||||
|
@ -0,0 +1,18 @@
|
||||
g_BackgroundLayerData.push(
|
||||
[
|
||||
{
|
||||
"offset": (time, width) => 0.02 * width * Math.cos(0.05 * time),
|
||||
"sprite": "background-hellenes1-1",
|
||||
"tiling": true,
|
||||
},
|
||||
{
|
||||
"offset": (time, width) => 0.12 * width * Math.cos(0.05 * time) - width/10,
|
||||
"sprite": "background-hellenes1-2",
|
||||
"tiling": false,
|
||||
},
|
||||
{
|
||||
"offset": (time, width) => 0.16 * width * Math.cos(0.05 * time) + width/4,
|
||||
"sprite": "background-hellenes1-3",
|
||||
"tiling": false,
|
||||
},
|
||||
]);
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<sprites>
|
||||
<sprite name="background-hellenes1-1">
|
||||
<image
|
||||
texture="pregame/backgrounds/hellenes1-1.png"
|
||||
fixed_h_aspect_ratio="1.777777"
|
||||
round_coordinates="false"
|
||||
/>
|
||||
</sprite>
|
||||
|
||||
<sprite name="background-hellenes1-2">
|
||||
<image
|
||||
texture="pregame/backgrounds/hellenes1-2.png"
|
||||
round_coordinates="false"
|
||||
wrap_mode="clamp_to_edge"
|
||||
/>
|
||||
</sprite>
|
||||
|
||||
<sprite name="background-hellenes1-3">
|
||||
<image
|
||||
texture="pregame/backgrounds/hellenes1-3.png"
|
||||
round_coordinates="false"
|
||||
wrap_mode="clamp_to_edge"
|
||||
/>
|
||||
</sprite>
|
||||
</sprites>
|
@ -1,9 +1,10 @@
|
||||
var userReportEnabledText; // contains the original version with "$status" placeholder
|
||||
var currentSubmenuType; // contains submenu type
|
||||
const MARGIN = 4; // menu border size
|
||||
const background = "hellenes1"; // Background type.
|
||||
var g_BackgroundCode; // Background type.
|
||||
|
||||
var g_ShowSplashScreens;
|
||||
var g_BackgroundLayerData = [];
|
||||
|
||||
function init(initData, hotloadData)
|
||||
{
|
||||
@ -20,6 +21,18 @@ function init(initData, hotloadData)
|
||||
|
||||
// Only show splash screen(s) once at startup, but not again after hotloading
|
||||
g_ShowSplashScreens = hotloadData ? hotloadData.showSplashScreens : initData && initData.isStartup;
|
||||
|
||||
// Pick a random background and initialise it
|
||||
g_BackgroundCode = Math.floor(Math.random() * g_BackgroundLayerData.length);
|
||||
var layerset = g_BackgroundLayerData[g_BackgroundCode];
|
||||
for (var i = 0; i < layerset.length; i++)
|
||||
{
|
||||
var layer = layerset[i];
|
||||
var guiObj = Engine.GetGUIObjectByName("background["+i+"]");
|
||||
guiObj.hidden = false;
|
||||
guiObj.sprite = layer.sprite;
|
||||
guiObj.z = i;
|
||||
}
|
||||
}
|
||||
|
||||
function getHotloadData()
|
||||
@ -27,37 +40,31 @@ function getHotloadData()
|
||||
return { "showSplashScreens": g_ShowSplashScreens };
|
||||
}
|
||||
|
||||
var t0 = new Date;
|
||||
function scrollBackgrounds(background)
|
||||
var t0 = +(new Date());
|
||||
function scrollBackgrounds()
|
||||
{
|
||||
switch(background)
|
||||
var layerset = g_BackgroundLayerData[g_BackgroundCode];
|
||||
for (var i = 0; i < layerset.length; i++)
|
||||
{
|
||||
default:
|
||||
case "hellenes1":
|
||||
var layer1 = Engine.GetGUIObjectByName("backgroundHele1-1");
|
||||
var layer2 = Engine.GetGUIObjectByName("backgroundHele1-2");
|
||||
var layer3 = Engine.GetGUIObjectByName("backgroundHele1-3");
|
||||
var layer = layerset[i];
|
||||
var guiObj = Engine.GetGUIObjectByName("background["+i+"]");
|
||||
|
||||
layer1.hidden = false;
|
||||
layer2.hidden = false;
|
||||
layer3.hidden = false;
|
||||
var screen = guiObj.parent.getComputedSize();
|
||||
var h = screen.bottom - screen.top;
|
||||
var w = h * 16/9;
|
||||
|
||||
var screen = layer1.parent.getComputedSize();
|
||||
var h = screen.bottom - screen.top; // height of screen
|
||||
var w = h*16/9; // width of background image
|
||||
|
||||
// Offset the layers by oscillating amounts
|
||||
var t = (t0 - new Date) / 700;
|
||||
var speed = 1/20;
|
||||
var off1 = 0.02 * w * (1+Math.cos(t*speed));
|
||||
var off2 = 0.12 * w * (1+Math.cos(t*speed)) - h*6/9;
|
||||
var off3 = 0.16 * w * (1+Math.cos(t*speed));
|
||||
|
||||
var left = screen.right - w * (1 + Math.ceil(screen.right / w));
|
||||
layer1.size = new GUISize(left + off1, screen.top, screen.right + off1, screen.bottom);
|
||||
layer2.size = new GUISize(screen.right/2 - h + off2, screen.top, screen.right/2 + h + off2, screen.bottom);
|
||||
layer3.size = new GUISize(screen.right - h + off3, screen.top, screen.right + off3, screen.bottom);
|
||||
break;
|
||||
var time = (new Date() - t0) / 1000;
|
||||
var offset = layer.offset(time, w);
|
||||
if (layer.tiling)
|
||||
{
|
||||
var left = offset % screen.right;
|
||||
if (left > 0)
|
||||
left -= screen.right;
|
||||
var right = left + screen.right * 2;
|
||||
guiObj.size = new GUISize(left, screen.top, right, screen.bottom);
|
||||
}
|
||||
else
|
||||
guiObj.size = new GUISize(screen.right/2 - h + offset, screen.top, screen.right/2 + h + offset, screen.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +120,7 @@ function onTick()
|
||||
lastTickTime = now;
|
||||
|
||||
// Animate backgrounds
|
||||
scrollBackgrounds(background);
|
||||
scrollBackgrounds();
|
||||
|
||||
// Animate submenu
|
||||
updateMenuPosition(tickLength);
|
||||
|
@ -5,6 +5,7 @@
|
||||
<script file="gui/common/functions_global_object.js"/>
|
||||
<script file="gui/common/functions_utility_error.js"/>
|
||||
<script file="gui/pregame/mainmenu.js"/>
|
||||
<script directory="gui/pregame/backgrounds/"/>
|
||||
|
||||
|
||||
<!--
|
||||
@ -18,27 +19,13 @@
|
||||
onTick();
|
||||
</action>
|
||||
|
||||
<object name="backgroundHele1-1"
|
||||
type="image"
|
||||
sprite="background-hellenes1-1"
|
||||
hidden="true"
|
||||
ghost="true"
|
||||
z="1"
|
||||
/>
|
||||
<object name="backgroundHele1-2"
|
||||
type="image"
|
||||
sprite="background-hellenes1-2"
|
||||
hidden="true"
|
||||
ghost="true"
|
||||
z="2"
|
||||
/>
|
||||
<object name="backgroundHele1-3"
|
||||
type="image"
|
||||
sprite="background-hellenes1-3"
|
||||
hidden="true"
|
||||
ghost="true"
|
||||
z="3"
|
||||
/>
|
||||
<repeat count="5">
|
||||
<object name="background[n]"
|
||||
type="image"
|
||||
hidden="true"
|
||||
ghost="true"
|
||||
/>
|
||||
</repeat>
|
||||
|
||||
<!--
|
||||
==========================================
|
||||
|
@ -1,36 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<sprites>
|
||||
<!--
|
||||
==========================================
|
||||
PREGAME GUI - BACKGROUND PICTURES
|
||||
==========================================
|
||||
-->
|
||||
|
||||
<sprite name="background-hellenes1-1">
|
||||
<image
|
||||
texture="pregame/backgrounds/hellenes1-1.png"
|
||||
fixed_h_aspect_ratio="1.777777"
|
||||
round_coordinates="false"
|
||||
/>
|
||||
</sprite>
|
||||
|
||||
<sprite name="background-hellenes1-2">
|
||||
<image
|
||||
texture="pregame/backgrounds/hellenes1-2.png"
|
||||
round_coordinates="false"
|
||||
wrap_mode="clamp_to_edge"
|
||||
/>
|
||||
</sprite>
|
||||
|
||||
<sprite name="background-hellenes1-3">
|
||||
<image
|
||||
texture="pregame/backgrounds/hellenes1-3.png"
|
||||
round_coordinates="false"
|
||||
wrap_mode="clamp_to_edge"
|
||||
/>
|
||||
</sprite>
|
||||
|
||||
<!--
|
||||
==========================================
|
||||
PREGAME GUI - TEXTURE SPRITES - LOGOS
|
||||
|
@ -221,14 +221,26 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
continue;
|
||||
}
|
||||
|
||||
CStrW name (node.GetText().FromUTF8());
|
||||
std::string name = node.GetText();
|
||||
CStrW nameW (node.GetText().FromUTF8());
|
||||
|
||||
PROFILE2("load gui xml");
|
||||
PROFILE2_ATTR("name: %ls", name.c_str());
|
||||
PROFILE2_ATTR("name: %s", name.c_str());
|
||||
|
||||
TIMER(name.c_str());
|
||||
VfsPath path = VfsPath("gui") / name;
|
||||
page.gui->LoadXmlFile(path, page.inputs);
|
||||
TIMER(nameW.c_str());
|
||||
if (name.back() == '/')
|
||||
{
|
||||
VfsPath directory = VfsPath("gui") / nameW;
|
||||
VfsPaths pathnames;
|
||||
vfs::GetPathnames(g_VFS, directory, L"*.xml", pathnames);
|
||||
for (const VfsPath& path : pathnames)
|
||||
page.gui->LoadXmlFile(path, page.inputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
VfsPath path = VfsPath("gui") / nameW;
|
||||
page.gui->LoadXmlFile(path, page.inputs);
|
||||
}
|
||||
}
|
||||
|
||||
// Remember this GUI page, in case the scripts call FindObjectByName
|
||||
|
Loading…
Reference in New Issue
Block a user