1
0
forked from 0ad/0ad

Made a start on making the team tray and group pane buttons functional. Removed the silly text from the loading screen now that we do indeed have a functioning progress bar. Refined structure for resource pool functions. Fixed up little things here and there.

This was SVN commit r2082.
This commit is contained in:
Acumen 2005-03-30 02:01:22 +00:00
parent 9cc11918d3
commit 8d6ebe1b1f
6 changed files with 126 additions and 66 deletions

View File

@ -270,7 +270,7 @@
if(extension != ".pmp") {
// Add .pmp to the file name - shouldn't help if the name is mistyped, but may be useful in some cases
mapName = mapName + ".pmp";
console.write("Trying to fix the map name (probably missing extension).");
// console.write("Trying to fix the map name (probably missing extension).");
}
// Set up game

View File

@ -148,8 +148,10 @@
{
for (colLoop = 0; colLoop < crd_grppane_prt_col.last; colLoop++)
{
// Set size, caption, and onPress function for each button.
AddSizeGroupPane("SESSION_GROUP_PANE_PORTRAIT_" + groupPaneCounter, rowLoop, colLoop);
getGUIObjectByName("SESSION_GROUP_PANE_PORTRAIT_" + groupPaneCounter).caption = groupPaneCounter;
getGUIObjectByName("SESSION_GROUP_PANE_PORTRAIT_" + groupPaneCounter).onPress = function() { SelectUnit(groupPaneCounter); }
AddSizeGroupPaneBar("SESSION_GROUP_PANE_PORTRAIT_" + groupPaneCounter + "_BAR");
groupPaneCounter++;
}
@ -166,7 +168,11 @@
<object type="text" name="SN_STATUS_PANE_BG" style="session_ghost_object" ><action on="Load"><![CDATA[ addSizeCoordArray(this.name, Crd[SN_STATUS_PANE_BG]); ]]></action></object>
<object type="text" name="SN_STATUS_PANE_HEADING" style="session_ghost_subheading_center_object" ><action on="Load"><![CDATA[ addSizeCoordArray(this.name, Crd[SN_STATUS_PANE_HEADING], Crd[SN_STATUS_PANE_HEADING_FLP]); ]]></action></object>
<object type="button" name="SN_STATUS_PANE_PORTRAIT" style="portrait" ><action on="Load"><![CDATA[ addSizeCoordArray(this.name, Crd[SN_STATUS_PANE_PORTRAIT], Crd[SN_STATUS_PANE_PORTRAIT_FLP]); ]]></action></object>
<object type="button" name="SN_STATUS_PANE_PORTRAIT" hotkey="selection.snap" style="portrait" ><action on="Load"><![CDATA[ addSizeCoordArray(this.name, Crd[SN_STATUS_PANE_PORTRAIT], Crd[SN_STATUS_PANE_PORTRAIT_FLP]); ]]></action>
<action on="Press"><![CDATA[
setCameraTarget(selection[0].position); // Focus the camera on the unit when his portrait is clicked.
]]></action>
</object>
<object type="text" name="SN_STATUS_PANE_ICON_RANK" style="session_ghost_object" ><action on="Load"><![CDATA[ addSizeCoordArray(this.name, Crd[SN_STATUS_PANE_ICON_RANK], Crd[SN_STATUS_PANE_ICON_RANK_FLP]); ]]></action></object>
<object type="progressbar" name="SN_STATUS_PANE_ICON_HP_BAR" style="group_portrait_bar" sprite_background="back_bar" ><action on="Load"><![CDATA[ addSizeCoordArray(this.name, Crd[SN_STATUS_PANE_ICON_HP_BAR], Crd[SN_STATUS_PANE_ICON_HP_BAR_FLP]); ]]></action></object>
<object type="text" name="SN_STATUS_PANE_ICON_HP_TEXT" style="session_ghost_text_left_centre_object" textcolor="0 255 0" ><action on="Load"><![CDATA[ addSizeCoordArray(this.name, Crd[SN_STATUS_PANE_ICON_HP_TEXT], Crd[SN_STATUS_PANE_ICON_HP_TEXT_FLP]); ]]></action></object>
@ -846,11 +852,12 @@
<object type="button" name="SN_TEAM_TRAY_8" style="action_left" />
<object type="button" name="SN_TEAM_TRAY_9" style="action_left" >
<action on="Load"><![CDATA[
// Seek through ALL objects and set their sizes at once. (So make sure this always goes in the last control.)
// Seek through ALL objects and set their sizes, captions and onpresses at once. (So make sure this always goes in the last control.)
for (SN_TEAM_TRAY.curr = 1; SN_TEAM_TRAY.curr < SN_TEAM_TRAY.last; SN_TEAM_TRAY.curr++)
{
addSizeCoordArray("SN_TEAM_TRAY_" + SN_TEAM_TRAY.curr, Crd[SN_TEAM_TRAY[SN_TEAM_TRAY.curr]]);
GUIObjectSetCaption("SN_TEAM_TRAY_" + SN_TEAM_TRAY.curr, SN_TEAM_TRAY.curr);
getGUIObjectByName("SN_TEAM_TRAY_" + SN_TEAM_TRAY.curr).onPress = function() { SelectGroup(this.name.substring(this.name.length-1, this.name.length)); }
}
]]></action>
</object>

View File

@ -38,45 +38,24 @@ function startLoadingScreen()
getGUIObjectByName("loading_screen_titlebar_text").caption = "Loading Scenario ...";
getGUIObjectByName("loading_screen_progress_bar_text").caption = "... Reticulating splines ...";
getGUIObjectByName("loading_screen_progress_bar").caption = 80;
getGUIObjectByName("loading_screen_text").caption = "LOADING " + g_GameAttributes.mapFile + " ...\nPlease wait ...\n(Yes, we know the progress bar doesn't do diddly squat right now)\nJust keep waiting ...\nIt'll get there ...\nAlmost done ...\nTrust me!";
getGUIObjectByName("loading_screen_text").caption = "LOADING " + g_GameAttributes.mapFile + " ...\nPlease wait ...";
getGUIObjectByName("loading_screen_tip").caption = "Wise man once say ...\nHe who thinks slow, he act in haste, be rash and quick and foolish. But he that thinks too much, acts too slowly. The stupid always win, Commandersan. Remember that. You are tiny grasshopper.";
// Begin game session.
// setTimeout( loadSession, 200 );
startGame(); // new version returns quickly; we will hit the main loop
// occasionally, so need for evil timeout hack
if (! startGame())
{
// Failed to start the game; go back to the main menu.
GUIObjectHide("loading_screen");
GUIObjectUnhide("PREGAME_GUI");
// Show an error message
btCaptions = new Array("OK");
btCode = new Array("");
messageBox(400, 200, "The game could not be started with the given parameters. You probably have entered an invalid map name.", "Error", 0, btCaptions, btCode);
}
}
// ====================================================================
//function loadSession()
//{
// if (! startGame())
// {
// // Failed to start the game; go back to the main menu. TODO: display an error message.
// GUIObjectHide("loading_screen");
// GUIObjectUnhide("PREGAME_GUI");
// // Show an error message
// btCaptions = new Array("OK");
// btCode = new Array("");
// messageBox(400, 200, "The game could not be started with the given parameters. You probably have entered an invalid map name.", "Error", 0, btCaptions, btCode);
// }
//
// // Create resource pools for each player, etc.
// setupSession();
//
// FlipGUI(GUIType);
//
// // Select session peace track.
// curr_session_playlist_1 = newRandomSound("music", "peace");
// // Fade out main theme and fade in session theme.
// CrossFade(curr_music, curr_session_playlist_1, 0.0001);
//
// // Switch GUI from main menu to game session.
// GUIObjectHide("loading_screen");
// GUIObjectUnhide("SESSION_GUI");
//}
function reallyStartGame()
{
// Create resource pools for each player, etc.
@ -104,15 +83,7 @@ function setupSession()
// 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.
localPlayer.resource = new Object();
localPlayer.resource.food = 0;
localPlayer.resource.wood = 0;
localPlayer.resource.stone = 0;
localPlayer.resource.ore = 0;
localPlayer.resource.pop = new Object();
localPlayer.resource.pop.curr = 0;
localPlayer.resource.pop.housing = 0;
CreateResources();
// Start refreshing the session controls.
setInterval( getObjectInfo, 1, 1000 );

View File

@ -122,6 +122,18 @@ function AddSizeGroupPaneBar(objectName)
// ====================================================================
function SelectUnit(unitNumber)
{
// Sets the current unit selection to a given number in the selection[] array (selects a unit in the current selection).
// Occurs when clicking a portrait in the Group Pane.
clickedUnit = selection[unitNumber-1];
selection.clear();
selection.push(clickedUnit);
}
// ====================================================================
function UpdateGroupPane()
{
// Reveal Group Pane.

View File

@ -45,38 +45,89 @@ function initResourcePool()
// ====================================================================
function AddResource(resourceName, resourceQty)
{
// Creates a resource type.
if (!localPlayer.resource)
{
// Define the base resource group if it does not exist.
localPlayer.resource = new Array();
// Define resource total.
localPlayer.resource.last = new Object();
localPlayer.resource.last = 0;
}
// Set resource name to upper-case to ensure it matches resource control name.
resourceName = resourceName.toUpperCase();
// Store resource's name and starting value.
localPlayer.resource[localPlayer.resource.last] = new Object();
localPlayer.resource[localPlayer.resource.last].name = resourceName;
localPlayer.resource[localPlayer.resource.last].qty = resourceQty;
localPlayer.resource.last++;
console.write("Added " + resourceName + " (" + localPlayer.resource.last + ")");
}
// ====================================================================
function CreateResources()
{
// Defines all resource types for future use.
AddResource("Food", 0);
AddResource("Wood", 0);
AddResource("Stone", 0);
AddResource("Ore", 0);
AddResource("Population", 0);
AddResource("Housing", 0);
}
// ====================================================================
function GiveResources(resourceName, resourceQty)
{
// Generic function to add resources to the player's Pool.
switch (resourceName)
{
case "Food":
localPlayer.resource.food += resourceQty;
break;
case "Wood":
localPlayer.resource.wood += resourceQty;
break;
case "Stone":
localPlayer.resource.stone += resourceQty;
break;
case "Ore":
localPlayer.resource.ore += resourceQty;
break;
default:
break;
}
// Find the resource in the list.
resourceSeek = 0;
while (resourceName != localPlayer.resource[resourceSeek].name && resourceSeek < localPlayer.resource.last)
resourceSeek++;
// If the resource wasn't in the list, report an error.
return false;
// Add the quantity to the resource.
localPlayer.resource[resourceSeek].qty += resourceQty;
console.write("Earned " + resourceQty + " resources.");
return true;
}
// ====================================================================
function UpdateResourcePool()
{
getGUIObjectByName("SN_RESOURCE_COUNTER_FOOD").caption = localPlayer.resource.food;
getGUIObjectByName("SN_RESOURCE_COUNTER_WOOD").caption = localPlayer.resource.wood;
getGUIObjectByName("SN_RESOURCE_COUNTER_STONE").caption = localPlayer.resource.stone;
getGUIObjectByName("SN_RESOURCE_COUNTER_ORE").caption = localPlayer.resource.ore;
getGUIObjectByName("SN_RESOURCE_COUNTER_POPULATION").caption = localPlayer.resource.pop.curr + "/" + localPlayer.resource.pop.housing;
// Populate the resource pool with current quantities.
for (resourceSeek = 0; resourceSeek < localPlayer.resource.last; resourceSeek++)
{
switch (localPlayer.resource[resourceSeek].name.toString())
{
case "POPULATION":
// If it's population, combine population and housing in one string.
getGUIObjectByName("SN_RESOURCE_COUNTER_POPULATION").caption = localPlayer.resource[resourceSeek].qty + "/" + localPlayer.resource[resourceSeek].qty;
break;
case "HOUSING":
// Skip housing, as it's handled as a component of population.
break;
default:
// Set the value of a normal resource caption.
getGUIObjectByName("SN_RESOURCE_COUNTER_" + localPlayer.resource[resourceSeek].name).caption = localPlayer.resource[resourceSeek].qty.toString();
break;
}
}
}

View File

@ -22,6 +22,25 @@ function initTeamTray()
// ====================================================================
function SelectGroup(groupNumber)
{
// Set the current selection to the specified group (team) number, 1-9.
// If the group is already selected, centre on the group.
if (groups[groupNumber].length > 0)
{
// If group already selected,
if (selection == groups[groupNumber])
{
setCameraTarget(selection[0].position); // Centre on it.
}
else
selection = groups[groupNumber]; // If not, select it.
}
}
// ====================================================================
function UpdateTeamTray()
{
// Enable a Team Tray icon if its group has been created.