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

OrdersFleet.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 #include <wx/sashwin.h>
00028 
00029 #include "OrdersFleet.h"
00030 
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #endif
00034 
00035 BEGIN_EVENT_TABLE(OrdersFleet, wxPanel)
00036         EVT_BUTTON(ID_Rename, OrdersFleet::Rename)
00037         EVT_BUTTON(ID_Goto, OrdersFleet::Goto)
00038 END_EVENT_TABLE()
00039 
00040 OrdersFleet::OrdersFleet(MainWindow * parent, wxWindow * frame)
00041         : wxPanel(frame)
00042 {
00043         mMainWindow = parent;
00044         mFleet = NULL;
00045 
00046         wxBoxSizer * top = new wxBoxSizer(wxVERTICAL);
00047         mFleetStaticBox = new wxStaticBoxSizer(wxVERTICAL, this, "");
00048 
00049         mFleetStaticBox->Add(new wxButton(this, ID_Previous, "Previous"),
00050                 0,              // vertically stretchable
00051                 wxALL,  // has border all around it
00052                 5);     // border size is
00053 
00054         mFleetStaticBox->Add(new wxButton(this, ID_Next, "Next"),
00055                 0,              // vertically stretchable
00056                 wxALL,  // has border all around it
00057                 5);     // border size is
00058 
00059         mFleetStaticBox->Add(new wxButton(this, ID_Rename, "Rename"),
00060                 0,              // vertically stretchable
00061                 wxALL,  // has border all around it
00062                 5);     // border size is
00063 
00064         top->Add(mFleetStaticBox, 0, wxALIGN_LEFT);
00065 
00066         mLocationStaticBox = new wxStaticBoxSizer(wxHORIZONTAL, this, "");
00067 
00068         mLocationStaticBox->Add(new wxButton(this, ID_Goto, "Goto"),
00069                 0,              // vertically stretchable
00070                 wxALL,  // has border all around it
00071                 5);     // border size is
00072 
00073         mLocationStaticBox->Add(new wxButton(this, ID_Transfer, "Transfer"),
00074                 0,              // vertically stretchable
00075                 wxALL,  // has border all around it
00076                 5);     // border size is
00077 
00078         top->Add(mLocationStaticBox, 0, wxALIGN_LEFT);
00079 
00080 //      wxStaticBoxSizer * sbs = new wxStaticBoxSizer(wxVERTICAL, this, "");
00081         SetSizer(top);      // use the sizer for layout
00082 
00083         top->SetSizeHints(this);   // set size hints to honour minimum size
00084 
00085 /*      wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
00086 
00087         // create text ctrl with minimal size 100x60
00088         topsizer->Add(
00089                 new wxTextCtrl( this, -1, "My text.", wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE),
00090                 1,            // make vertically stretchable
00091                 wxEXPAND |    // make horizontally stretchable
00092                 wxALL,        //   and make border all around
00093                 10 );         // set border width to 10
00094 
00095 
00096         wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
00097         button_sizer->Add(
00098                 new wxButton( this, wxID_OK, "OK" ),
00099                 0,           // make horizontally unstretchable
00100                 wxALL,       // make border all around (implicit top alignment)
00101                 10 );        // set border width to 10
00102         button_sizer->Add(
00103                 new wxButton( this, wxID_CANCEL, "Cancel" ),
00104                 0,           // make horizontally unstretchable
00105                 wxALL,       // make border all around (implicit top alignment)
00106                 10 );        // set border width to 10
00107 
00108         topsizer->Add(
00109                 button_sizer,
00110                 0,                // make vertically unstretchable
00111                 wxALIGN_CENTER ); // no border and centre horizontally
00112 
00113         SetSizer( topsizer );      // use the sizer for layout
00114 
00115         topsizer->SetSizeHints( this );   // set size hints to honour minimum size
00116 */
00117 
00118 //      wxSashWindow * wd = new wxSashWindow(this, -1, wxPoint(10,10), wxSize(150,50), wxCLIP_CHILDREN | wxRAISED_BORDER);
00119 //      wd->AddItem(
00120 //      wd->Show(true);
00121 }
00122 
00123 OrdersFleet::~OrdersFleet()
00124 {
00125 }
00126 
00127 void OrdersFleet::SetLocation(Fleet * fleet)
00128 {
00129         mFleet = fleet;
00130         string t;
00131         t = fleet->GetName(TheGame->GetCurrentPlayer());
00132         mFleetStaticBox->GetStaticBox()->SetLabel(t.c_str());
00133 
00134         Planet * p = dynamic_cast<Planet *>(fleet->GetAlsoHere()->at(0));
00135         if (p == NULL)
00136                 mLocationStaticBox->GetStaticBox()->SetLabel("In Deep Space");
00137         else {
00138                 t = "Orbiting ";
00139                 t += p->GetName();
00140                 mLocationStaticBox->GetStaticBox()->SetLabel(t.c_str());
00141         }
00142 }
00143 
00144 void OrdersFleet::Rename(wxCommandEvent &)
00145 {
00146         if (mFleet != NULL) {
00147                 wxDialog dialog;
00148                 dialog.Create(this, -1, "Rename Fleet", wxDefaultPosition, wxSize(300, 100));
00149                 wxBoxSizer * top = new wxBoxSizer(wxVERTICAL);
00150                 wxBoxSizer * size1 = new wxBoxSizer(wxHORIZONTAL);
00151                 size1->Add(new wxStaticText(&dialog, -1, "New name:"), 0, wxALL, 5);
00152                 wxTextCtrl * tb = new wxTextCtrl(&dialog, -1, mFleet->GetName(TheGame->GetCurrentPlayer()).c_str(), wxDefaultPosition, wxSize(200, -1));
00153                 size1->Add(tb, 1, wxALL, 5);
00154                 top->Add(size1, 0, wxEXPAND | wxALIGN_LEFT);
00155                 top->Add(dialog.CreateStdDialogButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER);
00156                 dialog.SetSizer(top);
00157 
00158                 if (dialog.ShowModal() == wxID_OK) {
00159                         string s = tb->GetValue();
00160                         if (s != mFleet->GetName(TheGame->GetCurrentPlayer())) {
00161                                 mFleet->SetName(s.c_str());
00162                                 mMainWindow->SetLocation(mFleet);
00163                         }
00164                 }
00165         }
00166 }
00167 
00168 void OrdersFleet::Goto(wxCommandEvent &)
00169 {
00170         if (mFleet == NULL)
00171                 return;
00172 
00173         Planet * p = dynamic_cast<Planet *>(mFleet->GetAlsoHere()->at(0));
00174         if (p != NULL)
00175                 mMainWindow->SetLocation(p);
00176 }

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