File: unitnaming.cpp

package info (click to toggle)
asc 2.6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 82,860 kB
  • ctags: 26,395
  • sloc: cpp: 158,660; sh: 11,274; ansic: 6,878; makefile: 604; perl: 138
file content (68 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "unitnaming.h"
#include "../gamemap.h"
#include "../actions/renamecontainercommand.h"
#include "../contextutils.h"

bool UnitNaming::ok()
{
   if ( publicName->GetText() != unit->name || privateName->GetText() != unit->privateName ) {
      auto_ptr<RenameContainerCommand> rcc ( new RenameContainerCommand( unit ));
      rcc->setName( publicName->GetText(), privateName->GetText() );
      ActionResult res = rcc->execute( createContext( unit->getMap() ));
      if ( res.successful() ) 
         rcc.release();
   }
   QuitModal();
   return true;
}
      
bool UnitNaming::cancel()
{
   QuitModal();
   return true;
}

bool UnitNaming::line1completed()
{
   if ( privateName ) {
      privateName->EditBegin();
      return true;
   } else
      return false;
}
      
UnitNaming::UnitNaming ( ContainerBase* myUnit) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 300, 150), "Enter Names")
{
   unit = myUnit;
   
   int width = 90;
   new PG_Label( this, PG_Rect( border, 40, width, 20), "Public: ");
   
   int fieldwidth = Width() - 3 * border - width;
   publicName = new PG_LineEdit( this, PG_Rect( border*2 + width, 40, fieldwidth, 20));
   publicName->SetText( myUnit->name );
   publicName->sigEditReturn.connect( SigC::slot( *this, &UnitNaming::line1completed ));

   new PG_Label( this, PG_Rect( border, 70, width, 20), "Private: ");
   privateName = new PG_LineEdit( this, PG_Rect( border*2 + width, 70, fieldwidth, 20));
   privateName->SetText( myUnit->privateName);
   privateName->sigEditReturn.connect( SigC::slot( *this, &UnitNaming::ok ));

   AddStandardButton( "~O~k" )->sigClick.connect( SigC::slot( *this, &UnitNaming::ok ));
};

int UnitNaming::RunModal()
{
   publicName->EditBegin();
   return ASC_PG_Dialog::RunModal();
}