#include "StdAfx.h"
#include "ShipMonitor.h"
#include "Game.h"
#include "KlingonShip.h"
#include "Enterprise.h"
#include "StarBase.h"
ShipMonitor::ShipMonitor(IGUIFont* pFont)
{
m_pFont = pFont;
m_dispMode = Black;
m_pScanInfo = NULL;
m_drawSector.initFont(m_pFont);
}
ShipMonitor::~ShipMonitor(void)
{
}
void ShipMonitor::setMode(Mode mod)
{
m_dispMode = mod;
}
void ShipMonitor::draw(u32 uTime)
{
switch(m_dispMode)
{
case SectorView:
drawSector(uTime);
break;
case QuadrantView:
drawQuadrant(uTime);
break;
case DamageReport:
drawDamageReport();
break;
case ComputerLog:
drawComputerLog();
break;
case Help:
drawHelp();
break;
}
}
void ShipMonitor::drawSector(u32 uTime)
{
int iCharWidth = m_pFont->getDimension(L" ").Width;
int iLineHeight = m_pFont->getDimension(L" ").Height;
iLineHeight = iLineHeight + iLineHeight / 2;
dimension2di dimFont = m_pFont->getDimension(L"SECTOR VIEW");
m_pFont->draw(L"SECTOR VIEW", core::rect<s32>(iCharWidth, 2 * dimFont.Height, 500, 600), SColor(255,255,255,255));
// draw grid
//
int iY = 4 * dimFont.Height;
m_pFont->draw(L" 0 1 2 3 4 5 6 7", core::rect<s32>(iCharWidth * 3, iY, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"0", core::rect<s32>(iCharWidth, iY + 1 * iLineHeight, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"1", core::rect<s32>(iCharWidth, iY + 2 * iLineHeight, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"2", core::rect<s32>(iCharWidth, iY + 3 * iLineHeight, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"3", core::rect<s32>(iCharWidth, iY + 4 * iLineHeight, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"4", core::rect<s32>(iCharWidth, iY + 5 * iLineHeight, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"5", core::rect<s32>(iCharWidth, iY + 6 * iLineHeight, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"6", core::rect<s32>(iCharWidth, iY + 7 * iLineHeight, 500, 600), SColor(255,255,255,255));
m_pFont->draw(L"7", core::rect<s32>(iCharWidth, iY + 8 * iLineHeight, 500, 600), SColor(255,255,255,255));
Galaxy& refGalaxy = Game::getInstance()->getGameData()->getGalaxy();
Sector* pSector = refGalaxy.getSector(refGalaxy.getEnterprise().getSector());
if(pSector)
{
// stars
//
std::vector<StarCoordinate>& lstStars = pSector->getStars();
int iOffset = iCharWidth * 3;
for(std::vector<StarCoordinate>::iterator itStar = lstStars.begin();
itStar != lstStars.end(); ++itStar)
{
drawStar(*itStar);
}
drawStarBase(pSector->getStarBase());
for(std::vector<KlingonShip*>::iterator itKlingon = pSector->getKlingons().begin();
itKlingon != pSector->getKlingons().end(); ++itKlingon)
{
drawKlingon(*itKlingon);
}
drawEnterprise(&refGalaxy.getEnterprise());
}
}
void ShipMonitor::drawStar(StarCoordinate& coStar)
{
m_drawSector.drawAt(L"*", coStar, SColor(255,255,255,0));
}
void ShipMonitor::drawStarBase(StarBase* pBase)
{
if(pBase)
{
if (pBase->isDestroyed())
{
m_drawSector.drawAt(L"[@]", pBase->getLocation(), SColor(255,128,64,32));
}
else
{
m_drawSector.drawAt(L">!<", pBase->getLocation(), SColor(255,192,192,192));
}
}
}
void ShipMonitor::drawKlingon(KlingonShip* pKlingon)
{
if(pKlingon->isDestroyed())
{
m_drawSector.drawAt(L"#=+", pKlingon->getLocation(), SColor(255,128,128,128));
}
else
{
m_drawSector.drawAt(L"+++", pKlingon->getLocation(), SColor(105 + pKlingon->getEnergyLevel() ,255,64,64));
}
}
void ShipMonitor::drawEnterprise(Enterprise* pEnterprise)
{
m_drawSector.drawAt(L"<E>", pEnterprise->getLocation(), SColor(255,255,255,255));
}
void ShipMonitor::drawQuadrant(u32 uTime)
{
if(m_pScanInfo == NULL)
{
return;
}
int iCharWidth = m_pFont->getDimension(L" ").Width;
int iLineHeight = m_pFont->getDimension(L" ").Height;
iLineHeight = iLineHeight + iLineHeight / 2;
dimension2di dimFont = m_pFont->getDimension(L"QUADRANT VIEW");
m_pFont->draw(L"QUADRANT VIEW", core::rect<s32>(iCharWidth, 2 * dimFont.Height, 500, 600), SColor(255,255,255,255));
int iY = 4 * dimFont.Height;
StarCoordinate coSector = Game::getInstance()->getGameData()->getGalaxy().getEnterprise().getSector();
// x coordinates
//
stringw strText = L"";
if(coSector.X - 1 < 0)
{
strText = L" _";
}
else
{
strText = L" ";
strText += coSector.X - 1;
}
drawQuadrantData(1,0, strText);
strText = L" ";
strText += coSector.X;
drawQuadrantData(2,0, strText);
if(coSector.X + 1 > 7)
{
strText = L" _";
}
else
{
strText = L" ";
strText += coSector.X + 1;
}
drawQuadrantData(3,0, strText);
// y coordinates
if(coSector.Y - 1 < 0)
{
strText = L" _";
}
else
{
strText = L" ";
strText += coSector.Y - 1;
}
drawQuadrantData(0, 1, strText);
strText = L" ";
strText += coSector.Y;
drawQuadrantData(0, 2, strText);
if(coSector.Y + 1 > 7)
{
strText = L" _";
}
else
{
strText = L" ";
strText += coSector.Y + 1;
}
drawQuadrantData(0, 3, strText);
// data
//
drawQuadrantData(1, 1, m_pScanInfo[0].toString()); drawQuadrantData(2, 1, m_pScanInfo[1].toString()); drawQuadrantData(3, 1, m_pScanInfo[2].toString());
drawQuadrantData(1, 2, m_pScanInfo[3].toString()); drawQuadrantData(2, 2, m_pScanInfo[4].toString()); drawQuadrantData(3, 2, m_pScanInfo[5].toString());
drawQuadrantData(1, 3, m_pScanInfo[6].toString()); drawQuadrantData(2, 3, m_pScanInfo[7].toString()); drawQuadrantData(3, 3, m_pScanInfo[8].toString());
}
void ShipMonitor::drawQuadrantData(int iX, int iY, stringw strData)
{
dimension2di dimFont = m_pFont->getDimension(L" ");
int iOffsetWidth = dimFont.Width * 3;
int iOffsetHeight = dimFont.Height * 4;
int iLineHeight = dimFont.Height + dimFont.Height / 2;
m_pFont->draw(strData.c_str(), core::rect<s32>(iOffsetWidth + (dimFont.Width * iX * 4),
iOffsetHeight + (iLineHeight * iY), 500, 400), SColor(255,255,255,255));
}
void ShipMonitor::setScanInfo(Sector::Info* pScanInfo)
{
if(m_pScanInfo)
{
delete [] m_pScanInfo;
}
m_pScanInfo = pScanInfo;
}
void ShipMonitor::drawDamageReport()
{
dimension2di dimFont = m_pFont->getDimension(L" ");
m_pFont->draw(L"DAMAGE REPORT", core::rect<s32>(dimFont.Width, 2 * dimFont.Height, 500, 600), SColor(255,255,255,255));
Enterprise& rShip = Game::getInstance()->getGameData()->getGalaxy().getEnterprise();
drawReportLine(L"WARP ENGINE ", rShip.getSystemStatus(Enterprise::Engine), 1);
drawReportLine(L"SHORT RANGE SENSORS ", rShip.getSystemStatus(Enterprise::ShortRangeSensor), 2);
drawReportLine(L"LONG RANGE SENSORS ", rShip.getSystemStatus(Enterprise::LongRangeSensor), 3);
drawReportLine(L"PHASER CONTROLLER ", rShip.getSystemStatus(Enterprise::PhaserController), 4);
drawReportLine(L"TORPEDO CONTROLLER ", rShip.getSystemStatus(Enterprise::TorpedoController), 5);
drawReportLine(L"SHIELD CONTROLLER ", rShip.getSystemStatus(Enterprise::ShieldController), 6);
drawReportLine(L"COMPUTER ", rShip.getSystemStatus(Enterprise::Computer), 7);
}
void ShipMonitor::drawReportLine(stringw strData, int iStatus, int iLine)
{
SColor clr = SColor(255, 0, 255, 0);
if(iStatus < 33)
{
clr = SColor(255, 255, 0, 0);
}
else
{
if(iStatus < 66)
{
clr = SColor(255, 255, 255, 0);
}
}
strData += iStatus;
strData += L" %";
dimension2di dimFont = m_pFont->getDimension(L" ");
int iLineHeight = dimFont.Height;
iLineHeight = iLineHeight + iLineHeight / 2;
m_pFont->draw(strData.c_str(), core::rect<s32>(dimFont.Width * 2, 2 * dimFont.Height + iLineHeight * iLine, 500, 600), clr);
}
void ShipMonitor::drawComputerLog()
{
dimension2di dimFont = m_pFont->getDimension(L" ");
int iLineHeight = dimFont.Height;
iLineHeight = iLineHeight + iLineHeight / 2;
m_pFont->draw(L"COMPUTER QUADRANT LOG", core::rect<s32>(dimFont.Width, 2 * dimFont.Height, 500, 600), SColor(255,255,255,255));
int iHeighOffset = 4 * dimFont.Height;
Enterprise& rShip = Game::getInstance()->getGameData()->getGalaxy().getEnterprise();
for(int iY = 0; iY < 8; ++iY)
{
for(int iX = 0; iX < 8; ++iX)
{
StarCoordinate coAt = StarCoordinate(iX, iY);
stringw wText = coAt.isEqual(rShip.getSector()) ? L">" : L" ";
drawQuadrantData(iX, iY, wText + rShip.getLoggedSectorInfo(coAt).toString());
}
}
}
void ShipMonitor::drawHelp()
{
dimension2di dimFont = m_pFont->getDimension(L" ");
int iLineHeight = dimFont.Height;
iLineHeight = iLineHeight + iLineHeight / 2;
SColor clrWhite(255,255,255,255);
m_pFont->draw(L"HELP (ARROW UP & DOWN TO SCROLL)", core::rect<s32>(dimFont.Width, 2 * dimFont.Height, 500, 600), clrWhite);
}