added everything
This commit is contained in:
47
example/starter.racing/client/scripts/audioProfiles.cs
Executable file
47
example/starter.racing/client/scripts/audioProfiles.cs
Executable file
@ -0,0 +1,47 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Channel assignments (channel 0 is unused in-game).
|
||||
|
||||
$GuiAudioType = 1;
|
||||
$SimAudioType = 2;
|
||||
$MessageAudioType = 3;
|
||||
|
||||
new AudioDescription(AudioGui)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = $GuiAudioType;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioMessage)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = $MessageAudioType;
|
||||
};
|
||||
|
||||
new AudioProfile(AudioButtonOver)
|
||||
{
|
||||
filename = "~/data/sound/buttonOver.wav";
|
||||
description = "AudioGui";
|
||||
preload = true;
|
||||
};
|
||||
|
||||
new AudioProfile(AudioCountBeep)
|
||||
{
|
||||
filename = "~/data/sound/beep1.wav";
|
||||
description = "AudioGui";
|
||||
preload = true;
|
||||
};
|
||||
|
||||
new AudioProfile(AudioGoBeep)
|
||||
{
|
||||
filename = "~/data/sound/beep2.wav";
|
||||
description = "AudioGui";
|
||||
preload = true;
|
||||
};
|
78
example/starter.racing/client/scripts/centerPrint.cs
Executable file
78
example/starter.racing/client/scripts/centerPrint.cs
Executable file
@ -0,0 +1,78 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$centerPrintActive = 0;
|
||||
$bottomPrintActive = 0;
|
||||
|
||||
// Selectable window sizes
|
||||
$CenterPrintSizes[1] = 20;
|
||||
$CenterPrintSizes[2] = 36;
|
||||
$CenterPrintSizes[3] = 56;
|
||||
|
||||
// time is specified in seconds
|
||||
function clientCmdCenterPrint( %message, %time, %size )
|
||||
{
|
||||
// if centerprint already visible, reset text and time.
|
||||
if ($centerPrintActive) {
|
||||
if (centerPrintDlg.removePrint !$= "")
|
||||
cancel(centerPrintDlg.removePrint);
|
||||
}
|
||||
else {
|
||||
CenterPrintDlg.visible = 1;
|
||||
$centerPrintActive = 1;
|
||||
}
|
||||
|
||||
CenterPrintText.setText( "<just:center>" @ %message );
|
||||
CenterPrintDlg.extent = firstWord(CenterPrintDlg.extent) @ " " @ $CenterPrintSizes[%size];
|
||||
|
||||
if (%time > 0)
|
||||
centerPrintDlg.removePrint = schedule( ( %time * 1000 ), 0, "clientCmdClearCenterPrint" );
|
||||
}
|
||||
|
||||
// time is specified in seconds
|
||||
function clientCmdBottomPrint( %message, %time, %size )
|
||||
{
|
||||
// if bottomprint already visible, reset text and time.
|
||||
if ($bottomPrintActive) {
|
||||
if( bottomPrintDlg.removePrint !$= "")
|
||||
cancel(bottomPrintDlg.removePrint);
|
||||
}
|
||||
else {
|
||||
bottomPrintDlg.setVisible(true);
|
||||
$bottomPrintActive = 1;
|
||||
}
|
||||
|
||||
bottomPrintText.setText( "<just:center>" @ %message );
|
||||
bottomPrintDlg.extent = firstWord(bottomPrintDlg.extent) @ " " @ $CenterPrintSizes[%size];
|
||||
|
||||
if (%time > 0)
|
||||
bottomPrintDlg.removePrint = schedule( ( %time * 1000 ), 0, "clientCmdClearbottomPrint" );
|
||||
}
|
||||
|
||||
function BottomPrintText::onResize(%this, %width, %height)
|
||||
{
|
||||
%this.position = "0 0";
|
||||
}
|
||||
|
||||
function CenterPrintText::onResize(%this, %width, %height)
|
||||
{
|
||||
%this.position = "0 0";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
function clientCmdClearCenterPrint()
|
||||
{
|
||||
$centerPrintActive = 0;
|
||||
CenterPrintDlg.visible = 0;
|
||||
CenterPrintDlg.removePrint = "";
|
||||
}
|
||||
|
||||
function clientCmdClearBottomPrint()
|
||||
{
|
||||
$bottomPrintActive = 0;
|
||||
BottomPrintDlg.visible = 0;
|
||||
BottomPrintDlg.removePrint = "";
|
||||
}
|
286
example/starter.racing/client/scripts/chatHud.cs
Executable file
286
example/starter.racing/client/scripts/chatHud.cs
Executable file
@ -0,0 +1,286 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Message Hud
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// chat hud sizes
|
||||
$outerChatLenY[1] = 72;
|
||||
$outerChatLenY[2] = 140;
|
||||
$outerChatLenY[3] = 200;
|
||||
|
||||
// Only play sound files that are <= 5000ms in length.
|
||||
$MaxMessageWavLength = 5000;
|
||||
|
||||
// Helper function to play a sound file if the message indicates.
|
||||
// Returns starting position of wave file indicator.
|
||||
function playMessageSound(%message, %voice, %pitch)
|
||||
{
|
||||
// Search for wav tag marker.
|
||||
%wavStart = strstr(%message, "~w");
|
||||
if (%wavStart == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
%wav = getSubStr(%message, %wavStart + 2, 1000);
|
||||
if (%voice !$= "") {
|
||||
%wavFile = "~/data/sound/voice/" @ %voice @ "/" @ %wav;
|
||||
}
|
||||
else {
|
||||
%wavFile = "~/data/sound/" @ %wav;
|
||||
}
|
||||
if (strstr(%wavFile, ".wav") != (strlen(%wavFile) - 4)) {
|
||||
%wavFile = %wavFile @ ".wav";
|
||||
}
|
||||
// XXX This only expands to a single filepath, of course; it
|
||||
// would be nice to support checking in each mod path if we
|
||||
// have multiple mods active.
|
||||
%wavFile = ExpandFilename(%wavFile);
|
||||
|
||||
if ((%pitch < 0.5) || (%pitch > 2.0)) {
|
||||
%pitch = 1.0;
|
||||
}
|
||||
|
||||
%wavLengthMS = alxGetWaveLen(%wavFile) * %pitch;
|
||||
if (%wavLengthMS == 0) {
|
||||
error("** WAV file \"" @ %wavFile @ "\" is nonexistent or sound is zero-length **");
|
||||
}
|
||||
else if (%wavLengthMS <= $MaxMessageWavLength) {
|
||||
if ($ClientChatHandle[%sender] != 0) {
|
||||
alxStop($ClientChatHandle[%sender]);
|
||||
}
|
||||
$ClientChatHandle[%sender] = alxCreateSource(AudioMessage, %wavFile);
|
||||
if (%pitch != 1.0) {
|
||||
alxSourcef($ClientChatHandle[%sender], "AL_PITCH", %pitch);
|
||||
}
|
||||
alxPlay($ClientChatHandle[%sender]);
|
||||
}
|
||||
else {
|
||||
error("** WAV file \"" @ %wavFile @ "\" is too long **");
|
||||
}
|
||||
|
||||
return %wavStart;
|
||||
}
|
||||
|
||||
|
||||
// All messages are stored in this HudMessageVector, the actual
|
||||
// MainChatHud only displays the contents of this vector.
|
||||
|
||||
new MessageVector(HudMessageVector);
|
||||
$LastHudTarget = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
function onChatMessage(%message, %voice, %pitch)
|
||||
{
|
||||
// XXX Client objects on the server must have voiceTag and voicePitch
|
||||
// fields for values to be passed in for %voice and %pitch... in
|
||||
// this example mod, they don't have those fields.
|
||||
|
||||
// Clients are not allowed to trigger general game sounds with their
|
||||
// chat messages... a voice directory MUST be specified.
|
||||
if (%voice $= "") {
|
||||
%voice = "default";
|
||||
}
|
||||
|
||||
// See if there's a sound at the end of the message, and play it.
|
||||
if ((%wavStart = playMessageSound(%message, %voice, %pitch)) != -1) {
|
||||
// Remove the sound marker from the end of the message.
|
||||
%message = getSubStr(%message, 0, %wavStart);
|
||||
}
|
||||
|
||||
// Chat goes to the chat HUD.
|
||||
if (getWordCount(%message)) {
|
||||
ChatHud.addLine(%message);
|
||||
}
|
||||
}
|
||||
|
||||
function onServerMessage(%message)
|
||||
{
|
||||
// See if there's a sound at the end of the message, and play it.
|
||||
if ((%wavStart = playMessageSound(%message)) != -1) {
|
||||
// Remove the sound marker from the end of the message.
|
||||
%message = getSubStr(%message, 0, %wavStart);
|
||||
}
|
||||
|
||||
// Server messages go to the chat HUD too.
|
||||
if (getWordCount(%message)) {
|
||||
ChatHud.addLine(%message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// MainChatHud methods
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function MainChatHud::onWake( %this )
|
||||
{
|
||||
// set the chat hud to the users pref
|
||||
%this.setChatHudLength( $Pref::ChatHudLength );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MainChatHud::setChatHudLength( %this, %length )
|
||||
{
|
||||
OuterChatHud.resize(firstWord(OuterChatHud.position), getWord(OuterChatHud.position, 1),
|
||||
firstWord(OuterChatHud.extent), $outerChatLenY[%length]);
|
||||
ChatScrollHud.scrollToBottom();
|
||||
ChatPageDown.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MainChatHud::nextChatHudLen( %this )
|
||||
{
|
||||
%len = $pref::ChatHudLength++;
|
||||
if ($pref::ChatHudLength == 4)
|
||||
$pref::ChatHudLength = 1;
|
||||
%this.setChatHudLength($pref::ChatHudLength);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ChatHud methods
|
||||
// This is the actual message vector/text control which is part of
|
||||
// the MainChatHud dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function ChatHud::addLine(%this,%text)
|
||||
{
|
||||
//first, see if we're "scrolled up"...
|
||||
%textHeight = %this.profile.fontSize;
|
||||
if (%textHeight <= 0)
|
||||
%textHeight = 12;
|
||||
%chatScrollHeight = getWord(%this.getGroup().getGroup().extent, 1);
|
||||
%chatPosition = getWord(%this.extent, 1) - %chatScrollHeight + getWord(%this.position, 1);
|
||||
%linesToScroll = mFloor((%chatPosition / %textHeight) + 0.5);
|
||||
if (%linesToScroll > 0)
|
||||
%origPosition = %this.position;
|
||||
|
||||
//add the message...
|
||||
while( !chatPageDown.isVisible() && HudMessageVector.getNumLines() && (HudMessageVector.getNumLines() >= $pref::HudMessageLogSize))
|
||||
{
|
||||
%tag = HudMessageVector.getLineTag(0);
|
||||
if(%tag != 0)
|
||||
%tag.delete();
|
||||
HudMessageVector.popFrontLine();
|
||||
}
|
||||
HudMessageVector.pushBackLine(%text, $LastHudTarget);
|
||||
$LastHudTarget = 0;
|
||||
|
||||
//now that we've added the message, see if we need to reset the position
|
||||
if (%linesToScroll > 0)
|
||||
{
|
||||
chatPageDown.setVisible(true);
|
||||
%this.position = %origPosition;
|
||||
}
|
||||
else
|
||||
chatPageDown.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function ChatHud::pageUp(%this)
|
||||
{
|
||||
// Find out the text line height
|
||||
%textHeight = %this.profile.fontSize;
|
||||
if (%textHeight <= 0)
|
||||
%textHeight = 12;
|
||||
|
||||
// Find out how many lines per page are visible
|
||||
%chatScrollHeight = getWord(%this.getGroup().getGroup().extent, 1);
|
||||
if (%chatScrollHeight <= 0)
|
||||
return;
|
||||
|
||||
%pageLines = mFloor(%chatScrollHeight / %textHeight) - 1;
|
||||
if (%pageLines <= 0)
|
||||
%pageLines = 1;
|
||||
|
||||
// See how many lines we actually can scroll up:
|
||||
%chatPosition = -1 * getWord(%this.position, 1);
|
||||
%linesToScroll = mFloor((%chatPosition / %textHeight) + 0.5);
|
||||
if (%linesToScroll <= 0)
|
||||
return;
|
||||
|
||||
if (%linesToScroll > %pageLines)
|
||||
%scrollLines = %pageLines;
|
||||
else
|
||||
%scrollLines = %linesToScroll;
|
||||
|
||||
// Now set the position
|
||||
%this.position = firstWord(%this.position) SPC (getWord(%this.position, 1) + (%scrollLines * %textHeight));
|
||||
|
||||
// Display the pageup icon
|
||||
chatPageDown.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function ChatHud::pageDown(%this)
|
||||
{
|
||||
// Find out the text line height
|
||||
%textHeight = %this.profile.fontSize;
|
||||
if (%textHeight <= 0)
|
||||
%textHeight = 12;
|
||||
|
||||
// Find out how many lines per page are visible
|
||||
%chatScrollHeight = getWord(%this.getGroup().getGroup().extent, 1);
|
||||
if (%chatScrollHeight <= 0)
|
||||
return;
|
||||
|
||||
%pageLines = mFloor(%chatScrollHeight / %textHeight) - 1;
|
||||
if (%pageLines <= 0)
|
||||
%pageLines = 1;
|
||||
|
||||
// See how many lines we actually can scroll down:
|
||||
%chatPosition = getWord(%this.extent, 1) - %chatScrollHeight + getWord(%this.position, 1);
|
||||
%linesToScroll = mFloor((%chatPosition / %textHeight) + 0.5);
|
||||
if (%linesToScroll <= 0)
|
||||
return;
|
||||
|
||||
if (%linesToScroll > %pageLines)
|
||||
%scrollLines = %pageLines;
|
||||
else
|
||||
%scrollLines = %linesToScroll;
|
||||
|
||||
// Now set the position
|
||||
%this.position = firstWord(%this.position) SPC (getWord(%this.position, 1) - (%scrollLines * %textHeight));
|
||||
|
||||
// See if we have should (still) display the pagedown icon
|
||||
if (%scrollLines < %linesToScroll)
|
||||
chatPageDown.setVisible(true);
|
||||
else
|
||||
chatPageDown.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Support functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function pageUpMessageHud()
|
||||
{
|
||||
ChatHud.pageUp();
|
||||
}
|
||||
|
||||
function pageDownMessageHud()
|
||||
{
|
||||
ChatHud.pageDown();
|
||||
}
|
||||
|
||||
function cycleMessageHudSize()
|
||||
{
|
||||
MainChatHud.nextChatHudLen();
|
||||
}
|
30
example/starter.racing/client/scripts/client.cs
Executable file
30
example/starter.racing/client/scripts/client.cs
Executable file
@ -0,0 +1,30 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Server Admin Commands
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function SAD(%password)
|
||||
{
|
||||
if (%password !$= "")
|
||||
commandToServer('SAD', %password);
|
||||
}
|
||||
|
||||
function SADSetPassword(%password)
|
||||
{
|
||||
commandToServer('SADSetPassword', %password);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Misc server commands
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function clientCmdSyncClock(%time)
|
||||
{
|
||||
// Time update from the server, this is only sent at the start of a mission
|
||||
// or when a client joins a game in progress.
|
||||
}
|
||||
|
373
example/starter.racing/client/scripts/default.bind.cs
Executable file
373
example/starter.racing/client/scripts/default.bind.cs
Executable file
@ -0,0 +1,373 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
if ( isObject( moveMap ) )
|
||||
moveMap.delete();
|
||||
new ActionMap(moveMap);
|
||||
|
||||
if ( isObject( racingMap ) )
|
||||
racingMap.delete();
|
||||
new ActionMap(racingMap);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Non-remapable binds
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function escapeFromGame()
|
||||
{
|
||||
if ( $Server::ServerType $= "SinglePlayer" )
|
||||
MessageBoxYesNo( "Quit Mission", "Exit from this Mission?", "disconnect();", "");
|
||||
else
|
||||
MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
|
||||
}
|
||||
|
||||
moveMap.bindCmd(keyboard, "escape", "", "escapeFromGame();");
|
||||
|
||||
function showPlayerList(%val)
|
||||
{
|
||||
if (%val)
|
||||
PlayerListGui.toggle();
|
||||
}
|
||||
|
||||
moveMap.bind( keyboard, F2, showPlayerList );
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Movement Keys
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
$movementSpeed = 1; // m/s
|
||||
|
||||
function setSpeed(%speed)
|
||||
{
|
||||
if(%speed)
|
||||
$movementSpeed = %speed;
|
||||
}
|
||||
|
||||
function moveleft(%val)
|
||||
{
|
||||
$mvLeftAction = %val * $movementSpeed;
|
||||
}
|
||||
|
||||
function moveright(%val)
|
||||
{
|
||||
$mvRightAction = %val * $movementSpeed;
|
||||
}
|
||||
|
||||
function moveup(%val)
|
||||
{
|
||||
$mvUpAction = %val * $movementSpeed;
|
||||
}
|
||||
|
||||
function movedown(%val)
|
||||
{
|
||||
$mvDownAction = %val * $movementSpeed;
|
||||
}
|
||||
|
||||
function accelerate(%val)
|
||||
{
|
||||
$mvForwardAction = %val * $movementSpeed;
|
||||
}
|
||||
|
||||
function brake(%val)
|
||||
{
|
||||
$mvBackwardAction = %val * $movementSpeed;
|
||||
}
|
||||
|
||||
function turnLeft( %val )
|
||||
{
|
||||
$mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||||
}
|
||||
|
||||
function turnRight( %val )
|
||||
{
|
||||
$mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||||
}
|
||||
|
||||
function panUp( %val )
|
||||
{
|
||||
$mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||||
}
|
||||
|
||||
function panDown( %val )
|
||||
{
|
||||
$mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||||
}
|
||||
|
||||
function getMouseAdjustAmount(%val)
|
||||
{
|
||||
// based on a default camera fov of 90'
|
||||
return(%val * ($cameraFov / 90) * 0.01);
|
||||
}
|
||||
|
||||
function yaw(%val)
|
||||
{
|
||||
$mvYaw += getMouseAdjustAmount(%val);
|
||||
}
|
||||
|
||||
function pitch(%val)
|
||||
{
|
||||
$mvPitch += getMouseAdjustAmount(%val);
|
||||
}
|
||||
|
||||
function handbrake(%val)
|
||||
{
|
||||
$mvTriggerCount2++;
|
||||
}
|
||||
|
||||
racingMap.bind( keyboard, a, turnleft );
|
||||
racingMap.bind( keyboard, d, turnright );
|
||||
racingMap.bind( keyboard, left, turnleft );
|
||||
racingMap.bind( keyboard, right, turnright );
|
||||
|
||||
moveMap.bind( keyboard, a, moveleft );
|
||||
moveMap.bind( keyboard, d, moveright );
|
||||
moveMap.bind( keyboard, left, moveleft );
|
||||
moveMap.bind( keyboard, right, moveright );
|
||||
|
||||
moveMap.bind( keyboard, w, accelerate );
|
||||
moveMap.bind( keyboard, s, brake );
|
||||
moveMap.bind( keyboard, up, accelerate );
|
||||
moveMap.bind( keyboard, down, brake );
|
||||
|
||||
moveMap.bind( keyboard, space, handbrake );
|
||||
moveMap.bind( mouse, xaxis, yaw );
|
||||
moveMap.bind( mouse, yaxis, pitch );
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Mouse Trigger
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function mouseFire(%val)
|
||||
{
|
||||
$mvTriggerCount0++;
|
||||
}
|
||||
|
||||
function altTrigger(%val)
|
||||
{
|
||||
$mvTriggerCount1++;
|
||||
}
|
||||
|
||||
moveMap.bind( mouse, button0, mouseFire );
|
||||
//moveMap.bind( mouse, button1, altTrigger );
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Zoom and FOV functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
if($Pref::player::CurrentFOV $= "")
|
||||
$Pref::player::CurrentFOV = 45;
|
||||
|
||||
function setZoomFOV(%val)
|
||||
{
|
||||
if(%val)
|
||||
toggleZoomFOV();
|
||||
}
|
||||
|
||||
function toggleZoom( %val )
|
||||
{
|
||||
if ( %val )
|
||||
{
|
||||
$ZoomOn = true;
|
||||
setFov( $Pref::player::CurrentFOV );
|
||||
}
|
||||
else
|
||||
{
|
||||
$ZoomOn = false;
|
||||
setFov( $Pref::player::DefaultFov );
|
||||
}
|
||||
}
|
||||
|
||||
moveMap.bind(keyboard, r, setZoomFOV);
|
||||
moveMap.bind(keyboard, e, toggleZoom);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Camera & View functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function toggleFreeLook( %val )
|
||||
{
|
||||
if ( %val )
|
||||
$mvFreeLook = true;
|
||||
else
|
||||
$mvFreeLook = false;
|
||||
}
|
||||
|
||||
$firstPerson = true;
|
||||
function toggleFirstPerson(%val)
|
||||
{
|
||||
if (%val)
|
||||
{
|
||||
$firstPerson = !$firstPerson;
|
||||
ServerConnection.setFirstPerson($firstPerson);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleCamera(%val)
|
||||
{
|
||||
if (%val)
|
||||
{
|
||||
// Since we want the free cam to strafe but the WheeledVehicle
|
||||
// to turn we need to do a little ActionMap wizardry
|
||||
%control = ServerConnection.getControlObject();
|
||||
if (%control.getClassName() $= "Camera")
|
||||
racingMap.push();
|
||||
else
|
||||
racingMap.pop();
|
||||
|
||||
commandToServer('ToggleCamera');
|
||||
}
|
||||
}
|
||||
|
||||
moveMap.bind( keyboard, z, toggleFreeLook );
|
||||
moveMap.bind(keyboard, tab, toggleFirstPerson );
|
||||
moveMap.bind(keyboard, "alt c", toggleCamera);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Misc. Player stuff
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
moveMap.bindCmd(keyboard, "ctrl r", "commandToServer('reset');", "");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Item manipulation
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
moveMap.bindCmd(keyboard, "h", "commandToServer('use',\"HealthKit\");", "");
|
||||
moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"Rifle\");", "");
|
||||
moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"Crossbow\");", "");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Message HUD functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function pageMessageHudUp( %val )
|
||||
{
|
||||
if ( %val )
|
||||
pageUpMessageHud();
|
||||
}
|
||||
|
||||
function pageMessageHudDown( %val )
|
||||
{
|
||||
if ( %val )
|
||||
pageDownMessageHud();
|
||||
}
|
||||
|
||||
function resizeMessageHud( %val )
|
||||
{
|
||||
if ( %val )
|
||||
cycleMessageHudSize();
|
||||
}
|
||||
|
||||
moveMap.bind(keyboard, u, toggleMessageHud );
|
||||
//moveMap.bind(keyboard, y, teamMessageHud );
|
||||
moveMap.bind(keyboard, "pageUp", pageMessageHudUp );
|
||||
moveMap.bind(keyboard, "pageDown", pageMessageHudDown );
|
||||
moveMap.bind(keyboard, "p", resizeMessageHud );
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Demo recording functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function startRecordingDemo( %val )
|
||||
{
|
||||
if ( %val )
|
||||
startDemoRecord();
|
||||
}
|
||||
|
||||
function stopRecordingDemo( %val )
|
||||
{
|
||||
if ( %val )
|
||||
stopDemoRecord();
|
||||
}
|
||||
|
||||
moveMap.bind( keyboard, F3, startRecordingDemo );
|
||||
moveMap.bind( keyboard, F4, stopRecordingDemo );
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helper Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function dropCameraAtPlayer(%val)
|
||||
{
|
||||
if (%val)
|
||||
commandToServer('dropCameraAtPlayer');
|
||||
}
|
||||
|
||||
function dropPlayerAtCamera(%val)
|
||||
{
|
||||
if (%val)
|
||||
commandToServer('DropPlayerAtCamera');
|
||||
}
|
||||
|
||||
moveMap.bind(keyboard, "F8", dropCameraAtPlayer);
|
||||
moveMap.bind(keyboard, "F7", dropPlayerAtCamera);
|
||||
|
||||
function bringUpOptions(%val)
|
||||
{
|
||||
if (%val)
|
||||
Canvas.pushDialog(OptionsDlg);
|
||||
}
|
||||
|
||||
moveMap.bind(keyboard, "ctrl o", bringUpOptions);
|
||||
moveMap.bindCmd(keyboard, "n", "NetGraph::toggleNetGraph();", "");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Dubuging Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
$MFDebugRenderMode = 0;
|
||||
function cycleDebugRenderMode(%val)
|
||||
{
|
||||
if (!%val)
|
||||
return;
|
||||
|
||||
if (getBuildString() $= "Debug")
|
||||
{
|
||||
if($MFDebugRenderMode == 0)
|
||||
{
|
||||
// Outline mode, including fonts so no stats
|
||||
$MFDebugRenderMode = 1;
|
||||
GLEnableOutline(true);
|
||||
}
|
||||
else if ($MFDebugRenderMode == 1)
|
||||
{
|
||||
// Interior debug mode
|
||||
$MFDebugRenderMode = 2;
|
||||
GLEnableOutline(false);
|
||||
setInteriorRenderMode(7);
|
||||
showInterior();
|
||||
}
|
||||
else if ($MFDebugRenderMode == 2)
|
||||
{
|
||||
// Back to normal
|
||||
$MFDebugRenderMode = 0;
|
||||
setInteriorRenderMode(0);
|
||||
GLEnableOutline(false);
|
||||
show();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("Debug render modes only available when running a Debug build.");
|
||||
}
|
||||
}
|
||||
|
||||
GlobalActionMap.bind(keyboard, "F9", cycleDebugRenderMode);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Misc.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
|
||||
GlobalActionMap.bindCmd(keyboard, "alt k", "cls();","");
|
||||
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");
|
||||
GlobalActionMap.bindCmd(keyboard, "F1", "", "contextHelp();");
|
||||
|
46
example/starter.racing/client/scripts/game.cs
Executable file
46
example/starter.racing/client/scripts/game.cs
Executable file
@ -0,0 +1,46 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Game start / end events sent from the server
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function clientCmdSetCounter(%count)
|
||||
{
|
||||
if(%count == 3)
|
||||
counter.setVisible(true);
|
||||
|
||||
counter.setBitmap("starter.racing/client/ui/" @ %count @ ".png");
|
||||
|
||||
alxPlay(AudioCountBeep);
|
||||
}
|
||||
|
||||
function clientCmdGameStart(%seq)
|
||||
{
|
||||
// Display the GO bitmap and play a sound
|
||||
counter.setBitmap("starter.racing/client/ui/go.png");
|
||||
alxPlay(AudioGoBeep);
|
||||
// Remove the GO after a second.
|
||||
counter.schedule(1000, setVisible, false);
|
||||
}
|
||||
|
||||
function clientCmdGameEnd(%seq)
|
||||
{
|
||||
// Stop local activity... the game will be destroyed on the server
|
||||
alxStopAll();
|
||||
|
||||
// Copy the current scores from the player list into the
|
||||
// end game gui (bit of a hack for now).
|
||||
EndGameGuiList.clear();
|
||||
for (%i = 0; %i < PlayerListGuiList.rowCount(); %i++) {
|
||||
%text = PlayerListGuiList.getRowText(%i);
|
||||
%id = PlayerListGuiList.getRowId(%i);
|
||||
EndGameGuiList.addRow(%id,%text);
|
||||
}
|
||||
EndGameGuiList.sortNumerical(1,false);
|
||||
|
||||
// Display the end-game screen
|
||||
Canvas.setContent(EndGameGui);
|
||||
}
|
36
example/starter.racing/client/scripts/loadingGui.cs
Executable file
36
example/starter.racing/client/scripts/loadingGui.cs
Executable file
@ -0,0 +1,36 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function LoadingGui::onAdd(%this)
|
||||
{
|
||||
%this.qLineCount = 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function LoadingGui::onWake(%this)
|
||||
{
|
||||
// Play sound...
|
||||
CloseMessagePopup();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function LoadingGui::onSleep(%this)
|
||||
{
|
||||
// Clear the load info:
|
||||
if ( %this.qLineCount !$= "" )
|
||||
{
|
||||
for ( %line = 0; %line < %this.qLineCount; %line++ )
|
||||
%this.qLine[%line] = "";
|
||||
}
|
||||
%this.qLineCount = 0;
|
||||
|
||||
LOAD_MapName.setText( "" );
|
||||
LOAD_MapDescription.setText( "" );
|
||||
LoadingProgress.setValue( 0 );
|
||||
LoadingProgressTxt.setValue( "WAITING FOR SERVER" );
|
||||
|
||||
// Stop sound...
|
||||
}
|
112
example/starter.racing/client/scripts/messageHud.cs
Executable file
112
example/starter.racing/client/scripts/messageHud.cs
Executable file
@ -0,0 +1,112 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Enter Chat Message Hud
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessageHud::open(%this)
|
||||
{
|
||||
%offset = 6;
|
||||
|
||||
if(%this.isVisible())
|
||||
return;
|
||||
|
||||
if(%this.isTeamMsg)
|
||||
%text = "TEAM:";
|
||||
else
|
||||
%text = "GLOBAL:";
|
||||
|
||||
MessageHud_Text.setValue(%text);
|
||||
|
||||
%windowPos = "0 " @ ( getWord( outerChatHud.position, 1 ) + getWord( outerChatHud.extent, 1 ) + 1 );
|
||||
%windowExt = getWord( OuterChatHud.extent, 0 ) @ " " @ getWord( MessageHud_Frame.extent, 1 );
|
||||
|
||||
%textExtent = getWord(MessageHud_Text.extent, 0) + 14;
|
||||
%ctrlExtent = getWord(MessageHud_Frame.extent, 0);
|
||||
|
||||
Canvas.pushDialog(%this);
|
||||
|
||||
messageHud_Frame.position = %windowPos;
|
||||
messageHud_Frame.extent = %windowExt;
|
||||
MessageHud_Edit.position = setWord(MessageHud_Edit.position, 0, %textExtent + %offset);
|
||||
MessageHud_Edit.extent = setWord(MessageHud_Edit.extent, 0, %ctrlExtent - %textExtent - (2 * %offset));
|
||||
|
||||
%this.setVisible(true);
|
||||
deactivateKeyboard();
|
||||
MessageHud_Edit.makeFirstResponder(true);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessageHud::close(%this)
|
||||
{
|
||||
if(!%this.isVisible())
|
||||
return;
|
||||
|
||||
Canvas.popDialog(%this);
|
||||
%this.setVisible(false);
|
||||
if ( $enableDirectInput )
|
||||
activateKeyboard();
|
||||
MessageHud_Edit.setValue("");
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessageHud::toggleState(%this)
|
||||
{
|
||||
if(%this.isVisible())
|
||||
%this.close();
|
||||
else
|
||||
%this.open();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessageHud_Edit::onEscape(%this)
|
||||
{
|
||||
MessageHud.close();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessageHud_Edit::eval(%this)
|
||||
{
|
||||
%text = trim(%this.getValue());
|
||||
if(%text !$= "")
|
||||
{
|
||||
if(MessageHud.isTeamMsg)
|
||||
commandToServer('teamMessageSent', %text);
|
||||
else
|
||||
commandToServer('messageSent', %text);
|
||||
}
|
||||
|
||||
MessageHud.close();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// MessageHud key handlers
|
||||
|
||||
function toggleMessageHud(%make)
|
||||
{
|
||||
if(%make)
|
||||
{
|
||||
MessageHud.isTeamMsg = false;
|
||||
MessageHud.toggleState();
|
||||
}
|
||||
}
|
||||
|
||||
function teamMessageHud(%make)
|
||||
{
|
||||
if(%make)
|
||||
{
|
||||
MessageHud.isTeamMsg = true;
|
||||
MessageHud.toggleState();
|
||||
}
|
||||
}
|
153
example/starter.racing/client/scripts/missionDownload.cs
Executable file
153
example/starter.racing/client/scripts/missionDownload.cs
Executable file
@ -0,0 +1,153 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Mission Loading & Mission Info
|
||||
// The mission loading server handshaking is handled by the
|
||||
// common/client/missingLoading.cs. This portion handles the interface
|
||||
// with the game GUI.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Loading Phases:
|
||||
// Phase 1: Download Datablocks
|
||||
// Phase 2: Download Ghost Objects
|
||||
// Phase 3: Scene Lighting
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Phase 1
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function onMissionDownloadPhase1(%missionName, %musicTrack)
|
||||
{
|
||||
// Close and clear the message hud (in case it's open)
|
||||
MessageHud.close();
|
||||
//cls();
|
||||
|
||||
// Reset the loading progress controls:
|
||||
LoadingProgress.setValue(0);
|
||||
LoadingProgressTxt.setValue("LOADING DATABLOCKS");
|
||||
}
|
||||
|
||||
function onPhase1Progress(%progress)
|
||||
{
|
||||
LoadingProgress.setValue(%progress);
|
||||
Canvas.repaint();
|
||||
}
|
||||
|
||||
function onPhase1Complete()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Phase 2
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function onMissionDownloadPhase2()
|
||||
{
|
||||
// Reset the loading progress controls:
|
||||
LoadingProgress.setValue(0);
|
||||
LoadingProgressTxt.setValue("LOADING OBJECTS");
|
||||
Canvas.repaint();
|
||||
}
|
||||
|
||||
function onPhase2Progress(%progress)
|
||||
{
|
||||
LoadingProgress.setValue(%progress);
|
||||
Canvas.repaint();
|
||||
}
|
||||
|
||||
function onPhase2Complete()
|
||||
{
|
||||
}
|
||||
|
||||
function onFileChunkReceived(%fileName, %ofs, %size)
|
||||
{
|
||||
LoadingProgress.setValue(%ofs / %size);
|
||||
LoadingProgressTxt.setValue("Downloading " @ %fileName @ "...");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Phase 3
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function onMissionDownloadPhase3()
|
||||
{
|
||||
LoadingProgress.setValue(0);
|
||||
LoadingProgressTxt.setValue("LIGHTING MISSION");
|
||||
Canvas.repaint();
|
||||
}
|
||||
|
||||
function onPhase3Progress(%progress)
|
||||
{
|
||||
LoadingProgress.setValue(%progress);
|
||||
}
|
||||
|
||||
function onPhase3Complete()
|
||||
{
|
||||
LoadingProgress.setValue( 1 );
|
||||
$lightingMission = false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Mission loading done!
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function onMissionDownloadComplete()
|
||||
{
|
||||
// Client will shortly be dropped into the game, so this is
|
||||
// good place for any last minute gui cleanup.
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Before downloading a mission, the server transmits the mission
|
||||
// information through these messages.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
addMessageCallback( 'MsgLoadInfo', handleLoadInfoMessage );
|
||||
addMessageCallback( 'MsgLoadDescripition', handleLoadDescriptionMessage );
|
||||
addMessageCallback( 'MsgLoadInfoDone', handleLoadInfoDoneMessage );
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function handleLoadInfoMessage( %msgType, %msgString, %mapName ) {
|
||||
|
||||
// Need to pop up the loading gui to display this stuff.
|
||||
Canvas.setContent("LoadingGui");
|
||||
|
||||
// Clear all of the loading info lines:
|
||||
for( %line = 0; %line < LoadingGui.qLineCount; %line++ )
|
||||
LoadingGui.qLine[%line] = "";
|
||||
LoadingGui.qLineCount = 0;
|
||||
|
||||
//
|
||||
LOAD_MapName.setText( %mapName );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function handleLoadDescriptionMessage( %msgType, %msgString, %line )
|
||||
{
|
||||
LoadingGui.qLine[LoadingGui.qLineCount] = %line;
|
||||
LoadingGui.qLineCount++;
|
||||
|
||||
// Gather up all the previous lines, append the current one
|
||||
// and stuff it into the control
|
||||
%text = "<spush><font:Arial:16>";
|
||||
|
||||
for( %line = 0; %line < LoadingGui.qLineCount - 1; %line++ )
|
||||
%text = %text @ LoadingGui.qLine[%line] @ " ";
|
||||
%text = %text @ LoadingGui.qLine[%line] @ "<spop>";
|
||||
|
||||
LOAD_MapDescription.setText( %text );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function handleLoadInfoDoneMessage( %msgType, %msgString )
|
||||
{
|
||||
// This will get called after the last description line is sent.
|
||||
}
|
603
example/starter.racing/client/scripts/optionsDlg.cs
Executable file
603
example/starter.racing/client/scripts/optionsDlg.cs
Executable file
@ -0,0 +1,603 @@
|
||||
function optionsDlg::setPane(%this, %pane)
|
||||
{
|
||||
OptAudioPane.setVisible(false);
|
||||
OptGraphicsPane.setVisible(false);
|
||||
OptNetworkPane.setVisible(false);
|
||||
OptControlsPane.setVisible(false);
|
||||
("Opt" @ %pane @ "Pane").setVisible(true);
|
||||
OptRemapList.fillList();
|
||||
}
|
||||
|
||||
function OptionsDlg::onWake(%this)
|
||||
{
|
||||
OptGraphicsButton.performClick();
|
||||
%buffer = getDisplayDeviceList();
|
||||
%count = getFieldCount( %buffer );
|
||||
OptGraphicsDriverMenu.clear();
|
||||
OptScreenshotMenu.init();
|
||||
OptScreenshotMenu.setValue($pref::Video::screenShotFormat);
|
||||
for(%i = 0; %i < %count; %i++)
|
||||
OptGraphicsDriverMenu.add(getField(%buffer, %i), %i);
|
||||
%selId = OptGraphicsDriverMenu.findText( $pref::Video::displayDevice );
|
||||
if ( %selId == -1 )
|
||||
%selId = 0; // How did THAT happen?
|
||||
OptGraphicsDriverMenu.setSelected( %selId );
|
||||
OptGraphicsDriverMenu.onSelect( %selId, "" );
|
||||
|
||||
// Audio
|
||||
OptAudioUpdate();
|
||||
OptAudioVolumeMaster.setValue($pref::Audio::masterVolume);
|
||||
OptAudioVolumeShell.setValue( $pref::Audio::channelVolume[$GuiAudioType]);
|
||||
OptAudioVolumeSim.setValue( $pref::Audio::channelVolume[$SimAudioType]);
|
||||
OptAudioDriverList.clear();
|
||||
OptAudioDriverList.add("OpenAL", 1);
|
||||
OptAudioDriverList.add("none", 2);
|
||||
%selId = OptAudioDriverList.findText($pref::Audio::driver);
|
||||
if ( %selId == -1 )
|
||||
%selId = 0; // How did THAT happen?
|
||||
OptAudioDriverList.setSelected( %selId );
|
||||
OptAudioDriverList.onSelect( %selId, "" );
|
||||
}
|
||||
|
||||
function OptionsDlg::onSleep(%this)
|
||||
{
|
||||
// write out the control config into the rw/config.cs file
|
||||
moveMap.save( "./client/config.cs" );
|
||||
}
|
||||
|
||||
function OptGraphicsDriverMenu::onSelect( %this, %id, %text )
|
||||
{
|
||||
// Attempt to keep the same res and bpp settings:
|
||||
if ( OptGraphicsResolutionMenu.size() > 0 )
|
||||
%prevRes = OptGraphicsResolutionMenu.getText();
|
||||
else
|
||||
%prevRes = getWords( $pref::Video::resolution, 0, 1 );
|
||||
|
||||
// Check if this device is full-screen only:
|
||||
if ( isDeviceFullScreenOnly( %this.getText() ) )
|
||||
{
|
||||
OptGraphicsFullscreenToggle.setValue( true );
|
||||
OptGraphicsFullscreenToggle.setActive( false );
|
||||
OptGraphicsFullscreenToggle.onAction();
|
||||
}
|
||||
else
|
||||
OptGraphicsFullscreenToggle.setActive( true );
|
||||
|
||||
if ( OptGraphicsFullscreenToggle.getValue() )
|
||||
{
|
||||
if ( OptGraphicsBPPMenu.size() > 0 )
|
||||
%prevBPP = OptGraphicsBPPMenu.getText();
|
||||
else
|
||||
%prevBPP = getWord( $pref::Video::resolution, 2 );
|
||||
}
|
||||
|
||||
// Fill the resolution and bit depth lists:
|
||||
OptGraphicsResolutionMenu.init( %this.getText(), OptGraphicsFullscreenToggle.getValue() );
|
||||
OptGraphicsBPPMenu.init( %this.getText() );
|
||||
|
||||
// Try to select the previous settings:
|
||||
%selId = OptGraphicsResolutionMenu.findText( %prevRes );
|
||||
if ( %selId == -1 )
|
||||
%selId = 0;
|
||||
OptGraphicsResolutionMenu.setSelected( %selId );
|
||||
|
||||
if ( OptGraphicsFullscreenToggle.getValue() )
|
||||
{
|
||||
%selId = OptGraphicsBPPMenu.findText( %prevBPP );
|
||||
if ( %selId == -1 )
|
||||
%selId = 0;
|
||||
OptGraphicsBPPMenu.setSelected( %selId );
|
||||
OptGraphicsBPPMenu.setText( OptGraphicsBPPMenu.getTextById( %selId ) );
|
||||
}
|
||||
else
|
||||
OptGraphicsBPPMenu.setText( "Default" );
|
||||
|
||||
}
|
||||
|
||||
function OptGraphicsResolutionMenu::init( %this, %device, %fullScreen )
|
||||
{
|
||||
%this.clear();
|
||||
%resList = getResolutionList( %device );
|
||||
%resCount = getFieldCount( %resList );
|
||||
%deskRes = getDesktopResolution();
|
||||
|
||||
%count = 0;
|
||||
for ( %i = 0; %i < %resCount; %i++ )
|
||||
{
|
||||
%res = getWords( getField( %resList, %i ), 0, 1 );
|
||||
|
||||
if ( !%fullScreen )
|
||||
{
|
||||
if ( firstWord( %res ) >= firstWord( %deskRes ) )
|
||||
continue;
|
||||
if ( getWord( %res, 1 ) >= getWord( %deskRes, 1 ) )
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only add to list if it isn't there already:
|
||||
if ( %this.findText( %res ) == -1 )
|
||||
{
|
||||
%this.add( %res, %count );
|
||||
%count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function OptGraphicsFullscreenToggle::onAction(%this)
|
||||
{
|
||||
Parent::onAction();
|
||||
%prevRes = OptGraphicsResolutionMenu.getText();
|
||||
|
||||
// Update the resolution menu with the new options
|
||||
OptGraphicsResolutionMenu.init( OptGraphicsDriverMenu.getText(), %this.getValue() );
|
||||
|
||||
// Set it back to the previous resolution if the new mode supports it.
|
||||
%selId = OptGraphicsResolutionMenu.findText( %prevRes );
|
||||
if ( %selId == -1 )
|
||||
%selId = 0;
|
||||
OptGraphicsResolutionMenu.setSelected( %selId );
|
||||
}
|
||||
|
||||
|
||||
function OptGraphicsBPPMenu::init( %this, %device )
|
||||
{
|
||||
%this.clear();
|
||||
|
||||
if ( %device $= "Voodoo2" )
|
||||
%this.add( "16", 0 );
|
||||
else
|
||||
{
|
||||
%resList = getResolutionList( %device );
|
||||
%resCount = getFieldCount( %resList );
|
||||
%count = 0;
|
||||
for ( %i = 0; %i < %resCount; %i++ )
|
||||
{
|
||||
%bpp = getWord( getField( %resList, %i ), 2 );
|
||||
|
||||
// Only add to list if it isn't there already:
|
||||
if ( %this.findText( %bpp ) == -1 )
|
||||
{
|
||||
%this.add( %bpp, %count );
|
||||
%count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function OptScreenshotMenu::init( %this )
|
||||
{
|
||||
if( %this.findText("PNG") == -1 )
|
||||
%this.add("PNG", 0);
|
||||
if( %this.findText("JPEG") == - 1 )
|
||||
%this.add("JPEG", 1);
|
||||
}
|
||||
|
||||
function optionsDlg::applyGraphics( %this )
|
||||
{
|
||||
%newDriver = OptGraphicsDriverMenu.getText();
|
||||
%newRes = OptGraphicsResolutionMenu.getText();
|
||||
%newBpp = OptGraphicsBPPMenu.getText();
|
||||
%newFullScreen = OptGraphicsFullscreenToggle.getValue();
|
||||
$pref::Video::screenShotFormat = OptScreenshotMenu.getText();
|
||||
|
||||
if ( %newDriver !$= $pref::Video::displayDevice )
|
||||
{
|
||||
setDisplayDevice( %newDriver, firstWord( %newRes ), getWord( %newRes, 1 ), %newBpp, %newFullScreen );
|
||||
//OptionsDlg::deviceDependent( %this );
|
||||
}
|
||||
else
|
||||
setScreenMode( firstWord( %newRes ), getWord( %newRes, 1 ), %newBpp, %newFullScreen );
|
||||
}
|
||||
|
||||
|
||||
|
||||
$RemapCount = 0;
|
||||
$RemapName[$RemapCount] = "Accelerate";
|
||||
$RemapCmd[$RemapCount] = "accelerate";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Brake/Reverse";
|
||||
$RemapCmd[$RemapCount] = "brake";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Turn Left";
|
||||
$RemapCmd[$RemapCount] = "turnLeft";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Turn Right";
|
||||
$RemapCmd[$RemapCount] = "turnRight";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Hand brake";
|
||||
$RemapCmd[$RemapCount] = "handbrake";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Adjust Zoom";
|
||||
$RemapCmd[$RemapCount] = "setZoomFov";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Toggle Zoom";
|
||||
$RemapCmd[$RemapCount] = "toggleZoom";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Free Look";
|
||||
$RemapCmd[$RemapCount] = "toggleFreeLook";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Switch 1st/3rd";
|
||||
$RemapCmd[$RemapCount] = "toggleFirstPerson";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Chat to Everyone";
|
||||
$RemapCmd[$RemapCount] = "toggleMessageHud";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Message Hud PageUp";
|
||||
$RemapCmd[$RemapCount] = "pageMessageHudUp";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Message Hud PageDown";
|
||||
$RemapCmd[$RemapCount] = "pageMessageHudDown";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Resize Message Hud";
|
||||
$RemapCmd[$RemapCount] = "resizeMessageHud";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Show Scores";
|
||||
$RemapCmd[$RemapCount] = "showPlayerList";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Reset car";
|
||||
$RemapCmd[$RemapCount] = "reset";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Toggle Camera";
|
||||
$RemapCmd[$RemapCount] = "toggleCamera";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Drop Camera at Player";
|
||||
$RemapCmd[$RemapCount] = "dropCameraAtPlayer";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Drop Player at Camera";
|
||||
$RemapCmd[$RemapCount] = "dropPlayerAtCamera";
|
||||
$RemapCount++;
|
||||
$RemapName[$RemapCount] = "Bring up Options Dialog";
|
||||
$RemapCmd[$RemapCount] = "bringUpOptions";
|
||||
$RemapCount++;
|
||||
|
||||
|
||||
function restoreDefaultMappings()
|
||||
{
|
||||
moveMap.delete();
|
||||
exec( "~/scripts/default.bind.cs" );
|
||||
OptRemapList.fillList();
|
||||
}
|
||||
|
||||
function getMapDisplayName( %device, %action )
|
||||
{
|
||||
if ( %device $= "keyboard" )
|
||||
return( %action );
|
||||
else if ( strstr( %device, "mouse" ) != -1 )
|
||||
{
|
||||
// Substitute "mouse" for "button" in the action string:
|
||||
%pos = strstr( %action, "button" );
|
||||
if ( %pos != -1 )
|
||||
{
|
||||
%mods = getSubStr( %action, 0, %pos );
|
||||
%object = getSubStr( %action, %pos, 1000 );
|
||||
%instance = getSubStr( %object, strlen( "button" ), 1000 );
|
||||
return( %mods @ "mouse" @ ( %instance + 1 ) );
|
||||
}
|
||||
else
|
||||
error( "Mouse input object other than button passed to getDisplayMapName!" );
|
||||
}
|
||||
else if ( strstr( %device, "joystick" ) != -1 )
|
||||
{
|
||||
// Substitute "joystick" for "button" in the action string:
|
||||
%pos = strstr( %action, "button" );
|
||||
if ( %pos != -1 )
|
||||
{
|
||||
%mods = getSubStr( %action, 0, %pos );
|
||||
%object = getSubStr( %action, %pos, 1000 );
|
||||
%instance = getSubStr( %object, strlen( "button" ), 1000 );
|
||||
return( %mods @ "joystick" @ ( %instance + 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
%pos = strstr( %action, "pov" );
|
||||
if ( %pos != -1 )
|
||||
{
|
||||
%wordCount = getWordCount( %action );
|
||||
%mods = %wordCount > 1 ? getWords( %action, 0, %wordCount - 2 ) @ " " : "";
|
||||
%object = getWord( %action, %wordCount - 1 );
|
||||
switch$ ( %object )
|
||||
{
|
||||
case "upov": %object = "POV1 up";
|
||||
case "dpov": %object = "POV1 down";
|
||||
case "lpov": %object = "POV1 left";
|
||||
case "rpov": %object = "POV1 right";
|
||||
case "upov2": %object = "POV2 up";
|
||||
case "dpov2": %object = "POV2 down";
|
||||
case "lpov2": %object = "POV2 left";
|
||||
case "rpov2": %object = "POV2 right";
|
||||
default: %object = "??";
|
||||
}
|
||||
return( %mods @ %object );
|
||||
}
|
||||
else
|
||||
error( "Unsupported Joystick input object passed to getDisplayMapName!" );
|
||||
}
|
||||
}
|
||||
|
||||
return( "??" );
|
||||
}
|
||||
|
||||
function buildFullMapString( %index )
|
||||
{
|
||||
%name = $RemapName[%index];
|
||||
%cmd = $RemapCmd[%index];
|
||||
|
||||
%temp = moveMap.getBinding( %cmd );
|
||||
if ( %temp $= "" )
|
||||
return %name TAB "";
|
||||
|
||||
%mapString = "";
|
||||
|
||||
%count = getFieldCount( %temp );
|
||||
for ( %i = 0; %i < %count; %i += 2 )
|
||||
{
|
||||
if ( %mapString !$= "" )
|
||||
%mapString = %mapString @ ", ";
|
||||
|
||||
%device = getField( %temp, %i + 0 );
|
||||
%object = getField( %temp, %i + 1 );
|
||||
%mapString = %mapString @ getMapDisplayName( %device, %object );
|
||||
}
|
||||
|
||||
return %name TAB %mapString;
|
||||
}
|
||||
|
||||
function OptRemapList::fillList( %this )
|
||||
{
|
||||
%this.clear();
|
||||
for ( %i = 0; %i < $RemapCount; %i++ )
|
||||
%this.addRow( %i, buildFullMapString( %i ) );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function OptRemapList::doRemap( %this )
|
||||
{
|
||||
%selId = %this.getSelectedId();
|
||||
%name = $RemapName[%selId];
|
||||
|
||||
OptRemapText.setValue( "REMAP \"" @ %name @ "\"" );
|
||||
OptRemapInputCtrl.index = %selId;
|
||||
Canvas.pushDialog( RemapDlg );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function redoMapping( %device, %action, %cmd, %oldIndex, %newIndex )
|
||||
{
|
||||
//%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
|
||||
moveMap.bind( %device, %action, %cmd );
|
||||
OptRemapList.setRowById( %oldIndex, buildFullMapString( %oldIndex ) );
|
||||
OptRemapList.setRowById( %newIndex, buildFullMapString( %newIndex ) );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function findRemapCmdIndex( %command )
|
||||
{
|
||||
for ( %i = 0; %i < $RemapCount; %i++ )
|
||||
{
|
||||
if ( %command $= $RemapCmd[%i] )
|
||||
return( %i );
|
||||
}
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/// This unbinds actions beyond %count associated to the
|
||||
/// particular moveMap %commmand.
|
||||
function unbindExtraActions( %command, %count )
|
||||
{
|
||||
%temp = moveMap.getBinding( %command );
|
||||
if ( %temp $= "" )
|
||||
return;
|
||||
|
||||
%count = getFieldCount( %temp ) - ( %count * 2 );
|
||||
for ( %i = 0; %i < %count; %i += 2 )
|
||||
{
|
||||
%device = getField( %temp, %i + 0 );
|
||||
%action = getField( %temp, %i + 1 );
|
||||
|
||||
moveMap.unbind( %device, %action );
|
||||
}
|
||||
}
|
||||
|
||||
function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
|
||||
{
|
||||
//error( "** onInputEvent called - device = " @ %device @ ", action = " @ %action @ " **" );
|
||||
Canvas.popDialog( RemapDlg );
|
||||
|
||||
// Test for the reserved keystrokes:
|
||||
if ( %device $= "keyboard" )
|
||||
{
|
||||
// Cancel...
|
||||
if ( %action $= "escape" )
|
||||
{
|
||||
// Do nothing...
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
%cmd = $RemapCmd[%this.index];
|
||||
%name = $RemapName[%this.index];
|
||||
|
||||
// Grab the friendly display name for this action
|
||||
// which we'll use when prompting the user below.
|
||||
%mapName = getMapDisplayName( %device, %action );
|
||||
|
||||
// Get the current command this action is mapped to.
|
||||
%prevMap = moveMap.getCommand( %device, %action );
|
||||
|
||||
// If nothing was mapped to the previous command
|
||||
// mapping then it's easy... just bind it.
|
||||
if ( %prevMap $= "" )
|
||||
{
|
||||
unbindExtraActions( %cmd, 1 );
|
||||
moveMap.bind( %device, %action, %cmd );
|
||||
OptRemapList.setRowById( %this.index, buildFullMapString( %this.index ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// If the previous command is the same as the
|
||||
// current then they hit the same input as what
|
||||
// was already assigned.
|
||||
if ( %prevMap $= %cmd )
|
||||
{
|
||||
unbindExtraActions( %cmd, 0 );
|
||||
moveMap.bind( %device, %action, %cmd );
|
||||
OptRemapList.setRowById( %this.index, buildFullMapString( %this.index ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for the index of the previous mapping.
|
||||
%prevMapIndex = findRemapCmdIndex( %prevMap );
|
||||
|
||||
// If we get a negative index then the previous
|
||||
// mapping was to an item that isn't included in
|
||||
// the mapping list... so we cannot unmap it.
|
||||
if ( %prevMapIndex == -1 )
|
||||
{
|
||||
MessageBoxOK( "Remap Failed", "\"" @ %mapName @ "\" is already bound to a non-remappable command!" );
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup the forced remapping callback command.
|
||||
%callback = "redoMapping(" @ %device @ ", \"" @ %action @ "\", \"" @
|
||||
%cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
|
||||
|
||||
// Warn that we're about to remove the old mapping and
|
||||
// replace it with another.
|
||||
%prevCmdName = $RemapName[%prevMapIndex];
|
||||
MessageBoxYesNo( "Warning",
|
||||
"\"" @ %mapName @ "\" is already bound to \""
|
||||
@ %prevCmdName @ "\"!\nDo you wish to replace this mapping?",
|
||||
%callback, "" );
|
||||
}
|
||||
|
||||
// Audio
|
||||
function OptAudioUpdate()
|
||||
{
|
||||
// set the driver text
|
||||
%text = "Vendor: " @ alGetString("AL_VENDOR") @
|
||||
"\nVersion: " @ alGetString("AL_VERSION") @
|
||||
"\nRenderer: " @ alGetString("AL_RENDERER") @
|
||||
"\nExtensions: " @ alGetString("AL_EXTENSIONS");
|
||||
OptAudioInfo.setText(%text);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Channel 0 is unused in-game, but is used here to test master volume.
|
||||
|
||||
new AudioDescription(AudioChannel0)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 0;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel1)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 1;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel2)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 2;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel3)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 3;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel4)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 4;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel5)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 5;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel6)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 6;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel7)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 7;
|
||||
};
|
||||
|
||||
new AudioDescription(AudioChannel8)
|
||||
{
|
||||
volume = 1.0;
|
||||
isLooping= false;
|
||||
is3D = false;
|
||||
type = 8;
|
||||
};
|
||||
|
||||
$AudioTestHandle = 0;
|
||||
|
||||
function OptAudioUpdateMasterVolume(%volume)
|
||||
{
|
||||
if (%volume == $pref::Audio::masterVolume)
|
||||
return;
|
||||
alxListenerf(AL_GAIN_LINEAR, %volume);
|
||||
$pref::Audio::masterVolume = %volume;
|
||||
if (!alxIsPlaying($AudioTestHandle))
|
||||
{
|
||||
$AudioTestHandle = alxCreateSource("AudioChannel0", expandFilename("~/data/sound/testing.wav"));
|
||||
alxPlay($AudioTestHandle);
|
||||
}
|
||||
}
|
||||
|
||||
function OptAudioUpdateChannelVolume(%channel, %volume)
|
||||
{
|
||||
if (%channel < 1 || %channel > 8)
|
||||
return;
|
||||
|
||||
if (%volume == $pref::Audio::channelVolume[%channel])
|
||||
return;
|
||||
|
||||
alxSetChannelVolume(%channel, %volume);
|
||||
$pref::Audio::channelVolume[%channel] = %volume;
|
||||
if (!alxIsPlaying($AudioTestHandle))
|
||||
{
|
||||
$AudioTestHandle = alxCreateSource("AudioChannel"@%channel, expandFilename("~/data/sound/testing.wav"));
|
||||
alxPlay($AudioTestHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function OptAudioDriverList::onSelect( %this, %id, %text )
|
||||
{
|
||||
if (%text $= "")
|
||||
return;
|
||||
|
||||
if ($pref::Audio::driver $= %text)
|
||||
return;
|
||||
|
||||
$pref::Audio::driver = %text;
|
||||
OpenALInit();
|
||||
}
|
74
example/starter.racing/client/scripts/playGui.cs
Executable file
74
example/starter.racing/client/scripts/playGui.cs
Executable file
@ -0,0 +1,74 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PlayGui is the main TSControl through which the game is viewed.
|
||||
// The PlayGui also contains the hud controls.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function PlayGui::onWake(%this)
|
||||
{
|
||||
// Turn off any shell sounds...
|
||||
// alxStop( ... );
|
||||
|
||||
$enableDirectInput = "1";
|
||||
activateDirectInput();
|
||||
|
||||
// Message hud dialog
|
||||
Canvas.pushDialog( MainChatHud );
|
||||
chatHud.attach(HudMessageVector);
|
||||
|
||||
// just update the action map here
|
||||
moveMap.push();
|
||||
racingMap.push();
|
||||
|
||||
// hack city - these controls are floating around and need to be clamped
|
||||
schedule(0, 0, "refreshCenterTextCtrl");
|
||||
schedule(0, 0, "refreshBottomTextCtrl");
|
||||
}
|
||||
|
||||
function PlayGui::onSleep(%this)
|
||||
{
|
||||
Canvas.popDialog( MainChatHud );
|
||||
|
||||
// pop the keymaps
|
||||
moveMap.pop();
|
||||
racingMap.pop();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
function PlayGui::updateLapCounter(%this)
|
||||
{
|
||||
LapCounter.setText("Lap" SPC %this.lap SPC "/" SPC %this.maxLaps);
|
||||
}
|
||||
|
||||
function clientCmdSetMaxLaps(%laps)
|
||||
{
|
||||
// Reset the current lap to 1 and set the max laps.
|
||||
PlayGui.lap = 1;
|
||||
PlayGui.maxLaps = %laps;
|
||||
PlayGui.updateLapCounter();
|
||||
}
|
||||
|
||||
function clientCmdIncreaseLapCounter()
|
||||
{
|
||||
// Increase the lap.
|
||||
PlayGui.lap++;
|
||||
PlayGui.updateLapCounter();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function refreshBottomTextCtrl()
|
||||
{
|
||||
BottomPrintText.position = "0 0";
|
||||
}
|
||||
|
||||
function refreshCenterTextCtrl()
|
||||
{
|
||||
CenterPrintText.position = "0 0";
|
||||
}
|
||||
|
||||
|
32
example/starter.racing/client/scripts/playerList.cs
Executable file
32
example/starter.racing/client/scripts/playerList.cs
Executable file
@ -0,0 +1,32 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into the client update messages to maintain our player list
|
||||
// and scoreboard.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
addMessageCallback('MsgClientJoin', handleClientJoin);
|
||||
addMessageCallback('MsgClientDrop', handleClientDrop);
|
||||
addMessageCallback('MsgClientScoreChanged', handleClientScoreChanged);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function handleClientJoin(%msgType, %msgString, %clientName, %clientId,
|
||||
%guid, %score, %isAI, %isAdmin, %isSuperAdmin )
|
||||
{
|
||||
PlayerListGui.update(%clientId,detag(%clientName),%isSuperAdmin,
|
||||
%isAdmin,%isAI,%score);
|
||||
}
|
||||
|
||||
function handleClientDrop(%msgType, %msgString, %clientName, %clientId)
|
||||
{
|
||||
PlayerListGui.remove(%clientId);
|
||||
}
|
||||
|
||||
function handleClientScoreChanged(%msgType, %msgString, %score, %clientId)
|
||||
{
|
||||
PlayerListGui.updateScore(%clientId,%score);
|
||||
}
|
166
example/starter.racing/client/scripts/serverConnection.cs
Executable file
166
example/starter.racing/client/scripts/serverConnection.cs
Executable file
@ -0,0 +1,166 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Functions dealing with connecting to a server
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Server connection error
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
addMessageCallback( 'MsgConnectionError', handleConnectionErrorMessage );
|
||||
|
||||
function handleConnectionErrorMessage(%msgType, %msgString, %msgError)
|
||||
{
|
||||
// On connect the server transmits a message to display if there
|
||||
// are any problems with the connection. Most connection errors
|
||||
// are game version differences, so hopefully the server message
|
||||
// will tell us where to get the latest version of the game.
|
||||
$ServerConnectionErrorMessage = %msgError;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// GameConnection client callbacks
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function GameConnection::initialControlSet(%this)
|
||||
{
|
||||
echo ("*** Initial Control Object");
|
||||
|
||||
// The first control object has been set by the server
|
||||
// and we are now ready to go.
|
||||
|
||||
// first check if the editor is active
|
||||
if (!Editor::checkActiveLoadDone())
|
||||
{
|
||||
if (Canvas.getContent() != PlayGui.getId())
|
||||
Canvas.setContent(PlayGui);
|
||||
}
|
||||
}
|
||||
|
||||
function GameConnection::setLagIcon(%this, %state)
|
||||
{
|
||||
if (%this.getAddress() $= "local")
|
||||
return;
|
||||
LagIcon.setVisible(%state $= "true");
|
||||
}
|
||||
|
||||
function GameConnection::onConnectionAccepted(%this)
|
||||
{
|
||||
// Called on the new connection object after connect() succeeds.
|
||||
LagIcon.setVisible(false);
|
||||
}
|
||||
|
||||
function GameConnection::onConnectionTimedOut(%this)
|
||||
{
|
||||
// Called when an established connection times out
|
||||
disconnectedCleanup();
|
||||
MessageBoxOK( "TIMED OUT", "The server connection has timed out.");
|
||||
}
|
||||
|
||||
function GameConnection::onConnectionDropped(%this, %msg)
|
||||
{
|
||||
// Established connection was dropped by the server
|
||||
disconnectedCleanup();
|
||||
MessageBoxOK( "DISCONNECT", "The server has dropped the connection: " @ %msg);
|
||||
}
|
||||
|
||||
function GameConnection::onConnectionError(%this, %msg)
|
||||
{
|
||||
// General connection error, usually raised by ghosted objects
|
||||
// initialization problems, such as missing files. We'll display
|
||||
// the server's connection error message.
|
||||
disconnectedCleanup();
|
||||
MessageBoxOK( "DISCONNECT", $ServerConnectionErrorMessage @ " (" @ %msg @ ")" );
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Connection Failed Events
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function GameConnection::onConnectRequestRejected( %this, %msg )
|
||||
{
|
||||
switch$(%msg)
|
||||
{
|
||||
case "CR_INVALID_PROTOCOL_VERSION":
|
||||
%error = "Incompatible protocol version: Your game version is not compatible with this server.";
|
||||
case "CR_INVALID_CONNECT_PACKET":
|
||||
%error = "Internal Error: badly formed network packet";
|
||||
case "CR_YOUAREBANNED":
|
||||
%error = "You are not allowed to play on this server.";
|
||||
case "CR_SERVERFULL":
|
||||
%error = "This server is full.";
|
||||
case "CHR_PASSWORD":
|
||||
// XXX Should put up a password-entry dialog.
|
||||
if ($Client::Password $= "")
|
||||
MessageBoxOK( "REJECTED", "That server requires a password.");
|
||||
else {
|
||||
$Client::Password = "";
|
||||
MessageBoxOK( "REJECTED", "That password is incorrect.");
|
||||
}
|
||||
return;
|
||||
case "CHR_PROTOCOL":
|
||||
%error = "Incompatible protocol version: Your game version is not compatible with this server.";
|
||||
case "CHR_CLASSCRC":
|
||||
%error = "Incompatible game classes: Your game version is not compatible with this server.";
|
||||
case "CHR_INVALID_CHALLENGE_PACKET":
|
||||
%error = "Internal Error: Invalid server response packet";
|
||||
default:
|
||||
%error = "Connection error. Please try another server. Error code: (" @ %msg @ ")";
|
||||
}
|
||||
disconnectedCleanup();
|
||||
MessageBoxOK( "REJECTED", %error);
|
||||
}
|
||||
|
||||
function GameConnection::onConnectRequestTimedOut(%this)
|
||||
{
|
||||
disconnectedCleanup();
|
||||
MessageBoxOK( "TIMED OUT", "Your connection to the server timed out." );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Disconnect
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function disconnect()
|
||||
{
|
||||
// Delete the connection if it's still there.
|
||||
if (isObject(ServerConnection))
|
||||
ServerConnection.delete();
|
||||
disconnectedCleanup();
|
||||
|
||||
// Call destroyServer in case we're hosting
|
||||
destroyServer();
|
||||
}
|
||||
|
||||
function disconnectedCleanup()
|
||||
{
|
||||
// Clear misc script stuff
|
||||
HudMessageVector.clear();
|
||||
|
||||
// Terminate all playing sounds
|
||||
alxStopAll();
|
||||
if (isObject(MusicPlayer))
|
||||
MusicPlayer.stop();
|
||||
|
||||
//
|
||||
LagIcon.setVisible(false);
|
||||
PlayerListGui.clear();
|
||||
|
||||
// Clear all print messages
|
||||
clientCmdclearBottomPrint();
|
||||
clientCmdClearCenterPrint();
|
||||
|
||||
// Back to the launch screen
|
||||
Canvas.setContent(MainMenuGui);
|
||||
|
||||
// Dump anything we're not using
|
||||
clearTextureHolds();
|
||||
purgeResources();
|
||||
}
|
||||
|
Reference in New Issue
Block a user