00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "FSClient.h"
00027
00028 #include "UniversePane.h"
00029
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #endif
00033
00034 BEGIN_EVENT_TABLE(UniversePane, wxScrolledWindow)
00035 EVT_PAINT(UniversePane::OnPaint)
00036 EVT_RIGHT_DOWN(UniversePane::OnRightDown)
00037 EVT_LEFT_DOWN(UniversePane::OnLeftDown)
00038 END_EVENT_TABLE()
00039
00040 wxLocation::~wxLocation()
00041 {
00042 }
00043
00044 UniversePane::UniversePane(MainWindow * mainw) : wxScrolledWindow(mainw, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL | wxVSCROLL)
00045 {
00046 mParent = mainw;
00047 mScale = 8.0;
00048 mLastSelected = NULL;
00049 SetVirtualSize(100 + 200*mScale, 100 + 200*mScale);
00050 SetScrollRate(1+2*mScale, 1+2*mScale);
00051 }
00052
00053 void UniversePane::OnPaint( wxPaintEvent &WXUNUSED( event ) )
00054 {
00055 if (!MainWindow::mPaintOK)
00056 return;
00057
00058 wxPaintDC dc( this );
00059 dc.Clear( );
00060 int vx=0, vy=0, unitX=0, unitY=0;
00061
00062 GetViewStart(&vx, &vy);
00063 GetScrollPixelsPerUnit( &unitX, &unitY );
00064
00065 int xOffset = -vx*unitX;
00066 int yOffset = -vy*unitY;
00067
00068
00069 dc.SetBrush( *wxBLACK_BRUSH );
00070 dc.SetPen( wxPen( wxColour( 0, 0, 0 ), 0, wxSOLID ) );
00071 dc.DrawRectangle( xOffset, yOffset, 3000, 3000 );
00072
00073 Planet *curPlanet;
00074 int i;
00075
00076
00077 dc.SetBrush( wxBrush( wxColour( 120, 0, 0 ), wxSOLID ) );
00078 dc.SetPen( wxPen( wxColour( 120, 0, 0 ), 3, wxSOLID ) );
00079 for (i = 1; i <= TheGalaxy->GetPlanetCount(); ++i) {
00080 curPlanet = TheGalaxy->GetPlanet(i);
00081 if (curPlanet && curPlanet->GetOwner() == TheGame->GetCurrentPlayer())
00082 {
00083 dc.DrawCircle( 50+xOffset+(((*curPlanet).GetPosX( ))-1000)*mScale, 50+yOffset+(1200-((*curPlanet).GetPosY( )))*mScale, (*curPlanet).GetScanSpace( )*mScale );
00084 }
00085 }
00086
00087 const Fleet * curFleet;
00088 for (i = 1; i <= Rules::MaxFleets; ++i) {
00089 curFleet = TheGame->GetCurrentPlayer()->GetFleet(i);
00090 if (curFleet)
00091 {
00092 dc.DrawCircle( 50+xOffset+(curFleet->GetPosX() - 1000)*mScale, 50+yOffset+(1200 - curFleet->GetPosY())*mScale, curFleet->GetScanSpace()*mScale);
00093 }
00094 }
00095
00096
00097 dc.SetBrush( wxBrush( wxColour( 0, 120, 0 ), wxSOLID ) );
00098 dc.SetPen( wxPen( wxColour( 0, 120, 0 ), 3, wxSOLID ) );
00099 for (i = 1; i <= TheGalaxy->GetPlanetCount(); ++i) {
00100 curPlanet = TheGalaxy->GetPlanet(i);
00101 if (curPlanet && curPlanet->GetOwner() == TheGame->GetCurrentPlayer())
00102 {
00103 dc.DrawCircle( 50+xOffset+(((*curPlanet).GetPosX( ))-1000)*mScale, 50+yOffset+(1200-((*curPlanet).GetPosY( )))*mScale, (*curPlanet).GetScanPen( )*mScale );
00104 }
00105 }
00106
00107 wxPoint TriPoints[] = {wxPoint(0,0), wxPoint(0,6), wxPoint(3,3)};
00108
00109 for (i = 1; i <= Rules::MaxFleets; ++i) {
00110 curFleet = TheGame->GetCurrentPlayer()->GetFleet(i);
00111 if (curFleet)
00112 {
00113 dc.SetBrush( wxBrush( wxColour( 0, 120, 0 ), wxSOLID ) );
00114 dc.SetPen( wxPen( wxColour( 0, 120, 0 ), 3, wxSOLID ) );
00115 dc.DrawCircle( 50+xOffset+(curFleet->GetPosX() - 1000)*mScale, 50+yOffset+(1200 - curFleet->GetPosY())*mScale, curFleet->GetScanPen()*mScale);
00116 dc.SetBrush( wxBrush( wxColour( 0, 240, 0 ), wxSOLID ) );
00117 dc.SetPen( wxPen( wxColour( 0, 240, 0 ), 3, wxSOLID ) );
00118 dc.DrawPolygon(3, TriPoints, 50+xOffset+(curFleet->GetPosX() - 1000)*mScale, 50+yOffset+(1200 - curFleet->GetPosY())*mScale);
00119 }
00120 }
00121
00122
00123 dc.SetTextForeground( wxColour( 255, 255, 255 ) );
00124 for (i = 1; i <= TheGalaxy->GetPlanetCount(); ++i) {
00125 curPlanet = TheGalaxy->GetPlanet(i);
00126 if (curPlanet)
00127 {
00128 dc.SetBrush( wxBrush( wxColour( 0, 255, 0 ), wxSOLID ) );
00129 dc.SetPen( wxPen( wxColour( 0, 100, 0 ), 3, wxSOLID ) );
00130 dc.DrawCircle( 50+xOffset+(((*curPlanet).GetPosX( ))-1000)*mScale, 50+yOffset+(1200-((*curPlanet).GetPosY( )))*mScale, 10 );
00131 dc.DrawText(curPlanet->GetName().c_str(), 60+xOffset+(((*curPlanet).GetPosX( ))-1000)*mScale, 60+yOffset+(1200-((*curPlanet).GetPosY( )))*mScale );
00132 }
00133 }
00134 }
00135
00136 void UniversePane::OnRightDown(wxMouseEvent &me)
00137 {
00138 int x;
00139 int y;
00140 CalcUnscrolledPosition(me.m_x, me.m_y, &x, &y);
00141 x = (x-50)/mScale + 1000;
00142 y = 1200 - (y-50)/mScale;
00143 wxMenu menu;
00144 deque<Location *> * d;
00145 d = TheGame->GetClosestTop(x, y);
00146 if (d != NULL) {
00147 for (int i = 0; i < d->size(); ++i) {
00148 menu.Append(ID_SelLocation + i, d->at(i)->GetName(TheGame->GetCurrentPlayer()).c_str());
00149 Connect(ID_SelLocation + i, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(UniversePane::OnSelectLocation), new wxLocation(d->at(i)));
00150 }
00151 }
00152
00153 PopupMenu(&menu);
00154 }
00155
00156 void UniversePane::OnLeftDown(wxMouseEvent &me)
00157 {
00158 int x;
00159 int y;
00160 CalcUnscrolledPosition(me.m_x, me.m_y, &x, &y);
00161 x = (x-50)/mScale + 1000;
00162 y = 1200 - (y-50)/mScale;
00163
00164 deque<Location *> * d;
00165 d = TheGame->GetClosestTop(x, y);
00166 if (d != NULL) {
00167 if (d == mLastSelected) {
00168 mpLastSelected++;
00169 if (mpLastSelected >= d->size())
00170 mpLastSelected = 0;
00171 } else {
00172 mLastSelected = d;
00173 mpLastSelected = 0;
00174 }
00175
00176 SelectLocation(d->at(mpLastSelected));
00177 }
00178 }
00179
00180 void UniversePane::OnSelectLocation(wxCommandEvent& event)
00181 {
00182 wxLocation * wl = dynamic_cast<wxLocation *>(event.m_callbackUserData);
00183 if (wl != NULL)
00184 SelectLocation(wl->mLocation);
00185 }
00186
00187 void UniversePane::SelectLocation(Location * loc)
00188 {
00189 if (loc == NULL)
00190 return;
00191
00192 mParent->SetLocation(loc);
00193 }