2
* Copyright (C) 2002-4 by the Widelands Development Team
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include "editorinteractive.h"
21
#include "editor_place_bob_tool.h"
22
#include "editor_tool_place_bob_options_menu.h"
27
#include "ui_button.h"
28
#include "ui_checkbox.h"
29
#include "ui_tabpanel.h"
30
#include "ui_textarea.h"
34
=================================================
36
class Editor_Tool_Place_Bob_Options_Menu
38
=================================================
43
Editor_Tool_Place_Bob_Options_Menu::Editor_Tool_Place_Bob_Options_Menu
48
Editor_Tool_Place_Bob_Options_Menu::Editor_Tool_Place_Bob_Options_Menu(Editor_Interactive* parent, int index,
49
Editor_Place_Bob_Tool* pit, UIUniqueWindowRegistry* registry) :
50
Editor_Tool_Options_Menu(parent, index, registry, "Bobs Menu") {
51
const int max_items_in_tab=24;
52
const int min_items_in_tab=12;
60
int nr_bobs=get_parent()->get_map()->get_world()->get_nr_bobs();
61
int bobs_in_row=(int)(sqrt((float)nr_bobs));
62
if(bobs_in_row*bobs_in_row<nr_bobs) { bobs_in_row++; }
63
if(bobs_in_row>max_items_in_tab) bobs_in_row=max_items_in_tab;
64
if(bobs_in_row<min_items_in_tab) bobs_in_row=min_items_in_tab;
66
UITab_Panel* m_tabpanel=new UITab_Panel(this, 0, 0, 1);
67
m_tabpanel->set_snapparent(true);
68
UIBox* box=new UIBox(m_tabpanel, 0, 0, UIBox::Horizontal);
69
m_tabpanel->add(g_gr->get_picture(PicMod_Game, "pics/menu_tab_buildbig.png" , true), box);
74
for(int j=0; j<nr_bobs; j++) {
76
Bob_Descr* descr = get_parent()->get_map()->get_world()->get_bob_descr(j);
77
g_gr->get_picture_size(
78
g_gr->get_picture(PicMod_Game, descr->get_picture(),
81
if(h>height) height=h;
84
box->set_inner_size((bobs_in_row)*(width+1+space)+xstart, (bobs_in_row)*(height+1+space)+ystart+yend);
91
if(cur_x==bobs_in_row) {
96
box=new UIBox(m_tabpanel, 0, 0, UIBox::Horizontal);
97
m_tabpanel->add(g_gr->get_picture(PicMod_Game, "pics/menu_tab_buildbig.png" , true), box);
100
Bob_Descr* descr = get_parent()->get_map()->get_world()->get_bob_descr(i);
101
UICheckbox* cb= new UICheckbox(box, xpos, ypos,
102
g_gr->get_picture(PicMod_Game, descr->get_picture(), true));
104
cb->set_size(width, height);
106
cb->set_state(m_pit->is_enabled(i));
107
cb->changedtoid.set(this, &Editor_Tool_Place_Bob_Options_Menu::clicked);
108
m_checkboxes.push_back(cb);
109
box->add(cb, Align_Left);
110
box->add_space(space);
115
ypos+=height+1+space+5;
117
m_tabpanel->activate(0);
119
m_tabpanel->resize();
125
Editor_Tool_Place_Bob_Options_Menu::~Editor_Tool_Place_Bob_Options_Menu(void) {
130
void Editor_Tool_Place_Bob_Options_Menu::clicked()
132
this is called when one of the state boxes is toggled
135
void Editor_Tool_Place_Bob_Options_Menu::clicked(int n, bool t) {
136
bool multiselect = Sys_GetKeyState(KEY_LCTRL) | Sys_GetKeyState(KEY_RCTRL);
137
if(t==false && (!multiselect || m_pit->get_nr_enabled()==1)) { m_checkboxes[n]->set_state(true); return; }
141
while(m_pit->get_nr_enabled()) {
142
m_pit->enable(i++,false);
144
// Disable all checkboxes
145
for(i=0; i<((int)m_checkboxes.size()); i++) {
147
m_checkboxes[i]->changedtoid.set(this, &Editor_Tool_Place_Bob_Options_Menu::do_nothing);
148
m_checkboxes[i]->set_state(false);
149
m_checkboxes[i]->changedtoid.set(this, &Editor_Tool_Place_Bob_Options_Menu::clicked);
154
select_correct_tool();
158
void Editor_Tool_Place_Bob_Options_Menu::do_nothing(int n, bool t) {