diff --git a/binaries/data/mods/official/gui/test/4_session.xml b/binaries/data/mods/official/gui/test/4_session.xml index 62528429f9..8c69771923 100644 --- a/binaries/data/mods/official/gui/test/4_session.xml +++ b/binaries/data/mods/official/gui/test/4_session.xml @@ -11,9 +11,6 @@ diff --git a/binaries/data/mods/official/gui/test/functions_pregame_load.js b/binaries/data/mods/official/gui/test/functions_pregame_load.js index 52b6ce6d68..3bebc62314 100644 --- a/binaries/data/mods/official/gui/test/functions_pregame_load.js +++ b/binaries/data/mods/official/gui/test/functions_pregame_load.js @@ -28,7 +28,11 @@ function loadSession() GUIObjectUnhide("pregame_gui"); return; } - + + // Create resource pools for each player, etc. + setupSession(); + + // Switch GUI from main menu to game session. GUIObjectHide("loading_screen"); GUIObjectUnhide("session_gui"); FlipGUI(GUIType); @@ -40,3 +44,55 @@ function loadSession() } // ==================================================================== + +function setupSession() +{ + // Do essentials that can only be done when the session has been loaded ... + // For example, create the resource types. + // Initialise Resource Pools by attaching them to the Player object. + // (CPlayer code takes care of giving a copy to each player.) + player = new Object(); // I shouldn't need to do this. Need to find the existing Player to add these to. + player.resource = new Object(); + player.resource.food = 0; + player.resource.wood = 0; + player.resource.stone = 0; + player.resource.ore = 0; + player.resource.pop = new Object(); + player.resource.pop.curr = 0; + player.resource.pop.housing = 0; + + // Start refreshing the session controls. + setInterval( getObjectInfo, 1, 1000 ); +} + +// ==================================================================== + +function endSession(closeType) +{ + // Occurs when the player chooses to close the current game. + + switch (closeType) + { + case ("return"): + // If the player has chosen to quit game and return to main menu, + + // End the session. + endGame(); + + // Fade out current music and return to playing menu theme. + curr_music = newRandomSound('music', 'theme'); + CrossFade(curr_session_playlist_1, curr_music, 0.0001); + + // Swap GUIs to display main menu. + GUIObjectHide('session_gui'); + GUIObjectUnhide('pregame_gui'); + break; + case ("exit"): + // If the player has chosen to shutdown and immediately return to operating system, + + exit(); + break; + } +} + +// ==================================================================== \ No newline at end of file diff --git a/binaries/data/mods/official/gui/test/functions_session_resource_pool.js b/binaries/data/mods/official/gui/test/functions_session_resource_pool.js index f3e96299d7..bad18ed3ce 100755 --- a/binaries/data/mods/official/gui/test/functions_session_resource_pool.js +++ b/binaries/data/mods/official/gui/test/functions_session_resource_pool.js @@ -21,16 +21,6 @@ function initResourcePool() crd_resource_ore_y = crd_resource_stone_y; crd_resource_population_x = crd_resource_ore_x+crd_resource_counter_width+crd_resource_counter_span; crd_resource_population_y = crd_resource_ore_y; - - // Initialise Resource Pools. - Resource = new Object(); - Resource.Food = 0; - Resource.Wood = 0; - Resource.Stone = 0; - Resource.Ore = 0; - Resource.Pop = new Object(); - Resource.Pop.Curr = 0; - Resource.Pop.Housing = 0; } // ==================================================================== @@ -42,16 +32,16 @@ function GiveResources(resourceName, resourceQty) switch (resourceName) { case "Food": - Resource.Food += resourceQty; + player.resource.food += resourceQty; break; case "Wood": - Resource.Wood += resourceQty; + player.resource.wood += resourceQty; break; case "Stone": - Resource.Stone += resourceQty; + player.resource.stone += resourceQty; break; case "Ore": - Resource.Ore += resourceQty; + player.resource.ore += resourceQty; break; default: break; @@ -64,9 +54,9 @@ function GiveResources(resourceName, resourceQty) function UpdateResourcePool() { - getGUIObjectByName("resource_food_counter").caption = Resource.Food; - getGUIObjectByName("resource_wood_counter").caption = Resource.Wood; - getGUIObjectByName("resource_stone_counter").caption = Resource.Stone; - getGUIObjectByName("resource_ore_counter").caption = Resource.Ore; - getGUIObjectByName("resource_population_counter").caption = Resource.Pop.Curr + "/" + Resource.Pop.Housing; + getGUIObjectByName("resource_food_counter").caption = player.resource.food; + getGUIObjectByName("resource_wood_counter").caption = player.resource.wood; + getGUIObjectByName("resource_stone_counter").caption = player.resource.stone; + getGUIObjectByName("resource_ore_counter").caption = player.resource.ore; + getGUIObjectByName("resource_population_counter").caption = player.resource.pop.curr + "/" + player.resource.pop.housing; } \ No newline at end of file