KevinBlast/marble/client/scripts/playgui.cs

262 lines
6.2 KiB
C#
Raw Normal View History

2024-03-10 20:27:00 -04:00
//-----------------------------------------------------------------------------
// Torque Game Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, 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);
// Make sure the display is up to date
%this.setGemCount(%this.gemCount);
%this.setMaxGems(%this.maxGems);
%this.timerInc = 50;
// just update the action map here
if($playingDemo)
demoMap.push();
else
moveMap.push();
// hack city - these controls are floating around and need to be clamped
schedule(0, 0, "refreshCenterTextCtrl");
schedule(0, 0, "refreshBottomTextCtrl");
playGameMusic();
}
function PlayGui::onSleep(%this)
{
Canvas.popDialog(MainChatHud);
// Terminate all playing sounds
alxStopAll();
playShellMusic();
// pop the keymaps
moveMap.pop();
demoMap.pop();
}
//-----------------------------------------------------------------------------
function PlayGui::setMessage(%this,%bitmap,%timer)
{
// Set the center message bitmap
if (%bitmap !$= "") {
CenterMessageDlg.setBitmap($Con::Root @ "/client/ui/game/" @ %bitmap @ ".png",true);
CenterMessageDlg.setVisible(true);
cancel(CenterMessageDlg.timer);
if (%timer)
CenterMessageDlg.timer = CenterMessageDlg.schedule(%timer,"setVisible",false);
}
else
CenterMessageDlg.setVisible(false);
}
//-----------------------------------------------------------------------------
function PlayGui::setPowerUp(%this,%shapeFile)
{
// Update the power up hud control
if (%shapeFile $= "")
HUD_ShowPowerUp.setEmpty();
else
HUD_ShowPowerUp.setModel(%shapeFile, "");
}
//-----------------------------------------------------------------------------
function PlayGui::setMaxGems(%this,%count)
{
%this.maxGems = %count;
%one = %count % 10;
%ten = ((%count - %one) / 10) % 10;
%hun = ((%count - %one) / 100) % 12;
GemsTotalHun.setNumber(%hun);
GemsTotalTen.setNumber(%ten);
GemsTotalOne.setNumber(%one);
%visible = %count != 0;
HUD_ShowGem.setVisible(%visible);
GemsFoundHun.setVisible(%visible);
GemsFoundTen.setVisible(%visible);
GemsFoundOne.setVisible(%visible);
GemsSlash.setVisible(%visible);
GemsTotalHun.setVisible(%visible);
GemsTotalTen.setVisible(%visible);
GemsTotalOne.setVisible(%visible);
HUD_ShowGem.setModel("marble/data/shapes/items/gem.dts","");
}
function PlayGui::setGemCount(%this,%count)
{
%this.gemCount = %count;
%one = %count % 10;
%ten = ((%count - %one) / 10) % 10;
%hun = ((%count - %one) / 100) % 12;
GemsFoundHun.setNumber(%hun);
GemsFoundTen.setNumber(%ten);
GemsFoundOne.setNumber(%one);
}
//-----------------------------------------------------------------------------
// Elapsed Timer Display
function PlayGui::setTime(%this,%dt)
{
%this.elapsedTime = %dt;
%this.updateControls();
}
function PlayGui::resetTimer(%this,%dt)
{
%this.elapsedTime = 0;
%this.bonusTime = 0;
%this.totalBonus = 0;
if($BonusSfx !$= "")
{
alxStop($BonusSfx);
$BonusSfx = "";
}
%this.updateControls();
%this.stopTimer();
}
function PlayGui::adjustTimer(%this,%dt)
{
%this.elapsedTime += %dt;
%this.updateControls();
}
function PlayGui::addBonusTime(%this, %dt)
{
%this.bonusTime += %dt;
if($BonusSfx $= "")
$BonusSfx = alxPlay(TimeTravelLoopSfx);
}
function PlayGui::startTimer(%this)
{
$PlayTimerActive = true;
}
function onFrameAdvance(%timeDelta)
{
if($PlayTimerActive)
PlayGui.updateTimer(%timeDelta);
}
function PlayGui::stopTimer(%this)
{
$PlayTimerActive = false;
if($BonusSfx !$= "")
{
alxStop($BonusSfx);
$BonusSfx = "";
}
}
function PlayGui::updateTimer(%this, %timeInc)
{
if(%this.bonusTime)
{
if(%this.bonusTime > %timeInc)
{
%this.bonusTime -= %timeInc;
%this.totalBonus += %timeInc;
%timeInc = 0;
}
else
{
%timeInc -= %this.bonusTime;
%this.totalBonus += %this.bonusTime;
%this.bonusTime = 0;
alxStop($BonusSfx);
$BonusSfx = "";
}
}
%this.elapsedTime += %timeInc;
// Some sanity checking
if (%this.elapsedTime > 3600000)
%this.elapsedTime = 3599999;
%this.updateControls();
}
function PlayGui::updateControls(%this)
{
%et = %this.elapsedTime;
%drawNeg = false;
if(%et < 0)
{
%et = - %et;
%drawNeg = true;
}
%thousandth = mFloor(%et % 1000);
2024-03-10 20:27:00 -04:00
%totalSeconds = mFloor(%et / 1000);
%seconds = %totalSeconds % 60;
%minutes = %totalSeconds / 60;
2024-03-10 20:27:00 -04:00
%secondsOne = mFloor(%seconds % 10);
%secondsTen = mFloor(%seconds / 10);
%minutesOne = mFloor(%minutes % 10);
%minutesTen = mFloor(%minutes / 10);
%thousandthOne = mFloor(%thousandth % 10);
%thousandthTen = mFloor(%thousandth / 10) % 10;
%thousandthHundred = mFloor(%thousandth / 100);
2024-03-10 20:27:00 -04:00
// Update the controls
Min_Ten.setNumber(%minutesTen);
Min_One.setNumber(%minutesOne);
Sec_Ten.setNumber(%secondsTen);
Sec_One.setNumber(%secondsOne);
Sec_Tenth.setNumber(%thousandthHundred);
Sec_Hundredth.setNumber(%thousandthTen);
Sec_Thousandth.setNumber(%thousandthOne);
2024-03-10 20:27:00 -04:00
PG_NegSign.setVisible(%drawNeg);
}
//-----------------------------------------------------------------------------
function GuiBitmapCtrl::setNumber(%this,%number)
{
%this.setBitmap($Con::Root @ "/client/ui/game/numbers/" @ %number @ ".png");
}
//-----------------------------------------------------------------------------
function refreshBottomTextCtrl()
{
BottomPrintText.position = "0 0";
}
function refreshCenterTextCtrl()
{
CenterPrintText.position = "0 0";
}