#include <map_selection_box.h>
Inheritance diagram for MapSelectionBox:
Public Member Functions | |
MapSelectionBox (const Rectanglei &rect, bool _display_only) | |
void | ValidMapSelection () |
void | ChangeMapCallback () |
Widget * | Clic (const Point2i &mousePosition, uint button) |
Private Member Functions | |
void | ChangeMapDelta (int delta_index) |
void | ChangeMap (int index) |
Private Attributes | |
uint | selected_map_index |
bool | display_only |
PictureWidget * | map_preview_selected |
PictureWidget * | map_preview_before |
PictureWidget * | map_preview_before2 |
PictureWidget * | map_preview_after |
PictureWidget * | map_preview_after2 |
Label * | map_name_label |
Label * | map_author_label |
Button * | bt_map_plus |
Button * | bt_map_minus |
Definition at line 30 of file map_selection_box.h.
MapSelectionBox::MapSelectionBox | ( | const Rectanglei & | rect, | |
bool | _display_only | |||
) |
Definition at line 27 of file map_selection_box.cpp.
00027 : 00028 HBox(rect, true) 00029 { 00030 display_only = _display_only; 00031 00032 Profile *res = resource_manager.LoadXMLProfile( "graphism.xml",false); 00033 00034 AddWidget(new PictureWidget(Rectanglei(0,0,46,100), "menu/map_label")); 00035 00036 // PreviousMap/NextMap buttons 00037 bt_map_plus = new Button(Point2i(0, 0), res, "menu/big_plus", false); 00038 bt_map_minus = new Button(Point2i(0, 0), res, "menu/big_minus", false); 00039 00040 resource_manager.UnLoadXMLProfile(res); 00041 00042 Box * tmp_map_box = new VBox( Rectanglei(0, 0, 00043 rect.GetSizeX()-63, 0), false); 00044 tmp_map_box->SetBorder( Point2i(0,0) ); 00045 tmp_map_box->SetMargin(0); 00046 00047 // compute margin width between previews 00048 uint map_preview_height = rect.GetSizeY() -2*10 -40; 00049 00050 // Previews 00051 Box* previews_box = new HBox( Rectanglei(0, 0, 0, map_preview_height+10 ), false); 00052 previews_box->SetBorder( Point2i(10,0) ); 00053 00054 // compute margin width between previews 00055 uint map_preview_width = map_preview_height*4/3; 00056 uint total_width_previews = map_preview_width + map_preview_width*3; 00057 00058 uint margin = 0; 00059 00060 if ( uint(tmp_map_box->GetSizeX() - 20) > uint(total_width_previews + bt_map_plus->GetSizeX() + bt_map_minus->GetSizeX())) { 00061 margin = (tmp_map_box->GetSizeX() - 20 - 00062 (total_width_previews + bt_map_plus->GetSizeX() + bt_map_minus->GetSizeX()) ) / 6; 00063 } 00064 00065 if (margin < 5) { 00066 margin = 5; 00067 uint total_size_wo_margin = tmp_map_box->GetSizeX() - 20 - 6*margin - bt_map_plus->GetSizeX() - bt_map_minus->GetSizeX(); 00068 map_preview_width = (total_size_wo_margin)/4; // <= total = w + 4*(3/4)w 00069 map_preview_height = 3/4 * map_preview_width; 00070 } 00071 00072 previews_box->SetMargin(margin); 00073 00074 if (!display_only) { 00075 previews_box->AddWidget(bt_map_minus); 00076 } else { 00077 previews_box->AddWidget(new NullWidget(*bt_map_minus)); 00078 } 00079 00080 map_preview_before2 = new PictureWidget(Rectanglei(0, 0, map_preview_width *3/4, map_preview_height*3/4)); 00081 previews_box->AddWidget(map_preview_before2); 00082 00083 map_preview_before = new PictureWidget(Rectanglei(0, 0, map_preview_width *3/4, map_preview_height*3/4)); 00084 previews_box->AddWidget(map_preview_before); 00085 00086 // Selected map... 00087 map_preview_selected = new PictureWidget(Rectanglei(0, 0, map_preview_width, map_preview_height)); 00088 previews_box->AddWidget(map_preview_selected); 00089 00090 map_preview_after = new PictureWidget(Rectanglei(0, 0, map_preview_width *3/4, map_preview_height*3/4)); 00091 previews_box->AddWidget(map_preview_after); 00092 00093 map_preview_after2 = new PictureWidget(Rectanglei(0, 0, map_preview_width *3/4, map_preview_height*3/4)); 00094 previews_box->AddWidget(map_preview_after2); 00095 00096 if (!display_only) { 00097 previews_box->AddWidget(bt_map_plus); 00098 }else { 00099 previews_box->AddWidget(new NullWidget(*bt_map_plus)); 00100 } 00101 00102 tmp_map_box->AddWidget(previews_box); 00103 00104 if (display_only) { 00105 map_preview_before2->Disable(); 00106 map_preview_before->Disable(); 00107 map_preview_after->Disable(); 00108 map_preview_after2->Disable(); 00109 } 00110 00111 00112 // Map information 00113 map_name_label = new Label("Map", Rectanglei(0,0,0,0), *Font::GetInstance(Font::FONT_SMALL, Font::BOLD), dark_gray_color, true, false); 00114 tmp_map_box->AddWidget(map_name_label); 00115 00116 map_author_label = new Label("Author", Rectanglei(0,0,0,0), *Font::GetInstance(Font::FONT_SMALL), dark_gray_color, true, false); 00117 tmp_map_box->AddWidget(map_author_label); 00118 00119 AddWidget(tmp_map_box); 00120 00121 // Load Maps' list 00122 std::sort(MapsList::GetInstance()->lst.begin(), MapsList::GetInstance()->lst.end(), compareMaps); 00123 ChangeMap(MapsList::GetInstance()->GetActiveMapIndex()); 00124 }
Here is the call graph for this function:
void MapSelectionBox::ChangeMap | ( | int | index | ) | [private] |
Definition at line 135 of file map_selection_box.cpp.
00136 { 00137 if (index < 0 || index > int(MapsList::GetInstance()->lst.size() - 1)) return; 00138 00139 selected_map_index = index; 00140 00141 // Callback other network players 00142 if(network.IsServer()) 00143 { 00144 ActionHandler::GetInstance()->NewAction (new Action(Action::ACTION_SET_MAP, 00145 MapsList::GetInstance()->lst[selected_map_index].ReadName())); 00146 } 00147 00148 // Set Map information 00149 map_preview_selected->SetSurface(MapsList::GetInstance()->lst[selected_map_index].ReadPreview(), true); 00150 map_name_label->SetText(MapsList::GetInstance()->lst[selected_map_index].ReadName()); 00151 map_author_label->SetText(MapsList::GetInstance()->lst[selected_map_index].ReadAuthorInfo()); 00152 00153 // Set previews 00154 if (selected_map_index > 0) 00155 map_preview_before->SetSurface(MapsList::GetInstance()->lst[selected_map_index-1].ReadPreview(), true); 00156 else 00157 map_preview_before->SetNoSurface(); 00158 00159 if (selected_map_index > 1) 00160 map_preview_before2->SetSurface(MapsList::GetInstance()->lst[selected_map_index-2].ReadPreview(), true); 00161 else 00162 map_preview_before2->SetNoSurface(); 00163 00164 if (selected_map_index+1 < MapsList::GetInstance()->lst.size() ) 00165 map_preview_after->SetSurface(MapsList::GetInstance()->lst[selected_map_index+1].ReadPreview(), true); 00166 else 00167 map_preview_after->SetNoSurface(); 00168 00169 if (selected_map_index+2 < MapsList::GetInstance()->lst.size() ) 00170 map_preview_after2->SetSurface(MapsList::GetInstance()->lst[selected_map_index+2].ReadPreview(), true); 00171 else 00172 map_preview_after2->SetNoSurface(); 00173 }
Here is the call graph for this function:
Here is the caller graph for this function:
void MapSelectionBox::ChangeMapCallback | ( | ) |
Definition at line 203 of file map_selection_box.cpp.
00204 { 00205 int index = MapsList::GetInstance()->GetActiveMapIndex(); 00206 ChangeMap(index); 00207 }
Here is the call graph for this function:
Here is the caller graph for this function:
void MapSelectionBox::ChangeMapDelta | ( | int | delta_index | ) | [private] |
Definition at line 126 of file map_selection_box.cpp.
00127 { 00128 assert(!display_only); 00129 00130 int tmp = selected_map_index + delta_index; 00131 00132 ChangeMap(tmp); 00133 }
Here is the call graph for this function:
Here is the caller graph for this function:
Reimplemented from Box.
Definition at line 175 of file map_selection_box.cpp.
00176 { 00177 if (display_only) return NULL; 00178 00179 if (!Contains(mousePosition)) return NULL; 00180 00181 if (button == SDL_BUTTON_LEFT && map_preview_before2->Contains(mousePosition) ) { 00182 ChangeMapDelta(-2); 00183 } else if ( (button == SDL_BUTTON_LEFT && bt_map_minus->Contains(mousePosition)) 00184 || (button == SDL_BUTTON_LEFT && map_preview_before->Contains(mousePosition)) 00185 || (button == SDL_BUTTON_WHEELUP )) { 00186 ChangeMapDelta(-1); 00187 } else if ( (button == SDL_BUTTON_LEFT && bt_map_plus->Contains(mousePosition)) 00188 || (button == SDL_BUTTON_LEFT && map_preview_after->Contains(mousePosition)) 00189 || (button == SDL_BUTTON_WHEELDOWN)) { 00190 ChangeMapDelta(+1); 00191 } else if (map_preview_after2->Contains(mousePosition) ) { 00192 ChangeMapDelta(+2); 00193 } 00194 00195 return NULL; 00196 }
Here is the call graph for this function:
void MapSelectionBox::ValidMapSelection | ( | ) |
Definition at line 198 of file map_selection_box.cpp.
00199 { 00200 MapsList::GetInstance()->SelectMapByIndex(selected_map_index); 00201 }
Here is the call graph for this function:
Here is the caller graph for this function:
Button * MapSelectionBox::bt_map_minus [private] |
Definition at line 42 of file map_selection_box.h.
Button* MapSelectionBox::bt_map_plus [private] |
Definition at line 42 of file map_selection_box.h.
bool MapSelectionBox::display_only [private] |
Definition at line 34 of file map_selection_box.h.
Label* MapSelectionBox::map_author_label [private] |
Definition at line 41 of file map_selection_box.h.
Label* MapSelectionBox::map_name_label [private] |
Definition at line 40 of file map_selection_box.h.
PictureWidget* MapSelectionBox::map_preview_after [private] |
Definition at line 38 of file map_selection_box.h.
PictureWidget * MapSelectionBox::map_preview_after2 [private] |
Definition at line 38 of file map_selection_box.h.
PictureWidget* MapSelectionBox::map_preview_before [private] |
Definition at line 37 of file map_selection_box.h.
PictureWidget * MapSelectionBox::map_preview_before2 [private] |
Definition at line 37 of file map_selection_box.h.
Definition at line 36 of file map_selection_box.h.
uint MapSelectionBox::selected_map_index [private] |
Definition at line 33 of file map_selection_box.h.