Advanced Strategic Command
unitnaming.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include "unitnaming.h"
11 #include "../gamemap.h"
12 #include "../actions/renamecontainercommand.h"
13 #include "../contextutils.h"
14 
15 bool UnitNaming::ok()
16 {
17  if ( publicName->GetText() != unit->name || privateName->GetText() != unit->privateName ) {
18  auto_ptr<RenameContainerCommand> rcc ( new RenameContainerCommand( unit ));
19  rcc->setName( publicName->GetText(), privateName->GetText() );
20  ActionResult res = rcc->execute( createContext( unit->getMap() ));
21  if ( res.successful() )
22  rcc.release();
23  }
24  QuitModal();
25  return true;
26 }
27 
28 bool UnitNaming::cancel()
29 {
30  QuitModal();
31  return true;
32 }
33 
34 bool UnitNaming::line1completed()
35 {
36  if ( privateName ) {
37  privateName->EditBegin();
38  return true;
39  } else
40  return false;
41 }
42 
43 UnitNaming::UnitNaming ( ContainerBase* myUnit) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 300, 150), "Enter Names")
44 {
45  unit = myUnit;
46 
47  int width = 90;
48  new PG_Label( this, PG_Rect( border, 40, width, 20), "Public: ");
49 
50  int fieldwidth = Width() - 3 * border - width;
51  publicName = new PG_LineEdit( this, PG_Rect( border*2 + width, 40, fieldwidth, 20));
52  publicName->SetText( myUnit->name );
53  publicName->sigEditReturn.connect( sigc::mem_fun( *this, &UnitNaming::line1completed ));
54 
55  new PG_Label( this, PG_Rect( border, 70, width, 20), "Private: ");
56  privateName = new PG_LineEdit( this, PG_Rect( border*2 + width, 70, fieldwidth, 20));
57  privateName->SetText( myUnit->privateName);
58  privateName->sigEditReturn.connect( sigc::mem_fun( *this, &UnitNaming::ok ));
59 
60  AddStandardButton( "~O~k" )->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &UnitNaming::ok )));
61 };
62 
64 {
65  publicName->EditBegin();
66  return ASC_PG_Dialog::RunModal();
67 }
68 
ASCString name
a name given by the user or the map creator
Context createContext(GameMap *gamemap)
int RunModal()
Definition: unitnaming.cpp:63
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
UnitNaming(ContainerBase *unit)
Definition: unitnaming.cpp:43
bool successful() const
ASCString privateName
a name given by the user which is only visible to him and his allies.
GameMap * getMap() const
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
PG_Button * AddStandardButton(const ASCString &name)
Definition: paradialog.cpp:516