Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List

MainWindow.cpp

00001 /*
00002 Copyright 2005 Elliott Kleinrock
00003 
00004 This file is part of FreeStars, a free clone of the Stars! game.
00005 
00006 FreeStars is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 FreeStars is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with FreeStars; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 The full GPL Copyright notice should be in the file COPYING.txt
00021 
00022 Contact:
00023 Email Elliott at 9jm0tjj02@sneakemail.com
00024 */
00025 
00026 #include "FSClient.h"
00027 
00028 #include <wx/minifram.h>
00029 
00030 // wxDockIt stuff
00031 #include <wx/pane.h>
00032 #include <wx/dockwindow.h>
00033 #include <wx/dockhost.h>
00034 #include <wx/dockpanel.h>
00035 
00036 #include "UniversePane.h"
00037 #include "DetailsPlanet.h"
00038 #include "DetailsFleet.h"
00039 #include "OrdersPlanet.h"
00040 #include "OrdersFleet.h"
00041 
00042 #include "Battle.h"
00043 
00044 #ifdef _DEBUG
00045 #define new DEBUG_NEW
00046 #endif
00047 
00048 bool MainWindow::mPaintOK = false;
00049 
00050 BEGIN_EVENT_TABLE(MainWindow, wxFrame)
00051   EVT_MENU(wxID_EXIT,           MainWindow::OnExit)
00052   EVT_MENU(wxID_ABOUT,          MainWindow::OnAbout)
00053   EVT_MENU(ID_Open,                     MainWindow::OnOpen)
00054 END_EVENT_TABLE()
00055 
00056 MainWindow::MainWindow(const wxString& title, const wxPoint& pos, const wxSize& size): wxFrame((wxFrame *)NULL, -1, title, pos, size)
00057 {
00058         TheGame = new CGame();
00059         TheGalaxy = new CGalaxy( );
00060         TheGame->LoadPlayerFile("Data/TestGame.m1");
00061 
00062   wxMenu *menuFile       = new wxMenu;
00063   wxMenu *menuView       = new wxMenu;
00064   wxMenu *menuViewZoom   = new wxMenu;
00065   wxMenu *menuViewLayout = new wxMenu;
00066   wxMenu *menuTurn       = new wxMenu;
00067   wxMenu *menuCommands   = new wxMenu;
00068   wxMenu *menuReport     = new wxMenu;
00069   wxMenu *menuReportDump = new wxMenu;
00070   wxMenu *menuHelp       = new wxMenu;
00071 
00072   menuFile->Append( ID_New,                 "&New...\tCtrl+N" );
00073   menuFile->Append( ID_CustomRaceWizard,    "Custom &Race Wizard..." );
00074   menuFile->Append( ID_Open,                "&Open...\tCtrl+O" );
00075   menuFile->Append( ID_Close,               "&Close" );
00076   menuFile->Append( ID_Save,                "&Save\tCtrl+S" );
00077   menuFile->Append( ID_SaveAndSubmit,       "Save &And Submit\tCtrl+A" );
00078   menuFile->AppendSeparator();
00079   menuFile->Append( ID_PrintMap,            "&Print Map" );
00080   menuFile->AppendSeparator();
00081   menuFile->Append(wxID_EXIT,                           "E&xit");
00082 
00083   menuView->Append( ID_Toolbar,             "&Toolbar" );
00084   menuView->AppendSeparator();
00085   menuView->Append( ID_Find,                "&Find...\tCtrl+F" );
00086   menuView->Append( ID_Zoom,                "&Zoom", menuViewZoom );
00087         menuViewZoom->AppendRadioItem(ID_Zoom25, "25%");
00088         menuViewZoom->AppendRadioItem(ID_Zoom38, "38%");
00089         menuViewZoom->AppendRadioItem(ID_Zoom50, "50%");
00090         menuViewZoom->AppendRadioItem(ID_Zoom75, "75%");
00091         menuViewZoom->AppendRadioItem(ID_Zoom100, "100%");
00092         menuViewZoom->AppendRadioItem(ID_Zoom125, "125%");
00093         menuViewZoom->AppendRadioItem(ID_Zoom150, "150%");
00094         menuViewZoom->AppendRadioItem(ID_Zoom200, "200%");
00095         menuViewZoom->AppendRadioItem(ID_Zoom400, "400%");
00096 //    menuViewZoom->Check( ID_Zoom400, true );
00097   menuView->Append( ID_WindowLayout,        "&Window Layout", menuViewLayout );
00098         menuViewLayout->AppendRadioItem(ID_LayoutLarge,  "Large Screen");
00099         menuViewLayout->AppendRadioItem(ID_LayoutMedium, "Medium Screen");
00100         menuViewLayout->AppendRadioItem(ID_LayoutSmall,  "Small Screen");
00101         menuViewLayout->Check( ID_LayoutLarge, true );
00102   menuView->Append( ID_PlayerColors,        "Player &Color" );
00103   menuView->AppendSeparator();
00104   menuView->Append( ID_Race,                "&Race...\tF8" );
00105   menuView->Append( ID_GameParameters,      "&Game Parameters..." );
00106 
00107   menuTurn->Append(ID_WaitForNew,           "&Wait for New");
00108   menuTurn->Append(ID_Generate,             "&Generate\tF9");
00109 
00110   menuCommands->Append(ID_ShipDesign,       "&Ship Design...\tF4");
00111   menuCommands->Append(ID_Research,         "&Research...\tF5");
00112   menuCommands->Append(ID_BattlePlans,      "&Battle Plans...\tF6");
00113   menuCommands->Append(ID_PlayerRelations,  "&Player Relations...\tF7");
00114   menuCommands->AppendSeparator();
00115   menuCommands->Append(ID_ChangePassword,   "C&hange Password...");
00116 
00117   menuReport->Append(ID_Planets,            "&Planets...\tF3");
00118   menuReport->Append(ID_Fleets,             "&Fleets...\tF3");
00119   menuReport->Append(ID_OthersFleets,       "&Others' Fleets...\tF3");
00120   menuReport->AppendSeparator();
00121   menuReport->Append(ID_Battles,            "&Battles...\tF3");
00122   menuReport->AppendSeparator();
00123   menuReport->Append(ID_Score,              "&Score...\tF10");
00124   menuReport->AppendSeparator();
00125   menuReport->Append(ID_Dump,               "Dump to Text File", menuReportDump);
00126     menuReportDump->Append(ID_UniverseDefinition, "Universe Definition");
00127     menuReportDump->Append(ID_PlanetInformation,  "Planet Information");
00128     menuReportDump->Append(ID_FleetInformation,   "Fleet Information");
00129 
00130   menuHelp->Append(ID_Introduction,         "&Introduction");
00131   menuHelp->Append(ID_PlayersGuide,         "&Players Guide\tF1");
00132   menuHelp->AppendSeparator();
00133   menuHelp->Append(ID_TechnologyBrowser,    "&Technology Browser\tF2");
00134   menuHelp->Append(ID_Tutorial,             "T&utorial");
00135   menuHelp->AppendSeparator();
00136   menuHelp->Append(wxID_ABOUT,                          "&About Stars!");
00137 
00138   wxMenuBar *menuBar = new wxMenuBar;
00139   menuBar->Append( menuFile,     "&File" );
00140   menuBar->Append( menuView,     "&View" );
00141   menuBar->Append( menuTurn,     "&Turn" );
00142   menuBar->Append( menuCommands, "&Commands" );
00143   menuBar->Append( menuReport,   "&Report" );
00144   menuBar->Append( menuHelp,     "&Help" );
00145 
00146   SetMenuBar( menuBar );
00147 
00148   this->SetMinSize( wxSize( 640, 400 ) );
00149 
00150 //  wxSplitterWindow *vertical = new wxSplitterWindow( this );
00151 //  wxSplitterWindow *left     = new wxSplitterWindow( vertical );
00152 //  wxSplitterWindow *right    = new wxSplitterWindow( vertical );
00153 //  vertical->SplitVertically( left, right, 40 );
00154 //  right->SetMinimumPaneSize( 40 );
00155 //  left->SetMaxSize( wxSize( 40, 2000 ) );
00156         mStatusBar = CreateStatusBar();
00157         mToolBar = CreateToolBar();
00158 
00159         mLayoutManager = new wxLayoutManager( this );
00160     mLayoutManager->AddDefaultHosts();
00161 
00162     // add main client window
00163     wxPane * pPane = new wxPane(this, wxID_ANY, "");
00164     mLayoutManager->SetLayout(wxDWF_SPLITTER_BORDERS, pPane);
00165     pPane->ShowCloseButton(false);
00166     pPane->ShowHeader(false);
00167 
00168     // create dockwindows
00169     wxDockWindow * pDockWindow1;
00170         pDockWindow1 = new wxDockWindow(this, wxID_ANY, "Details - Planet", wxDefaultPosition, wxDefaultSize, "dp");//, wxDWC_NO_CONTROLS);
00171         mDetailsPlanet = new DetailsPlanet(this, pDockWindow1);
00172     pDockWindow1->SetClient(mDetailsPlanet);
00173     mLayoutManager->AddDockWindow(pDockWindow1);
00174 
00175     wxDockWindow * pDockWindow2;
00176         pDockWindow2 = new wxDockWindow(this, wxID_ANY, "Details - Fleet", wxDefaultPosition, wxDefaultSize, "df");//, wxDWC_NO_CONTROLS);
00177         mDetailsFleet = new DetailsFleet(this, pDockWindow2);
00178     pDockWindow2->SetClient(mDetailsFleet);
00179     mLayoutManager->AddDockWindow(pDockWindow2);
00180 
00181     wxDockWindow * pDockWindow3;
00182         pDockWindow3 = new wxDockWindow(this, wxID_ANY, "Orders - Planet", wxDefaultPosition, wxDefaultSize, "op");//, wxDWC_NO_CONTROLS);
00183         mOrdersPlanet = new OrdersPlanet(this, pDockWindow3);
00184     pDockWindow3->SetClient(mOrdersPlanet);
00185     mLayoutManager->AddDockWindow(pDockWindow3);
00186 
00187     wxDockWindow * pDockWindow4;
00188         pDockWindow4 = new wxDockWindow(this, wxID_ANY, "Orders - Fleet", wxDefaultPosition, wxDefaultSize, "of");//, wxDWC_NO_CONTROLS);
00189         mOrdersFleet = new OrdersFleet(this, pDockWindow4);
00190     pDockWindow4->SetClient(mOrdersFleet);
00191     mLayoutManager->AddDockWindow(pDockWindow4);
00192 
00193         // dock windows
00194     HostInfo hi;
00195     hi = mLayoutManager->GetDockHost(wxDEFAULT_BOTTOM_HOST);
00196         hi.placement = HIP_FRONT;
00197         hi.pHost->SetAreaSize(mDetailsPlanet->GetMinSize().GetHeight());
00198         mLayoutManager->DockWindow(pDockWindow1, hi);
00199 
00200     hi = mLayoutManager->GetDockHost(wxDEFAULT_BOTTOM_HOST);
00201         hi.placement = HIP_BACK;
00202         hi.pPanel = pDockWindow1->GetDockPanel();
00203         hi.pHost->SetAreaSize(mDetailsFleet->GetMinSize().GetHeight());
00204     mLayoutManager->DockWindow(pDockWindow2, hi);
00205 
00206     hi = mLayoutManager->GetDockHost(wxDEFAULT_LEFT_HOST);
00207         hi.pHost->SetAreaSize(128);
00208         hi.placement = HIP_FRONT;
00209         hi.pHost->SetAreaSize(mOrdersPlanet->GetMinSize().GetWidth());
00210     mLayoutManager->DockWindow(pDockWindow3, hi);
00211 
00212     hi = mLayoutManager->GetDockHost(wxDEFAULT_LEFT_HOST);
00213         hi.placement = HIP_BACK;
00214         hi.pHost->SetAreaSize(mOrdersFleet->GetMinSize().GetWidth());
00215         hi.pPanel = pDockWindow3->GetDockPanel();
00216     mLayoutManager->DockWindow(pDockWindow4, hi);
00217 
00218         map = new UniversePane(this);
00219         map->Show( true );
00220         map->Refresh( true, NULL );
00221         pPane->SetClient(map);
00222 
00223         mPaintOK = true;
00224 }
00225 
00226 MainWindow::~MainWindow()
00227 {
00228         delete mLayoutManager;
00229         Rules::Cleanup();
00230         Component::Cleanup();
00231         Battle::Cleanup();
00232         Ship::Cleanup();
00233         delete TheGalaxy;
00234         delete TheGame;
00235 }
00236 
00237 void MainWindow::OnExit(wxCommandEvent& WXUNUSED(event))
00238 {
00239         mPaintOK = false;
00240 
00241         Close(true);
00242 }
00243 
00244 void MainWindow::OnAbout(wxCommandEvent& WXUNUSED(event))
00245 {
00246   wxMessageBox( "FreeStars for all major operating systems\nThe Advanced Interstellar Strategy Game\nVersion 0.1\nCopyright (C) 2005 by Pieter Hulshoff",
00247                 "About FreeStars", wxOK | wxICON_INFORMATION, this);
00248 }
00249 
00250 void MainWindow::OnOpen(wxCommandEvent& WXUNUSED(event))
00251 {
00252         wxFileDialog fd(this, "Open Player Turn File", TheGame->GetFileLoc().c_str());
00253         fd.SetWildcard("*.m*");
00254 
00255         if (fd.ShowModal() == wxID_OK) {
00256                 ::wxBeginBusyCursor();
00257                 Rules::Cleanup();
00258                 Component::Cleanup();
00259                 Battle::Cleanup();
00260                 Ship::Cleanup();
00261                 delete TheGalaxy;
00262                 delete TheGame;
00263                 TheGame = new CGame();
00264                 TheGalaxy = new CGalaxy( );
00265                 TheGame->LoadPlayerFile(fd.GetPath());
00266                 map->Refresh(true, NULL);
00267                 ::wxEndBusyCursor();
00268         }
00269 }
00270 
00271 void MainWindow::SetLocation(Location * loc)
00272 {
00273         Fleet * f = dynamic_cast<Fleet *>(loc);
00274         if (f != NULL) {
00275                 if (f->GetOwner() == TheGame->GetCurrentPlayer()) {
00276                         mOrdersFleet->SetLocation(f);
00277 //                      mOrdersFleet->SetFocus();
00278                 } else {
00279                         mDetailsFleet->SetLocation(f);
00280 //                      mDetailsFleet->SetFocus();
00281                 }
00282 //              SetFocus();
00283         }
00284 
00285         Planet * p = dynamic_cast<Planet *>(loc);
00286         if (p != NULL) {
00287                 mDetailsPlanet->SetLocation(p);
00288 //              mDetailsPlanet->SetFocus();
00289                 if (p->GetOwner() == TheGame->GetCurrentPlayer()) {
00290                         mOrdersPlanet->SetLocation(p);
00291 //                      mOrdersPlanet->SetFocus();
00292                 }
00293 //              SetFocus();
00294         }
00295 }

Generated on Mon Aug 8 21:33:43 2005 for Freestars by  doxygen 1.4.2-20050421