~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/editor/ui_menus/editor_tool_place_bob_options_menu.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2002-4 by the Widelands Development Team
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 */
 
19
 
 
20
#include "editorinteractive.h"
 
21
#include "editor_place_bob_tool.h"
 
22
#include "editor_tool_place_bob_options_menu.h"
 
23
#include "keycodes.h"
 
24
#include "map.h"
 
25
#include "system.h"
 
26
#include "ui_box.h"
 
27
#include "ui_button.h"
 
28
#include "ui_checkbox.h"
 
29
#include "ui_tabpanel.h"
 
30
#include "ui_textarea.h"
 
31
#include "world.h"
 
32
 
 
33
/*
 
34
=================================================
 
35
 
 
36
class Editor_Tool_Place_Bob_Options_Menu
 
37
 
 
38
=================================================
 
39
*/
 
40
 
 
41
/*
 
42
===========
 
43
Editor_Tool_Place_Bob_Options_Menu::Editor_Tool_Place_Bob_Options_Menu
 
44
 
 
45
constructor
 
46
===========
 
47
*/
 
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;
 
53
 
 
54
   m_pit=pit;
 
55
 
 
56
   const int space=5;
 
57
   const int xstart=5;
 
58
   const int ystart=15;
 
59
   const int yend=15;
 
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;
 
65
 
 
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);
 
70
 
 
71
 
 
72
   int width=0;
 
73
   int height=0;
 
74
   for(int j=0; j<nr_bobs; j++) {
 
75
      int w,h;
 
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(),
 
79
                              true), &w, &h);
 
80
      if(w>width) width=w;
 
81
      if(h>height) height=h;
 
82
   }
 
83
 
 
84
   box->set_inner_size((bobs_in_row)*(width+1+space)+xstart, (bobs_in_row)*(height+1+space)+ystart+yend);
 
85
 
 
86
   int ypos=ystart;
 
87
   int xpos=xstart;
 
88
   int cur_x=0;
 
89
   int i=0;
 
90
   while(i<nr_bobs) {
 
91
      if(cur_x==bobs_in_row) {
 
92
         cur_x=0;
 
93
         ypos=ystart;
 
94
         xpos=xstart;
 
95
         box->resize();
 
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);
 
98
      }
 
99
 
 
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));
 
103
 
 
104
      cb->set_size(width, height);
 
105
      cb->set_id(i);
 
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);
 
111
      xpos+=width+1+space;
 
112
      ++cur_x;
 
113
      ++i;
 
114
   }
 
115
   ypos+=height+1+space+5;
 
116
 
 
117
   m_tabpanel->activate(0);
 
118
   box->resize();
 
119
   m_tabpanel->resize();
 
120
}
 
121
 
 
122
/*
 
123
 * Cleanup
 
124
 */
 
125
Editor_Tool_Place_Bob_Options_Menu::~Editor_Tool_Place_Bob_Options_Menu(void) {
 
126
}
 
127
 
 
128
/*
 
129
===========
 
130
   void Editor_Tool_Place_Bob_Options_Menu::clicked()
 
131
 
 
132
this is called when one of the state boxes is toggled
 
133
===========
 
134
*/
 
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; }
 
138
 
 
139
   if(!multiselect) {
 
140
      int i=0;
 
141
      while(m_pit->get_nr_enabled()) {
 
142
         m_pit->enable(i++,false);
 
143
      }
 
144
      // Disable all checkboxes
 
145
      for(i=0; i<((int)m_checkboxes.size()); i++) {
 
146
         if(i==n) continue;
 
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);
 
150
      }
 
151
   }
 
152
 
 
153
   m_pit->enable(n,t);
 
154
   select_correct_tool();
 
155
}
 
156
 
 
157
/* do nothing */
 
158
void Editor_Tool_Place_Bob_Options_Menu::do_nothing(int n, bool t) {
 
159
}