1
0
forked from 0ad/0ad

# cleanup JS

fix tabs and indenting

This was SVN commit r4371.
This commit is contained in:
janwas 2006-09-21 11:30:40 +00:00
parent 054cbaf644
commit d34ae19788
9 changed files with 356 additions and 361 deletions

View File

@ -38,89 +38,88 @@ TODO: Make button code work for any number of buttons without extending the code
function messageBox (mbWidth, mbHeight, mbMessage, mbTitle, mbMode, mbButtonCaptions, mbButtonsCode)
{
mbMainObj = getGUIObjectByName ("mbMain");
mbTitleObj = getGUIObjectByName ("mbTitleBar");
mbTextObj = getGUIObjectByName ("mbText");
mbButton1Obj = getGUIObjectByName ("mbButton1");
mbButton2Obj = getGUIObjectByName ("mbButton2");
mbButton3Obj = getGUIObjectByName ("mbButton3");
mbMainObj = getGUIObjectByName ("mbMain");
mbTitleObj = getGUIObjectByName ("mbTitleBar");
mbTextObj = getGUIObjectByName ("mbText");
mbButton1Obj = getGUIObjectByName ("mbButton1");
mbButton2Obj = getGUIObjectByName ("mbButton2");
mbButton3Obj = getGUIObjectByName ("mbButton3");
// Calculate size
mbLRDiff = mbWidth / 2; // Message box left/right difference from 50% of screen
mbUDDiff = mbHeight / 2; // Message box up/down difference from 50% of screen
mbSizeString = "50%-" + mbLRDiff + " 50%-" + mbUDDiff + " 50%+" + mbLRDiff + " 50%+" + mbUDDiff;
mbMainObj.size = mbSizeString;
// Texts
mbTitleObj.caption = mbTitle;
mbTextObj.caption = mbMessage;
// Calculate size
mbLRDiff = mbWidth / 2; // Message box left/right difference from 50% of screen
mbUDDiff = mbHeight / 2; // Message box up/down difference from 50% of screen
mbSizeString = "50%-" + mbLRDiff + " 50%-" + mbUDDiff + " 50%+" + mbLRDiff + " 50%+" + mbUDDiff;
mbMainObj.size = mbSizeString;
// Texts
mbTitleObj.caption = mbTitle;
mbTextObj.caption = mbMessage;
// Message box modes
// There is a number of standard modes, and if none of these is used (mbMode == 0), the button captions will be
// taken from the array mbButtonCaptions; there currently is a maximum of three buttons.
switch (mbMode)
// Message box modes
// There is a number of standard modes, and if none of these is used (mbMode == 0), the button captions will be
// taken from the array mbButtonCaptions; there currently is a maximum of three buttons.
switch (mbMode)
{
case 1:
// Simple Yes/No question box
mbButtonCaptions = new Array("Yes", "No");
break;
case 2:
// Okay-only box
mbButtonCaptions = new Array("OK");
break;
case 3:
// Retry/Abort/Ignore box (will we ever need this?!)
mbButtonCaptions = new Array("Retry", "Ignore", "Abort");
default:
case 1:
// Simple Yes/No question box
mbButtonCaptions = new Array("Yes", "No");
break;
}
case 2:
// Okay-only box
mbButtonCaptions = new Array("OK");
break;
case 3:
// Retry/Abort/Ignore box (will we ever need this?!)
mbButtonCaptions = new Array("Retry", "Ignore", "Abort");
default:
break;
}
// Buttons
switch (mbButtonCaptions.length)
// Buttons
switch (mbButtonCaptions.length)
{
case 1:
// One Button only
mbButton1Obj.caption = mbButtonCaptions[0];
mbButton1Obj.size = "30% 100%-80 70% 100%-50";
mbButton1Obj.hidden = false;
mbButton2Obj.hidden = true;
mbButton3Obj.hidden = true;
break;
case 2:
// Two Buttons
mbButton1Obj.caption = mbButtonCaptions[0];
mbButton2Obj.caption = mbButtonCaptions[1];
mbButton1Obj.size = "10% 100%-80 45% 100%-50";
mbButton2Obj.size = "55% 100%-80 90% 100%-50";
mbButton1Obj.hidden = false;
mbButton2Obj.hidden = false;
mbButton3Obj.hidden = true;
break;
case 3:
// Three Buttons
mbButton1Obj.caption = mbButtonCaptions[0];
mbButton2Obj.caption = mbButtonCaptions[1];
mbButton3Obj.caption = mbButtonCaptions[2];
mbButton1Obj.size = "10% 100%-80 30% 100%-50";
mbButton2Obj.size = "40% 100%-80 60% 100%-50";
mbButton3Obj.size = "70% 100%-80 90% 100%-50";
mbButton1Obj.hidden = false;
mbButton2Obj.hidden = false;
mbButton3Obj.hidden = false;
break;
}
// Show the message box
guiUnHide (mbMainObj.name);
// Testing
getGUIGlobal().mbButton1Code = mbButtonsCode[0];
getGUIGlobal().mbButton2Code = mbButtonsCode[1];
getGUIGlobal().mbButton3Code = mbButtonsCode[2];
case 1:
// One Button only
mbButton1Obj.caption = mbButtonCaptions[0];
mbButton1Obj.size = "30% 100%-80 70% 100%-50";
mbButton1Obj.hidden = false;
mbButton2Obj.hidden = true;
mbButton3Obj.hidden = true;
break;
case 2:
// Two Buttons
mbButton1Obj.caption = mbButtonCaptions[0];
mbButton2Obj.caption = mbButtonCaptions[1];
mbButton1Obj.size = "10% 100%-80 45% 100%-50";
mbButton2Obj.size = "55% 100%-80 90% 100%-50";
mbButton1Obj.hidden = false;
mbButton2Obj.hidden = false;
mbButton3Obj.hidden = true;
break;
case 3:
// Three Buttons
mbButton1Obj.caption = mbButtonCaptions[0];
mbButton2Obj.caption = mbButtonCaptions[1];
mbButton3Obj.caption = mbButtonCaptions[2];
mbButton1Obj.size = "10% 100%-80 30% 100%-50";
mbButton2Obj.size = "40% 100%-80 60% 100%-50";
mbButton3Obj.size = "70% 100%-80 90% 100%-50";
mbButton1Obj.hidden = false;
mbButton2Obj.hidden = false;
mbButton3Obj.hidden = false;
break;
}
// Show the message box
guiUnHide (mbMainObj.name);
// Testing
getGUIGlobal().mbButton1Code = mbButtonsCode[0];
getGUIGlobal().mbButton2Code = mbButtonsCode[1];
getGUIGlobal().mbButton3Code = mbButtonsCode[2];
}
// ====================================================================

View File

@ -1,6 +1,6 @@
/*
DESCRIPTION : Functions used load/end the game session and manipulate the loading screen.
NOTES :
NOTES :
*/
// ====================================================================
@ -32,14 +32,14 @@ function startMap (mapName, losSetting, openWindow)
// Begin game session.
if (! startGame())
{
// Failed to start the game; go back to the main menu.
guiSwitch ("ld", "pg");
// Restore default cursor.
setCursor ("arrow-default");
// 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);
// Failed to start the game; go back to the main menu.
guiSwitch ("ld", "pg");
// Restore default cursor.
setCursor ("arrow-default");
// 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);
}
// Set starting UI layout.
@ -50,43 +50,43 @@ function startMap (mapName, losSetting, openWindow)
setSkin ("wheat");
// Set GUI coordinates to starting orientation.
flipGUI (GUIType);
flipGUI (GUIType);
}
// ====================================================================
function startLoadingScreen()
{
// Switch screens from main menu to loading screen.
guiSwitch ("pg", "ld");
// Set to "hourglass" cursor.
setCursor("cursor-wait");
console.write ("Loading " + g_GameAttributes.mapFile + " (" + g_GameAttributes.numPlayers + " players) ...");
// Switch screens from main menu to loading screen.
guiSwitch ("pg", "ld");
// Set to "hourglass" cursor.
setCursor("cursor-wait");
console.write ("Loading " + g_GameAttributes.mapFile + " (" + g_GameAttributes.numPlayers + " players) ...");
// Choose random concept art for loading screen background (should depend on the selected civ later when this is specified).
var sprite = "";
var loadingBkgArray = buildDirEntList("art/textures/ui/loading/", "*.dds", false);
if (loadingBkgArray.length == 0)
console.write ("ERROR: Failed to find any matching textures for the loading screen background.");
else
{
// Get a random index from the list of loading screen backgrounds.
sprite = "stretched:" + loadingBkgArray[getRandom (0, loadingBkgArray.length-1)];
sprite = sprite.replace ("art/textures/ui/", "");
}
getGUIObjectByName ("ldConcept").sprite = sprite;
// Choose random concept art for loading screen background (should depend on the selected civ later when this is specified).
var sprite = "";
var loadingBkgArray = buildDirEntList("art/textures/ui/loading/", "*.dds", false);
if (loadingBkgArray.length == 0)
console.write ("ERROR: Failed to find any matching textures for the loading screen background.");
else
{
// Get a random index from the list of loading screen backgrounds.
sprite = "stretched:" + loadingBkgArray[getRandom (0, loadingBkgArray.length-1)];
sprite = sprite.replace ("art/textures/ui/", "");
}
getGUIObjectByName ("ldConcept").sprite = sprite;
// janwas: main loop now sets progress / description, but that won't
// happen until the first timeslice completes, so set initial values.
getGUIObjectByName ("ldTitleBar").caption = "Loading Scenario ...";
getGUIObjectByName ("ldProgressBarText").caption = "";
getGUIObjectByName ("ldProgressBar").caption = 0;
getGUIObjectByName ("ldText").caption = "LOADING " + g_GameAttributes.mapFile + " ...\nPlease wait ...";
// janwas: main loop now sets progress / description, but that won't
// happen until the first timeslice completes, so set initial values.
getGUIObjectByName ("ldTitleBar").caption = "Loading Scenario ...";
getGUIObjectByName ("ldProgressBarText").caption = "";
getGUIObjectByName ("ldProgressBar").caption = 0;
getGUIObjectByName ("ldText").caption = "LOADING " + g_GameAttributes.mapFile + " ...\nPlease wait ...";
// Pick a random tip of the day (each line is a separate tip).
var tipArray = readFileLines("gui/text/tips.txt");
// Set tip string.
getGUIObjectByName ("ldTip").caption = tipArray[getRandom(0, tipArray.length-1)];
// Pick a random tip of the day (each line is a separate tip).
var tipArray = readFileLines("gui/text/tips.txt");
// Set tip string.
getGUIObjectByName ("ldTip").caption = tipArray[getRandom(0, tipArray.length-1)];
}
// ====================================================================
@ -110,33 +110,33 @@ function reallyStartGame()
function setupSession ()
{
// Do essentials that can only be done when the session has been loaded ...
// For example, create the resource types, scores, etc, for each player.
// Do essentials that can only be done when the session has been loaded ...
// For example, create the resource types, scores, etc, for each player.
/*
if (sessionType == "Skirmish")
{
// Set up a bunch of players so we can see them pretty colours. :P
console.write ("Setting Up Temporary Single Players");
// The first player is by default allocated to the local player in SP, so
// adding 7 players means that we'll have 8 players in total
for (var i=0; i<7; i++)
{
g_GameAttributes.slots[i+1].assignLocal();
console.write ("Slot "+(i+1)+" is assigned: " + g_GameAttributes.slots[i+1].assignment);
}
// Set up a bunch of players so we can see them pretty colours. :P
console.write ("Setting Up Temporary Single Players");
// The first player is by default allocated to the local player in SP, so
// adding 7 players means that we'll have 8 players in total
for (var i=0; i<7; i++)
{
g_GameAttributes.slots[i+1].assignLocal();
console.write ("Slot "+(i+1)+" is assigned: " + g_GameAttributes.slots[i+1].assignment);
}
}
*/
// 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, 1)
// 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, 1)
// Create the resouce counters
createResourceCounters();
// Start refreshing the session controls.
// Start refreshing the session controls.
setInterval( snRefresh, 1, 100 );
}
@ -144,32 +144,31 @@ function setupSession ()
function endSession (closeType)
{
// Occurs when the player chooses to close the current game.
// 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,
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", "menu");
crossFade(curr_session_playlist_1, curr_music, 1);
// End the session.
endGame();
// Fade out current music and return to playing menu theme.
curr_music = newRandomSound("music", "menu");
crossFade(curr_session_playlist_1, curr_music, 1);
// Stop refreshing the session controls.
cancelInterval();
// Stop refreshing the session controls.
cancelInterval();
// Swap GUIs to display main menu.
guiSwitch ("sn", "pg");
break;
case ("exit"):
// If the player has chosen to shutdown and immediately return to operating system,
exit();
break;
}
// Swap GUIs to display main menu.
guiSwitch ("sn", "pg");
break;
case ("exit"):
// If the player has chosen to shutdown and immediately return to operating system,
exit();
break;
}
}
// ====================================================================

View File

@ -15,7 +15,7 @@ function initMPHost (parentWindow, gameName, welcomeMessage, profileName)
server.serverName = gameName;
// Host Name
server.serverPlayerName = profileName;
// start listening
var success = server.open();
if (!success)
@ -56,7 +56,7 @@ console.write (event.id);
messageBox(400, 200, "Client " + event.name + "(" + event.id + ") disconnected from " + event.session + ".", "Client Disconnected", 2, new Array(), new Array());
}
server.onChat = function (event)
{
messageBox(400, 200, "(" + event.sender + ")" + event.message, "Host Chat Message", 2, new Array(), new Array());

View File

@ -35,13 +35,13 @@ function initSession()
function initCellReference()
{
cellGroup = new Array();
cellGroup = new Array();
// Define categories of cell groups by checking their reference files in the same locations as the icon sheets.
addCellGroupCategory ("art/textures/ui/session/icons/sheets/");
// (Note that we don't use this and we probably shouldn't, since the entities state which icon cell they should use; it makes it easier to remember which icon is used
// for which unit if we have this reference sheet, though.)
addCellGroupCategory ("art/textures/ui/session/portraits/sheets/");
// Define categories of cell groups by checking their reference files in the same locations as the icon sheets.
addCellGroupCategory ("art/textures/ui/session/icons/sheets/");
// (Note that we don't use this and we probably shouldn't, since the entities state which icon cell they should use; it makes it easier to remember which icon is used
// for which unit if we have this reference sheet, though.)
addCellGroupCategory ("art/textures/ui/session/portraits/sheets/");
}
// ====================================================================
@ -120,18 +120,18 @@ function setPortrait(objectName, portraitString, portraitSuffix, portraitCell)
return 1;
}
// Set the three portraits.
// Set the three portraits.
if (portraitSuffix && portraitSuffix != "")
setPortraitGUIObject.sprite = "sn" + portraitString + portraitSuffix;
setPortraitGUIObject.sprite = "sn" + portraitString + portraitSuffix;
else
setPortraitGUIObject.sprite = "sn" + portraitString;
setPortraitGUIObject.sprite = "sn" + portraitString;
setPortraitGUIObject.sprite_over = setPortraitGUIObject.sprite + "Over";
setPortraitGUIObject.sprite_disabled = setPortraitGUIObject.sprite + "Disabled";
setPortraitGUIObject.sprite_over = setPortraitGUIObject.sprite + "Over";
setPortraitGUIObject.sprite_disabled = setPortraitGUIObject.sprite + "Disabled";
// If the source texture is a multi-frame image (icon sheet), specify correct cell.
if (portraitCell && portraitCell != "")
setPortraitGUIObject.cell_id = portraitCell;
// If the source texture is a multi-frame image (icon sheet), specify correct cell.
if (portraitCell && portraitCell != "")
setPortraitGUIObject.cell_id = portraitCell;
else
setPortraitGUIObject.cell_id = "";
@ -146,25 +146,25 @@ function flipGUI (NewGUIType)
switch (NewGUIType)
{
// Set which GUI to use.
case rb:
case lb:
case lt:
case rt:
GUIType = NewGUIType;
// Set which GUI to use.
case rb:
case lb:
case lt:
case rt:
GUIType = NewGUIType;
break;
default:
// If no type specified, toggle.
if (GUIType == rb)
GUIType = lb;
else
if (GUIType == lb)
GUIType = lt;
else
if (GUIType == lt)
GUIType = rt;
else
GUIType = rb;
default:
// If no type specified, toggle.
if (GUIType == rb)
GUIType = lb;
else
if (GUIType == lb)
GUIType = lt;
else
if (GUIType == lt)
GUIType = rt;
else
GUIType = rb;
break;
}
// Seek through all sizes created.

View File

@ -48,69 +48,62 @@ function worldClickHandler(event)
}
switch (cmd)
{
// location target commands
case NMT_Goto:
case NMT_Run:
case NMT_Patrol:
if (event.queued)
// location target commands
case NMT_Goto:
case NMT_Run:
case NMT_Patrol:
if (event.queued)
{
cmd = NMT_AddWaypoint;
}
args[0]=event.x;
args[1]=event.y;
break;
case NMT_AddWaypoint:
args[0]=event.x;
args[1]=event.y;
break;
// entity target commands
case NMT_Generic:
args[0]=event.entity;
if ( event.clicks == 1)
args[1]=event.action;
else
args[1]=event.secondaryAction;
break;
//TODO: get rid of order() calls.
case NMT_NotifyRequest:
if (event.clicks == 1)
action = event.action;
else
action = event.secondaryAction;
if (event.entity.isIdle())
{
for (var i=0; i<selection.length;i++)
{
cmd = NMT_AddWaypoint;
if (!selection[i].actions)
continue;
console.write("Requesting notification for " + event.entity);
selection[i].requestNotification( event.entity, action, true, false );
selection[i].order( ORDER_GOTO, event.entity.position.x, event.entity.position.z - selection[i].actions.escort.distance, true);
}
args[0]=event.x;
args[1]=event.y;
break;
case NMT_AddWaypoint:
args[0]=event.x;
args[1]=event.y;
break;
// entity target commands
// I'm guessing we no longer require these now that they have become generic events?
// case NMT_AttackMelee:
// case NMT_Gather:
// case NMT_Heal:
// args[0]=event.entity;
// args[1]=null;
// break;
case NMT_Generic:
args[0]=event.entity;
if ( event.clicks == 1)
args[1]=event.action;
else
args[1]=event.secondaryAction;
break;
//TODO: get rid of order() calls.
case NMT_NotifyRequest:
if (event.clicks == 1)
action = event.action;
else
action = event.secondaryAction;
if (event.entity.isIdle())
}
else
{
for (var i=0; i<selection.length;i++)
{
for (var i=0; i<selection.length;i++)
{
if (!selection[i].actions)
continue;
console.write("Requesting notification for " + event.entity);
selection[i].requestNotification( event.entity, action, true, false );
selection[i].order( ORDER_GOTO, event.entity.position.x, event.entity.position.z - selection[i].actions.escort.distance, true);
}
if (!selection[i].actions)
continue;
console.write("Requesting notification for " + event.entity);
selection[i].requestNotification( event.entity, action, true, false );
}
else
{
for (var i=0; i<selection.length;i++)
{
if (!selection[i].actions)
continue;
console.write("Requesting notification for " + event.entity);
selection[i].requestNotification( event.entity, action, true, false );
}
}
return;
default:
console.write("worldClickHandler: Unknown order: "+cmd);
return;
}
return;
default:
console.write("worldClickHandler: Unknown order: "+cmd);
return;
}
if (event.clicks == 2)
@ -127,15 +120,15 @@ function selectEntity(handler)
{
endSelection();
startSelection(function (event) {
// Selection is performed when single-clicking the right mouse
// button.
if (event.button == SDL_BUTTON_RIGHT && event.clicks == 1)
{
handler(event.entity);
}
// End selection on first mouse-click
endSelection();
});
// Selection is performed when single-clicking the right mouse
// button.
if (event.button == SDL_BUTTON_RIGHT && event.clicks == 1)
{
handler(event.entity);
}
// End selection on first mouse-click
endSelection();
});
}
// ====================================================================
@ -144,15 +137,15 @@ function selectLocation(handler)
{
endSelection();
startSelection(function (event) {
// Selection is performed when single-clicking the right mouse
// button.
if (event.button == SDL_BUTTON_RIGHT && event.clicks == 1)
{
handler(event.x, event.y);
}
// End selection on first mouse-click
endSelection();
});
// Selection is performed when single-clicking the right mouse
// button.
if (event.button == SDL_BUTTON_RIGHT && event.clicks == 1)
{
handler(event.x, event.y);
}
// End selection on first mouse-click
endSelection();
});
}
// ====================================================================
@ -186,22 +179,22 @@ function isSelecting()
function makeUnit (x, y, z, MakeUnitName)
{
// Spawn an entity at the given coordinates.
// Spawn an entity at the given coordinates.
var dudeSpawnPoint = new Vector3D(x, y, z);
new Entity(getEntityTemplate(MakeUnitName), dudeSpawnPoint, 1.0);
// writeConsole(MakeUnitName + " created at " + DudeSpawnPoint);
var dudeSpawnPoint = new Vector3D(x, y, z);
new Entity(getEntityTemplate(MakeUnitName), dudeSpawnPoint, 1.0);
// writeConsole(MakeUnitName + " created at " + DudeSpawnPoint);
}
// ====================================================================
function selected()
{
// Returns how many units selected.
// Returns how many units selected.
if( selection.length > 0 )
return( selection[0] );
return( null );
if( selection.length > 0 )
return( selection[0] );
return( null );
}
// ====================================================================
@ -256,6 +249,6 @@ function validProperty (propertyName)
// If we managed to check them all, every element in the property is valid. Return true.
return true;
}
// ====================================================================

View File

@ -1,6 +1,6 @@
/*
DESCRIPTION : Generic utility functions.
NOTES :
NOTES :
*/
// ====================================================================
@ -19,50 +19,50 @@ function getRandom(randomMin, randomMax)
function parseDelimiterString (parseString, delimiter)
{
// Seeks through the delimiters in a string and populates the elements of an array with fields found between them.
// Seeks through the delimiters in a string and populates the elements of an array with fields found between them.
// Declare local variables.
var parseLoop = 0;
var parseElement = 0;
var seekDelimiter = 0;
var parseArray = new Array();
// Declare local variables.
var parseLoop = 0;
var parseElement = 0;
var seekDelimiter = 0;
var parseArray = new Array();
// While we're still within the bounds of the string,
while (parseLoop <= parseString.length)
{
// Seek until we find a delimiter.
seekDelimiter = parseLoop;
while (parseString[seekDelimiter] != delimiter && seekDelimiter <= parseString.length)
seekDelimiter++;
// While we're still within the bounds of the string,
while (parseLoop <= parseString.length)
{
// Seek until we find a delimiter.
seekDelimiter = parseLoop;
while (parseString[seekDelimiter] != delimiter && seekDelimiter <= parseString.length)
seekDelimiter++;
// If we found a delimiter within the string,
if (seekDelimiter != parseString.length)
{
// Store sub-string between start point and delimiter in array element.
parseArray[parseElement] = parseString.substring(parseLoop, seekDelimiter);
parseElement++;
}
// If we found a delimiter within the string,
if (seekDelimiter != parseString.length)
{
// Store sub-string between start point and delimiter in array element.
parseArray[parseElement] = parseString.substring(parseLoop, seekDelimiter);
parseElement++;
}
// Move to after delimiter position for next seek.
parseLoop = seekDelimiter+1;
}
// Move to after delimiter position for next seek.
parseLoop = seekDelimiter+1;
}
// Store length of array.
parseArray.length = parseElement;
// Store length of array.
parseArray.length = parseElement;
return parseArray;
return parseArray;
}
// ====================================================================
function addArrayElement(Array)
{
// Adds an element to an array, updates its given index, and returns the index of the element.
// Adds an element to an array, updates its given index, and returns the index of the element.
Array[Array.last] = new Object();
Array.last++;
Array[Array.last] = new Object();
Array.last++;
return (Array.last - 1);
return (Array.last - 1);
}
// ====================================================================

View File

@ -1,6 +1,6 @@
/*
DESCRIPTION : GUI animation functions (sliding in/out, fading, etc).
NOTES :
NOTES :
*/
// ====================================================================
@ -8,26 +8,26 @@
function GUISlideIn(GUIObject, SlideSpeed)
{
// Just me testing some stuff :)
var SlideObject = getGUIObjectByName(GUIObject);
var SizeVar = SlideObject.size;
//var Sizes = SizeVar.split(" ");
// Just me testing some stuff :)
var SlideObject = getGUIObjectByName(GUIObject);
var SizeVar = SlideObject.size;
//var Sizes = SizeVar.split(" ");
//var x_s = Sizes[0];
//var y_s = Sizes[1];
//var x_e = Sizes[2];
//var y_e = Sizes[3];
//var height = x_e - x_s;
//var x_s = Sizes[0];
//var y_s = Sizes[1];
//var x_e = Sizes[2];
//var y_e = Sizes[3];
//var height = x_e - x_s;
//var Time = new Date();
//var StartTime = Time.getTime();
var i = 0;
while(i <= 2) {
i++;
SlideObject.size = new GUISize(x_s, 0 + i, x_e, 0 + i + height);
}
//var Time = new Date();
//var StartTime = Time.getTime();
var i = 0;
while(i <= 2) {
i++;
SlideObject.size = new GUISize(x_s, 0 + i, x_e, 0 + i + height);
}
}

View File

@ -38,8 +38,8 @@ function guiToggle (objectName)
if (guiObject == "" || guiObject == null || guiObject == undefined || guiObject == "undefined")
console.write ("guiToggle(): GUI Object not found: " + objectName);
// Toggle it
guiObject.hidden = !guiObject.hidden;
// Toggle it
guiObject.hidden = !guiObject.hidden;
}
// ====================================================================

View File

@ -1,40 +1,44 @@
function updateOrbital()
{
if( !getGUIObjectByName( 'arena' ).hidden )
{
g_ballx += g_balldx;
g_bally += g_balldy;
if (g_ballx > 600) {
g_balldx *= -0.9;
g_ballx = 600-(g_ballx-600);
}
else if (g_ballx < 0) {
g_balldx *= -0.9;
g_ballx = -g_ballx;
}
if (g_bally > 400) {
g_balldy *= -0.9;
g_bally = 400-(g_bally-400);
}
else if (g_bally < 0) {
g_balldy *= -0.9;
g_bally = -g_bally;
}
function updateOrbital()
{
if( !getGUIObjectByName( 'arena' ).hidden )
{
g_ballx += g_balldx;
g_bally += g_balldy;
if (g_ballx > 600)
{
g_balldx *= -0.9;
g_ballx = 600-(g_ballx-600);
}
else if (g_ballx < 0)
{
g_balldx *= -0.9;
g_ballx = -g_ballx;
}
if (g_bally > 400)
{
g_balldy *= -0.9;
g_bally = 400-(g_bally-400);
}
else if (g_bally < 0)
{
g_balldy *= -0.9;
g_bally = -g_bally;
}
// Gravitate towards the mouse
var vect_x = g_ballx-g_mousex;
var vect_y = g_bally-g_mousey;
var dsquared = vect_x*vect_x + vect_y*vect_y;
if (dsquared < 1000) dsquared = 1000;
var force = 10000.0 / dsquared;
var mag = Math.sqrt(dsquared);
vect_x /= mag; vect_y /= mag;
g_balldx -= force * vect_x;
g_balldy -= force * vect_y;
var ball = getGUIObjectByName('ball');
var r=5;
ball.size = new GUISize(g_ballx-r, g_bally-r, g_ballx+r, g_bally+r);
}
}
// Gravitate towards the mouse
var vect_x = g_ballx-g_mousex;
var vect_y = g_bally-g_mousey;
var dsquared = vect_x*vect_x + vect_y*vect_y;
if (dsquared < 1000) dsquared = 1000;
var force = 10000.0 / dsquared;
var mag = Math.sqrt(dsquared);
vect_x /= mag; vect_y /= mag;
g_balldx -= force * vect_x;
g_balldy -= force * vect_y;
var ball = getGUIObjectByName('ball');
var r=5;
ball.size = new GUISize(g_ballx-r, g_bally-r, g_ballx+r, g_bally+r);
}
}