00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "team_box.h"
00023 #include "../include/action_handler.h"
00024 #include "../network/network.h"
00025 #include "../team/team.h"
00026 #include "../tool/i18n.h"
00027
00028 TeamBox::TeamBox(std::string _player_name, const Rectanglei& rect) :
00029 HBox(rect, false)
00030 {
00031 associated_team=NULL;
00032
00033 SetMargin(2);
00034
00035 team_logo = new PictureWidget( Rectanglei(0,0,48,48) );
00036 AddWidget(team_logo);
00037
00038 Box * tmp_box = new VBox(Rectanglei(0, 0, rect.GetSizeX()-80, 80), false);
00039 tmp_box->SetMargin(2);
00040 tmp_box->SetBorder(Point2i(0,0));
00041 team_name = new Label(" ", Rectanglei(0,0,rect.GetSizeX()-80,0),
00042 *Font::GetInstance(Font::FONT_NORMAL, Font::BOLD), dark_gray_color, false, false);
00043
00044 Box * tmp_player_box = new HBox(Rectanglei(0,0,0,Font::GetInstance(Font::FONT_SMALL)->GetHeight()), false);
00045 tmp_player_box->SetMargin(0);
00046 tmp_player_box->SetBorder(Point2i(0,0));
00047 tmp_player_box->AddWidget(new Label(_("Head commander"), Rectanglei(0,0,(rect.GetSizeX()-80)-100,0),
00048 *Font::GetInstance(Font::FONT_SMALL), dark_gray_color, false, false));
00049 player_name = new TextBox(_player_name, Rectanglei(0,0,100,0),
00050 *Font::GetInstance(Font::FONT_SMALL));
00051 tmp_player_box->AddWidget(player_name);
00052
00053 nb_characters = new SpinButton(_("Number of characters"), Rectanglei(0,0,0,0),
00054 6,1,2,10,
00055 dark_gray_color, false);
00056
00057 tmp_box->AddWidget(team_name);
00058 tmp_box->AddWidget(tmp_player_box);
00059 tmp_box->AddWidget(nb_characters);
00060
00061 AddWidget(tmp_box);
00062 }
00063
00064 void TeamBox::SetTeam(Team& _team, bool read_team_values)
00065 {
00066 associated_team=&_team;
00067
00068 team_logo->SetSurface(_team.flag);
00069 if (!_team.IsLocal() && !_team.IsLocalAI()) {
00070 team_name->SetText(_team.GetName() + " - " + _("Remote"));
00071 } else {
00072 team_name->SetText(_team.GetName());
00073 }
00074 team_logo->SetSurface(_team.flag);
00075
00076 if (read_team_values) {
00077 player_name->SetText(_team.GetPlayerName());
00078 nb_characters->SetValue(_team.GetNbCharacters());
00079 }
00080
00081 ForceRedraw();
00082 }
00083
00084 void TeamBox::ClearTeam()
00085 {
00086 associated_team=NULL;
00087
00088 ForceRedraw();
00089 }
00090
00091 Team* TeamBox::GetTeam() const
00092 {
00093 return associated_team;
00094 }
00095
00096 void TeamBox::Update(const Point2i &mousePosition,
00097 const Point2i &lastMousePosition,
00098 Surface& surf)
00099 {
00100 Box::Update(mousePosition, lastMousePosition, surf);
00101 if (need_redrawing) {
00102 Draw(mousePosition, surf);
00103 }
00104
00105 if (associated_team != NULL){
00106 WidgetList::Update(mousePosition, surf);
00107 } else {
00108 Redraw(*this, surf);
00109 }
00110
00111 need_redrawing = false;
00112 }
00113
00114 Widget* TeamBox::Clic (const Point2i &mousePosition, uint button)
00115 {
00116 if (associated_team != NULL) {
00117
00118 Widget* w = WidgetList::Clic(mousePosition, button);
00119
00120 if ( !associated_team->IsLocal() && !associated_team->IsLocalAI() )
00121 return NULL;
00122
00123 if (w == nb_characters || w == player_name) {
00124 if (network.IsConnected()) {
00125 ValidOptions();
00126 }
00127 return w;
00128 }
00129 }
00130 return NULL;
00131 }
00132
00133 void TeamBox::ValidOptions() const
00134 {
00135
00136 associated_team->SetNbCharacters(uint(nb_characters->GetValue()));
00137
00138
00139 associated_team->SetPlayerName(player_name->GetText());
00140
00141
00142 if (associated_team->IsLocal() || associated_team->IsLocalAI()) {
00143
00144
00145 if (player_name->GetText() == "AI-stupid")
00146 associated_team->SetLocalAI();
00147 else
00148 associated_team->SetLocal();
00149
00150
00151 if (network.IsConnected()) {
00152 Action* a = new Action(Action::ACTION_UPDATE_TEAM, associated_team->GetId());
00153 a->Push(associated_team->GetPlayerName());
00154 a->Push(int(associated_team->GetNbCharacters()));
00155 ActionHandler::GetInstance()->NewAction (a);
00156 }
00157 }
00158 }
00159
00160 bool TeamBox::IsLocal() const
00161 {
00162 if (associated_team != NULL && associated_team->IsLocal()) {
00163 return true;
00164 }
00165
00166 return false;
00167 }