source: golgotha/src/golg/editor/mode/e_tile.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 8.3 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "editor/e_state.hh"
10#include "editor/mode/e_tile.hh"
11#include "editor/e_state.hh"
12#include "editor/contedit.hh"
13#include "tile.hh"
14#include "editor/editor.hh"
15#include "height_info.hh"
16#include "gui/butbox.hh"
17#include "editor/editor.hh"
18#include "editor/e_res.hh"
19#include "map_vert.hh"
20
21g1_tile_params g1_e_tile;
22
23void g1_tile_mode::show_focus()
24{
25  if (active() && !focus_visible)
26  {
27    switch (g1_e_tile.get_minor_mode())
28    {
29      case g1_tile_params::FILL :
30      case g1_tile_params::PLACE :
31        c->save_and_put_cell();
32        break;     
33    }
34
35    focus_visible=i4_T;
36  }
37}
38
39
40void g1_tile_mode::hide_focus()
41{
42  if (active() && focus_visible)
43  {
44    switch (g1_e_tile.get_minor_mode())
45    {
46      case g1_tile_params::FILL :
47      case g1_tile_params::PLACE :
48        c->restore_cell();
49        break;     
50    }
51
52    focus_visible=i4_F;
53  }
54}
55void g1_tile_mode::mouse_down()
56{
57  if (g1_e_tile.get_minor_mode()==g1_tile_params::FILL)
58  {
59    g1_get_map()->mark_for_recalc(G1_RECALC_WATER_VERTS);
60    c->fill_map();
61  }
62  else if (g1_e_tile.get_minor_mode()==g1_tile_params::PLACE)
63  {
64    g1_get_map()->mark_for_recalc(G1_RECALC_WATER_VERTS);
65    c->change_map_cell();
66  }
67
68  g1_mode_handler::mouse_down();
69
70}
71
72void g1_tile_mode::mouse_move(sw32 mx, sw32 my)
73{
74 
75  switch (g1_e_tile.get_minor_mode())
76  {
77    case g1_tile_params::FILL :
78    case g1_tile_params::PLACE :
79    {
80      i4_float gx,gy, dx,dy;
81      if (!c->view_to_game(mx,my, gx,gy, dx,dy))
82        return;
83
84      if (gx<0 || gy<0 ||  gx>=c->get_map()->width() || gy>=c->get_map()->height())
85        return;
86
87      if ((w32)gx!=c->cell_x ||  (w32)gy!=c->cell_y)
88      {
89        hide_focus();
90        c->cell_x=(w32)gx;
91        c->cell_y=(w32)gy;     
92        show_focus();
93
94        // if the mouse button is down, replaced the saved cell
95        if (mouse_down_flag)
96          c->change_map_cell();
97      }     
98    } break;       
99  }
100
101  g1_mode_handler::mouse_move(mx,my);
102
103}
104
105
106g1_mode_handler::state g1_tile_mode::current_state()
107{
108  w8 remap[]={ ROTATE, ZOOM, OTHER, OTHER, DRAG_SELECT };
109  I4_ASSERT(g1_e_tile.minor_mode<=sizeof(remap), "state too big");
110  return (g1_mode_handler::state)remap[g1_e_tile.get_minor_mode()];
111}
112
113void g1_tile_mode::move_selected(i4_float xc, i4_float yc, i4_float zc,
114                                 sw32 mouse_x, sw32 mouse_y)
115{
116  vert_exact_z-=mouse_y/50.0;
117  int z_int=(sw32)(vert_exact_z/0.05);
118  c->move_selected_heights(z_int-move_pivot->height);
119
120}
121
122i4_bool g1_tile_mode::select_object(sw32 mx, sw32 my,
123                                    i4_float &ox, i4_float &oy, i4_float &oz,
124                                    select_modifier mod)
125{
126 
127
128  sw32 x,y;
129  g1_map_vertex_class *v=c->find_map_vertex(mx, my, x, y);
130
131  if (mod!=FOR_CURSOR_HINT)
132  {
133    g1_editor_instance.unmark_all_selected_verts_for_undo_save();
134    if (v)
135      v->set_need_undo(i4_T);
136
137    g1_editor_instance.mark_selected_verts_for_undo_save();
138    g1_editor_instance.add_undo(G1_MAP_SELECTED_VERTS);   
139  }
140
141
142  if (v)
143  {
144    ox=x; oy=y;
145    oz=c->get_map()->vertex(x,y)->get_height();
146
147    if (!v->is_selected() && mod==CLEAR_OLD_IF_NO_SELECTION)
148    {
149      c->clear_selected_verts();
150
151      c->changed();
152      c->refresh();
153    }
154
155    if (mod==CLEAR_OLD_IF_NO_SELECTION || mod==ADD_TO_OLD)
156    {
157      v->set_is_selected(i4_T);
158      c->changed();
159      c->refresh();
160
161      move_pivot=v;
162      vert_exact_z=c->get_map()->vertex(x,y)->get_height();
163    }     
164
165
166    return i4_T;
167  }
168  else
169  {
170    if (mod==CLEAR_OLD_IF_NO_SELECTION)
171      c->clear_selected_verts();
172
173    return i4_F;
174  }
175}
176
177void g1_tile_mode::select_objects_in_area(sw32 x1, sw32 y1, sw32 x2, sw32 y2,
178                                          select_modifier mod)
179{
180  c->select_verts_in_area(x1,y1,x2,y2, mod);
181}
182
183
184void g1_tile_mode::key_press(i4_key_press_event_class *kev)
185{
186  switch (kev->key)
187  {
188    case '1' :
189    {
190      hide_focus();
191      int lsize=g1_get_map()->width()*g1_get_map()->height();
192      g1_map_cell_class *c=g1_get_map()->cell(0,0);
193
194      for (int i=0; i<lsize; i++, c++)
195      {
196        int rot=c->get_rotation();
197        int remap[4]={1,0,3,2};   
198        rot=remap[rot];
199        c->set_rotation((g1_rotation_type)rot);
200      }
201      show_focus();
202    } break;
203
204    case '`' :
205    {
206      hide_focus();
207
208      g1_map_cell_class *cell=c->get_map()->cell(c->cell_x, c->cell_y);
209
210      g1_e_tile.set_cell_type(cell->type);
211      g1_e_tile.set_cell_rotation(cell->get_rotation());
212      g1_e_tile.set_mirrored(cell->mirrored());
213     
214      if (g1_e_tile.get_minor_mode()!=g1_tile_params::PLACE &&
215          g1_e_tile.get_minor_mode()!=g1_tile_params::FILL)
216        g1_e_tile.set_minor_mode(g1_tile_params::PLACE);
217
218      i4_warning("rotation = %d, mirrored = %d", cell->get_rotation(), cell->mirrored());
219     
220      show_focus();
221    } break;
222
223
224    case '\'':
225    {
226      hide_focus();
227      g1_e_tile.set_mirrored((i4_bool)!g1_e_tile.get_mirrored());
228
229      show_focus();
230    } break;
231
232    case '[' :
233    {
234      if (g1_e_tile.get_minor_mode()==g1_tile_params::PLACE)
235      {
236        if (g1_e_tile.get_cell_type()>0)
237        {
238          hide_focus();
239          g1_e_tile.set_cell_type(g1_e_tile.get_cell_type()-1);
240          show_focus();
241        }
242      }
243
244      if (g1_e_tile.get_minor_mode()==g1_tile_params::HEIGHT)
245        c->move_selected_heights(-1);
246
247    } break;
248
249    case ']' :
250    {
251      if (g1_e_tile.get_minor_mode()==g1_tile_params::PLACE)
252      {
253        if (g1_e_tile.get_cell_type()+1<g1_tile_man.total())
254        {
255          hide_focus();
256          g1_e_tile.set_cell_type(g1_e_tile.get_cell_type()+1);
257          show_focus();
258        }
259      }
260      if (g1_e_tile.get_minor_mode()==g1_tile_params::HEIGHT)
261        c->move_selected_heights(1);
262
263    } break;
264
265   
266    case '\\' :   
267    {
268      hide_focus();
269      if (g1_e_tile.get_cell_rotation()==G1_ROTATE_270)
270        g1_e_tile.set_cell_rotation(G1_ROTATE_0);
271      else     
272        g1_e_tile.set_cell_rotation((g1_rotation_type)(g1_e_tile.get_cell_rotation()+1));
273      show_focus();
274
275
276    } break;
277
278  }
279}
280
281g1_tile_mode::g1_tile_mode(g1_controller_edit_class *c)
282  : g1_mode_handler(c)
283{
284  c->cell_x=0;
285  c->cell_y=0;
286  focus_visible=i4_F;
287}
288
289
290g1_tile_params::g1_tile_params()
291{
292  vert_move_snap=1;
293  picker_mp_window=0;
294  picker=0;
295
296  minor_mode=ROTATE;
297  current_cell_type=0;
298  current_cell_rotation=G1_ROTATE_0;   
299  mirrored=i4_F;
300}
301
302
303void g1_tile_params::refresh_picker()
304{
305  if (picker.get())
306    picker->refresh();
307}
308
309
310void g1_tile_params::create_buttons(i4_parent_window_class *container)
311{
312  i4_button_box_class *box=new i4_button_box_class(&g1_edit_state);
313  char *rn[]={"tROTATE", "tZOOM", "tPLACE", "tFILL", "tHEIGHT", 0 };
314  w32 i=ROTATE;
315  for (char **a=rn; *a; a++, i++)
316    g1_edit_state.add_but(box, *a, 0, (i4_bool) i==minor_mode,
317                          new g1_set_minor_mode_event("TILE",i));
318
319  box->arrange_right_down();
320  container->add_child(0,0, box);
321}
322
323
324void g1_tile_params::cleanup()
325{
326  if (mp_window.get())
327  {
328    get_style()->close_mp_window(mp_window.get());
329    picker=0;
330  }
331}
332
333void g1_tile_params::open_picker()
334{
335  cleanup();
336
337  if (g1_e_tile.allow_picker_creation())
338  {
339    picker=new g1_tile_picker_class(get_style(), &picker_info, 0,0);
340    picker->create_windows();
341
342    i4_parent_window_class *mpw;
343    mpw=get_style()->create_mp_window(picker_info.win_x, picker_info.win_y,
344                                      picker->width(), picker->height(),
345                                      g1_ges("tile_pick_title"));
346
347    mpw->add_child(0,0, picker.get());
348    mp_window=mpw;
349
350  }
351}
Note: See TracBrowser for help on using the repository browser.