~ubuntu-branches/ubuntu/vivid/berusky/vivid

« back to all changes in this revision

Viewing changes to src/editor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2011-08-27 08:09:19 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110827080919-1a7tyg1mm3ndg5sp
Tags: 1.3-1
* New upstream release.
* Switch to dpkg-source 3.0 (quilt) format.
* debian/berusky.6: Added.  Closes: #605982.
* debian/patches/02_endian.diff: Removed.
* debian/patches/03_arraysize.diff: Removed.
* debian/patches/06_newline.diff: Removed.
* debian/patches/08_backspace.diff: Removed.
* debian/patches/09_hints.diff: Removed.
* debian/patches/10_typos.diff: Added.  Closes: #616350.
* debian/berusky.desktop: Updated.  Closes: #616343.
* debian/control: Build-Depends: libgtk2.0-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <stdlib.h>
30
30
#include <time.h>
31
31
#include <string.h>
32
 
#include <curses.h>
33
 
#include <sys/wait.h>
34
32
#include <error.h>
35
33
#include <errno.h>
 
34
#include <stdio.h>
 
35
 
 
36
#include "portability.h"
 
37
 
 
38
#ifdef LINUX
 
39
#include <sys/wait.h>
 
40
#elif WINDOWS
 
41
#include <stdio.h>
 
42
#include <process.h>
 
43
#endif
36
44
 
37
45
#include "berusky.h"
38
46
#include "berusky_gui.h"
39
47
#include "main.h"
40
48
#include "editor.h"
41
49
 
42
 
ITEM_REPOSITORY *item_panel::p_repo = NULL;
43
 
 
44
 
// draws item panel, writes records to item_array and 
45
 
// returns number of written items
46
 
 
47
 
/* Rect is
48
 
  start_x;
49
 
  start_y;
50
 
 
51
 
  dx = dx*item_num;
52
 
  dy = dy*item_num;
53
 
*/
54
 
 
55
 
bool item_panel::panel_scroll_check(int direction)
56
 
{
57
 
  int tmp_item    = item_first    + item_increment * direction;
58
 
  int tmp_variant = variant_first + variant_increment * direction;
59
 
 
60
 
  if(tmp_item < 0 || tmp_variant < 0)
61
 
    return(FALSE);
62
 
 
63
 
  int i;
64
 
  for(i = 0; i < item_num; i++) {
65
 
    int item =    tmp_item + item_increment * i;
66
 
    int variant = tmp_variant + variant_increment * i;
67
 
  
68
 
    if(!p_repo->item_valid(item) || !p_repo->variant_valid(item,variant))
69
 
      break;
70
 
  }
71
 
  
72
 
  return(i == item_num);
73
 
}
74
 
 
75
 
void item_panel::panel_scroll(int direction, EDITOR_SELECTION *p_sel, bool redraw)
76
 
{
77
 
  if(panel_scroll_check(direction)) {
78
 
    item_first    += item_increment * direction;
79
 
    variant_first += variant_increment * direction;
80
 
    if(item_selected != NO_SELECTION) {
81
 
      item_return(item_selected,p_sel,direction);
82
 
    }
83
 
    if(redraw)
84
 
      publish();
85
 
  }
86
 
}
87
 
 
88
 
int  item_panel::item_return(tpos x, tpos y, EDITOR_SELECTION *p_sel)
 
50
ITEM_REPOSITORY *editor_panel::p_repo = NULL;
 
51
 
 
52
bool editor_panel::slot_return(tpos x, tpos y, int &slot)
89
53
{
90
54
  tpos sx = start_x;
91
55
  tpos sy = start_y;
92
56
 
93
 
  /* Panel is horizontal/vertical? */
 
57
  // Panel is horizontal/vertical?
94
58
  if(dx) { 
95
59
    sx += EDIT_ARROW_DX;
96
60
  } else {
98
62
  }  
99
63
 
100
64
  int i;
101
 
  for(i = 0; i < item_num; i++) {
102
 
  
 
65
  for(i = 0; i < panel_size_get(); i++) {
 
66
    if(!slot_valid(i))
 
67
      return(FALSE);
 
68
    
103
69
    tpos tx = sx + dx*i;
104
70
    tpos ty = sy + dy*i;
105
 
  
106
 
    int item =    item_first + item_increment*i;
107
 
    int variant = variant_first + variant_increment*i;
108
 
  
109
 
    if(!p_repo->item_valid(item) || !p_repo->variant_valid(item,variant))
110
 
      return(NO_SELECTION);
111
71
    
112
72
    if(INSIDE(tx, x, ITEM_SIZE_X) && INSIDE(ty, y, ITEM_SIZE_Y)) {
113
 
      if(p_sel) {
114
 
        p_sel->item = item;
115
 
        p_sel->variant = variant;      
116
 
      }
117
 
      return(i);
118
 
    }
119
 
  }
120
 
  
121
 
  return(NO_SELECTION);
122
 
}
123
 
 
124
 
int  item_panel::item_return(int selected_item, EDITOR_SELECTION *p_sel, int correction)
125
 
{
126
 
  int i;
127
 
 
128
 
  selected_item += correction;
129
 
  if(selected_item < 0)
130
 
    selected_item = 0;
131
 
  if(selected_item >= item_num)
132
 
    selected_item = item_num-1;
133
 
 
134
 
  for(i = 0; i < item_num; i++) {
135
 
  
136
 
    int item =    item_first + item_increment*i;
137
 
    int variant = variant_first + variant_increment*i;
138
 
  
139
 
    if(!p_repo->item_valid(item) || !p_repo->variant_valid(item,variant)) {
140
 
      return(i > 0 && i == selected_item ? i-1 : NO_SELECTION);
141
 
    }
142
 
    if(i == selected_item) {
143
 
      if(p_sel) {
144
 
        p_sel->item = item;
145
 
        p_sel->variant = variant;      
146
 
      }
147
 
      return(i);
148
 
    }
149
 
  }
150
 
 
151
 
  return(NO_SELECTION);
152
 
}
153
 
 
154
 
void item_panel::publish(void)
155
 
{
156
 
  RECT r;
157
 
 
158
 
  tpos sx = start_x;
159
 
  tpos sy = start_y;
160
 
 
161
 
  if(dx) {
162
 
    // Panel is horizontal
163
 
    sx += EDIT_ARROW_DX;
164
 
  
165
 
    r.x = sx;
166
 
    r.y = sy;
167
 
    r.w = dx*item_num;
168
 
    r.h = ITEM_SIZE_Y;  
169
 
  } else {
170
 
    // Panel is vertical
171
 
    sy += EDIT_ARROW_DY;
172
 
  
173
 
    r.x = sx;
174
 
    r.y = sy;
175
 
    r.w = ITEM_SIZE_X;
176
 
    r.h = dy*item_num;
177
 
  }
178
 
 
179
 
  p_grf->fill(&r,0);
180
 
 
181
 
  int i;
182
 
  for(i = 0; i < item_num; i++) {
183
 
  
184
 
    tpos x = sx + dx*i;
185
 
    tpos y = sy + dy*i;
186
 
  
187
 
    int item =    item_first + item_increment*i;
188
 
    int variant = variant_first + variant_increment*i;
189
 
  
190
 
    if(!p_repo->item_valid(item) || !p_repo->variant_valid(item,variant))
191
 
      break;
192
 
 
193
 
    #define COLOR_HIGHLIGHTED_R   0
194
 
    #define COLOR_HIGHLIGHTED_G   0
195
 
    #define COLOR_HIGHLIGHTED_B   200
196
 
    
197
 
    #define COLOR_SELECTED_R      175
198
 
    #define COLOR_SELECTED_G      0
199
 
    #define COLOR_SELECTED_B      0
200
 
    
201
 
    if(i == item_highlighted) {
202
 
      p_grf->fill(x,y,ITEM_SIZE_X,ITEM_SIZE_Y,p_grf->color_map(COLOR_HIGHLIGHTED_R,
203
 
                  COLOR_HIGHLIGHTED_G, COLOR_HIGHLIGHTED_B));
204
 
    }
205
 
    if(i == item_selected) {
206
 
      p_grf->fill(x,y,ITEM_SIZE_X,ITEM_SIZE_Y, p_grf->color_map(COLOR_SELECTED_R,
207
 
                  COLOR_SELECTED_G, COLOR_SELECTED_B));
208
 
    }
209
 
    
210
 
    p_repo->draw(x+CELL_SIZE_X,y+CELL_SIZE_X,item,variant,0);
211
 
  }
212
 
 
213
 
  p_grf->redraw_add(&r);
214
 
}
215
 
 
216
 
// draws controls for a panel
217
 
void item_panel::publish_controls(INPUT *p_input)
218
 
{
219
 
  RECT r;
220
 
 
221
 
  tpos sx = start_x;
222
 
  tpos sy = start_y;
223
 
 
224
 
  if(dx) {
225
 
    // Panel is horizontal
226
 
    sx += EDIT_ARROW_DX;
227
 
  
228
 
    r.x = sx;
229
 
    r.y = sy;
230
 
    r.w = dx*item_num;
 
73
      slot = i;
 
74
      return(TRUE);
 
75
    }
 
76
  }
 
77
  
 
78
  return(FALSE);
 
79
}
 
80
 
 
81
void editor_panel::panel_scroll(int direction, EDITOR_SELECTION *p_sel, bool redraw)
 
82
{  
 
83
  int panel_item_first = item_firts_get();  
 
84
  int panel_item_num = items_num_get();
 
85
  int item_new;
 
86
 
 
87
  if(direction == ITEMS_START) {
 
88
    item_new = 0;
 
89
  }
 
90
  else if(direction == ITEMS_END) {
 
91
    item_new = panel_item_num - panel_size_get();
 
92
  }
 
93
  else {  
 
94
    item_new = panel_item_first + direction;
 
95
  }
 
96
  
 
97
  if(item_new < 0) {
 
98
    item_new = 0;
 
99
  }
 
100
  
 
101
  if(item_new == panel_item_first) {
 
102
    // no scroll - don't change it
 
103
    return;
 
104
  }
 
105
  
 
106
  // Do we scroll the panel?
 
107
  if(panel_item_num > panel_size_get()) {
 
108
    if(item_new + panel_size_get() > panel_item_num) {
 
109
      item_new = panel_item_num - panel_size_get();
 
110
      assert(item_new >= panel_item_first);
 
111
    }
 
112
    if(item_new != panel_item_first)
 
113
      panel_set(item_new, p_sel, TRUE, redraw);
 
114
  }
 
115
}
 
116
 
 
117
RECT editor_panel::boundary_get(void)
 
118
{
 
119
  RECT r;
 
120
 
 
121
  tpos sx = start_x;
 
122
  tpos sy = start_y;
 
123
 
 
124
  if(dx) {
 
125
    // Panel is horizontal
 
126
    sx += EDIT_ARROW_DX;
 
127
  
 
128
    r.x = sx;
 
129
    r.y = sy;
 
130
    r.w = dx*panel_size_get();
231
131
    r.h = ITEM_SIZE_Y;
232
132
  } else {
233
133
    // Panel is vertical
236
136
    r.x = sx;
237
137
    r.y = sy;
238
138
    r.w = ITEM_SIZE_X;
239
 
    r.h = dy*item_num;
 
139
    r.h = dy*panel_size_get();
240
140
  }
241
141
 
 
142
  return r;
 
143
}
 
144
 
 
145
void editor_panel::register_controls_events(INPUT *p_input)
 
146
{
 
147
  RECT r = boundary_get();
 
148
 
242
149
  /* Scrolling (by mouse wheel) */
243
150
  p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(r,MASK_WHEEL_UP),
244
151
                      MEVENT_ACTIVATE_ONCE|MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS,
246
153
  p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(r,MASK_WHEEL_DOWN),
247
154
                      MEVENT_ACTIVATE_ONCE|MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS,
248
155
                      LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL, panel_handle, 1)));
249
 
 
 
156
                      
250
157
  /* Highlight of items in panel */
251
158
  p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(r),
252
159
                      MEVENT_MOUSE_EXTERNAL|MEVENT_MOUSE_IN, 
260
167
 
261
168
  if(dx) { // Panel is horizontal
262
169
    {
 
170
      RECT t = {start_x, start_y+CELL_SIZE_Y, EDIT_ARROW_DX, EDIT_ARROW_DY};
 
171
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
 
172
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
 
173
                          panel_handle,-1)));
 
174
    }
 
175
    {
 
176
      RECT t = {r.x+r.w,r.y+CELL_SIZE_Y, EDIT_ARROW_DX, EDIT_ARROW_DY};
 
177
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
 
178
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
 
179
                          panel_handle,1)));
 
180
    }
 
181
  } else { // Panel is vertical
 
182
    {
 
183
      RECT t = {start_x+CELL_SIZE_X, start_y, EDIT_ARROW_DX, EDIT_ARROW_DY};
 
184
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
 
185
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
 
186
                          panel_handle,-1)));
 
187
    }
 
188
    {
 
189
      RECT t = {r.x+CELL_SIZE_X, r.y+r.h, EDIT_ARROW_DX, EDIT_ARROW_DY};
 
190
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
 
191
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
 
192
                          panel_handle,1)));
 
193
    }
 
194
  }  
 
195
}
 
196
 
 
197
void editor_panel::slot_draw(int slot, int item, int variant)
 
198
{
 
199
  RECT r = boundary_get();
 
200
 
 
201
  tpos x = r.x + dx*slot;
 
202
  tpos y = r.y + dy*slot;
 
203
 
 
204
  p_grf->fill(x,y,ITEM_SIZE_X,ITEM_SIZE_Y,0);
 
205
 
 
206
  if(!p_repo->item_valid(item) || !p_repo->variant_valid(item,variant))
 
207
    return;
 
208
  
 
209
  #define COLOR_HIGHLIGHTED_R   0
 
210
  #define COLOR_HIGHLIGHTED_G   0
 
211
  #define COLOR_HIGHLIGHTED_B   200
 
212
  
 
213
  #define COLOR_SELECTED_R      175
 
214
  #define COLOR_SELECTED_G      0
 
215
  #define COLOR_SELECTED_B      0
 
216
  
 
217
  if(slot == panel_slot_highlighted) {
 
218
    p_grf->fill(x,y,ITEM_SIZE_X,ITEM_SIZE_Y,p_grf->color_map(COLOR_HIGHLIGHTED_R,
 
219
                COLOR_HIGHLIGHTED_G, COLOR_HIGHLIGHTED_B));
 
220
  }
 
221
  if(slot == panel_slot_selected) {
 
222
    p_grf->fill(x,y,ITEM_SIZE_X,ITEM_SIZE_Y, p_grf->color_map(COLOR_SELECTED_R,
 
223
                COLOR_SELECTED_G, COLOR_SELECTED_B));
 
224
  }
 
225
  
 
226
  p_repo->draw(x+CELL_SIZE_X,y+CELL_SIZE_X,item,variant,0);
 
227
}
 
228
 
 
229
void editor_panel::controls_draw(void)
 
230
{
 
231
  RECT r = boundary_get();
 
232
 
 
233
  if(dx) { // Panel is horizontal
 
234
    {
263
235
      p_grf->draw(EDIT_ARROW_LEFT,start_x,start_y+CELL_SIZE_Y);
264
236
      p_grf->redraw_add(EDIT_ARROW_LEFT,start_x,start_y+CELL_SIZE_Y);
265
 
      RECT t = {start_x, start_y+CELL_SIZE_Y, EDIT_ARROW_DX, EDIT_ARROW_DY};
266
 
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
267
 
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
268
 
                          panel_handle,-1)));
269
237
    }
270
238
    {
271
239
      p_grf->draw(EDIT_ARROW_RIGHT,r.x+r.w,r.y+CELL_SIZE_Y);
272
240
      p_grf->redraw_add(EDIT_ARROW_RIGHT,r.x+r.w,r.y+CELL_SIZE_Y);
273
 
      RECT t = {r.x+r.w,r.y+CELL_SIZE_Y, EDIT_ARROW_DX, EDIT_ARROW_DY};
274
 
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
275
 
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
276
 
                          panel_handle,1)));
277
241
    }
278
242
  } else { // Panel is vertical
279
243
    {
280
244
      p_grf->draw(EDIT_ARROW_UP,start_x+CELL_SIZE_X,start_y);
281
245
      p_grf->redraw_add(EDIT_ARROW_UP,start_x+CELL_SIZE_X,start_y);
282
 
      RECT t = {start_x+CELL_SIZE_X, start_y, EDIT_ARROW_DX, EDIT_ARROW_DY};
283
 
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
284
 
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
285
 
                          panel_handle,-1)));
286
246
    }
287
247
    {
288
248
      p_grf->draw(EDIT_ARROW_DOWN,r.x+CELL_SIZE_X,r.y+r.h);
289
249
      p_grf->redraw_add(EDIT_ARROW_DOWN,r.x+CELL_SIZE_X,r.y+r.h);
290
 
      RECT t = {r.x+CELL_SIZE_X, r.y+r.h, EDIT_ARROW_DX, EDIT_ARROW_DY};
291
 
      p_input->mevent_add(MOUSE_EVENT(MOUSE_STATE(t,MASK_BUTTON_LEFT),
292
 
                          MEVENT_MOUSE_IN|MEVENT_MOUSE_BUTTONS, LEVEL_EVENT(ED_LEVEL_IPANEL_SCROLL,
293
 
                          panel_handle,1)));
294
250
    }
295
251
  }  
296
252
}
297
253
 
 
254
/* Select the select item by variant panel
 
255
*/
 
256
void item_panel::item_select(EDITOR_SELECTION *p_sel)
 
257
{
 
258
  int slot = selected_slot_get();
 
259
  if(slot == NO_SELECTION)
 
260
    return;
 
261
  
 
262
  int selected_item = panel_item_first+slot;
 
263
  
 
264
  // Propagate the selected item to variant panel
 
265
  ((VARIANT_PANEL*)attached_panel_get())->panel_item_set(selected_item, FALSE);
 
266
  ((VARIANT_PANEL*)attached_panel_get())->panel_set(0, p_sel, FALSE, TRUE);
 
267
  ((VARIANT_PANEL*)attached_panel_get())->slot_select(0, p_sel, TRUE, TRUE);
 
268
}
 
269
 
 
270
void item_panel::panel_draw(void)
 
271
{
 
272
  RECT r = boundary_get();
 
273
 
 
274
  p_grf->fill(&r,0);
 
275
  int i;
 
276
  for(i = 0; i < panel_size_get(); i++) {
 
277
    slot_draw(i, panel_item_first + i, 0);
 
278
  }
 
279
  p_grf->redraw_add(&r);
 
280
 
 
281
  controls_draw();
 
282
}
 
283
 
 
284
void variant_panel::panel_draw(void)
 
285
{
 
286
  RECT r = boundary_get();
 
287
 
 
288
  p_grf->fill(&r,0);
 
289
  int i;
 
290
  for(i = 0; i < panel_size_get(); i++) {
 
291
    slot_draw(i, panel_item, panel_variant_first + i);
 
292
  }
 
293
  p_grf->redraw_add(&r);
 
294
 
 
295
  controls_draw();
 
296
}
 
297
 
298
298
editor_layer_config::editor_layer_config(void)
299
299
{
300
 
  
 
300
 
301
301
}
302
302
 
303
303
editor_gui::editor_gui(ITEM_REPOSITORY *p_repo_, DIR_LIST *p_dir_):
306
306
  p_repo(p_repo_),
307
307
  level(p_repo_), 
308
308
  console(&input,CONSOLE_X,CONSOLE_Y,CONSOLE_DX,CONSOLE_LINES),
309
 
  sel(&level)
 
309
  selected_editor_item(&level)
 
310
{
 
311
  editor_panel::set_up(p_repo_);
 
312
 
 
313
  ipanel[0] = new ITEM_PANEL(ITEMS_IN_PANEL, VERTICAL, 0, 0, PANEL_HANDLE_1);
 
314
  ipanel[1] = new VARIANT_PANEL(ITEMS_IN_PANEL, VERTICAL, ITEM_SIZE_X, 0, PANEL_HANDLE_2);
 
315
  ipanel[2] = new ITEM_PANEL(ITEMS_IN_PANEL, HORIZONTAL, 2*ITEM_SIZE_X, 0, PANEL_HANDLE_3);
 
316
  ipanel[3] = new VARIANT_PANEL(ITEMS_IN_PANEL, HORIZONTAL, 2*ITEM_SIZE_X, ITEM_SIZE_Y, PANEL_HANDLE_4);
 
317
 
 
318
  ipanel[0]->attached_panel_set(ipanel[1]);
 
319
  ipanel[2]->attached_panel_set(ipanel[3]);
 
320
 
 
321
  ipanel[1]->attached_panel_set(ipanel[0]);
 
322
  ipanel[3]->attached_panel_set(ipanel[2]);
 
323
 
 
324
  editor_reset();
 
325
}
 
326
 
 
327
editor_gui::~editor_gui(void)
 
328
{
 
329
  int i;
 
330
  for(i = 0; i < PANELS; i++) {    
 
331
    delete ipanel[i];
 
332
  }
 
333
}
 
334
 
 
335
void editor_gui::editor_reset(void)
310
336
{
311
337
  input.mevent_clear();
312
338
  input.events_wait(TRUE);
313
339
 
 
340
  draw_level = TRUE;
 
341
 
314
342
  // Clear whole screen
315
343
  p_grf->clear();
 
344
 
 
345
  int i;
 
346
  for(i = 0; i < PANELS; i++) {
 
347
    ipanel[i]->register_controls_events(&input);
 
348
  }
 
349
  level_config();
316
350
  
317
 
  // TODO -- predelat vsechno draw -> na konfigy (reset)
318
 
  level_config();  
319
 
  panel_reset();
 
351
  panel_draw();
320
352
  selection_draw();
321
353
  layer_menu_draw();
322
354
  layer_status_draw();
323
355
  level_draw();
324
356
  layer_active_set(ALL_LEVEL_LAYERS);
325
357
  side_menu_create();
326
 
  side_menu_update();
 
358
  side_menu_draw();
327
359
 
328
360
  level.back_max_set(background_num(p_dir));
329
361
}
330
362
 
331
 
editor_gui::~editor_gui(void)
332
 
{
333
 
 
334
 
}
335
 
 
336
363
// Panel interface
337
364
void editor_gui::panel_item_select(int panel, tpos x, tpos y)
338
365
{
339
366
  panel -= PANEL_HANDLE_1;
340
367
  assert(panel >= 0 && panel < PANELS);
341
368
 
 
369
  EDITOR_PANEL *p_attached = ipanel[panel]->attached_panel_get();
 
370
 
342
371
  int i;
343
372
  for(i = 0; i < PANELS; i++) {
344
 
    if(i == panel)
345
 
      ipanel[i].item_select(x,y,&sel);
346
 
    else
347
 
      ipanel[i].item_unselect();    
 
373
    if(p_attached != ipanel[i]) {
 
374
      ipanel[i]->slot_unselect(TRUE,TRUE);
 
375
    }
348
376
  }
 
377
 
 
378
  // Select the selection
 
379
  ipanel[panel]->slot_select(x,y,&selected_editor_item,TRUE,TRUE);
 
380
  
349
381
  // Draw the current selection
350
382
  selection_draw();
351
383
 
352
384
  // Set active layer
353
 
  layer_active_set(p_repo->item_get_layer(sel.item));
 
385
  layer_active_set(p_repo->item_get_layer(selected_editor_item.item));
354
386
}
355
387
 
356
388
void editor_gui::panel_item_highlight(int panel, tpos x, tpos y)
357
389
{
358
390
  panel -= PANEL_HANDLE_1;
359
391
  assert(panel >= 0 && panel < PANELS);
360
 
  ipanel[panel].item_highlight(x,y);
 
392
  ipanel[panel]->slot_highlight(x,y,TRUE);
361
393
}
362
394
 
363
 
void editor_gui::panel_reset(void)
 
395
void editor_gui::panel_draw(void)
364
396
{
365
 
  #define ITEMS_X_START   0
366
 
  #define ITEMS_Y_START   0
367
 
  #define ITEMS_X_DIFF    0
368
 
  #define ITEMS_Y_DIFF    35
369
 
  #define ITEMS_DX        (EDITOR_RESOLUTION_X-ITEMS_X_START)
370
 
  #define ITEMS_DY        (EDITOR_RESOLUTION_Y-ITEMS_Y_START)
371
 
 
372
 
  //-- dodelat tu listu
373
 
  #define ITEMS_IN_PANEL  12
374
 
 
375
 
  item_panel::set_up(p_repo);
376
 
 
377
 
  ipanel[0].set_up(ITEMS_IN_PANEL, VERTICAL, 0, 0, PANEL_HANDLE_1,ipanel+1);
378
 
  ipanel[0].item_increment = 1;
379
 
  ipanel[1].set_up(ITEMS_IN_PANEL, VERTICAL, ITEM_SIZE_X, 0, PANEL_HANDLE_2);
380
 
  ipanel[1].variant_increment = 1;
381
 
 
382
 
  ipanel[2].set_up(ITEMS_IN_PANEL, HORIZONTAL, 2*ITEM_SIZE_X, 0, PANEL_HANDLE_3, ipanel+3);
383
 
  ipanel[2].item_increment = 1;
384
 
  ipanel[3].set_up(ITEMS_IN_PANEL, HORIZONTAL, 2*ITEM_SIZE_X, ITEM_SIZE_Y, PANEL_HANDLE_4);
385
 
  ipanel[3].variant_increment = 1;
386
 
 
387
397
  int i;
388
398
  for(i = 0; i < PANELS; i++) {
389
 
    ipanel[i].publish();
390
 
    ipanel[i].publish_controls(&input);
 
399
    ipanel[i]->panel_draw();
391
400
  }
392
401
}
393
402
 
395
404
{
396
405
  panel -= PANEL_HANDLE_1;
397
406
  assert(panel >= 0 && panel < PANELS);
398
 
  ipanel[panel].panel_scroll(direction,&sel); 
 
407
  ipanel[panel]->panel_scroll(direction,&selected_editor_item,TRUE);
399
408
  selection_draw();
400
409
}
401
410
 
 
411
void editor_gui::panel_scroll_mouse(int direction)
 
412
{
 
413
  MOUSE_STATE *p_state = input.mouse_state_get();
 
414
  int panel = -1;
 
415
 
 
416
  int i;
 
417
  for(i = 0; i < PANELS; i++) {
 
418
    RECT r = ipanel[i]->boundary_get();
 
419
    if(p_state->in_rect(r)) {
 
420
      panel = i;
 
421
      break;
 
422
    }
 
423
  }
 
424
 
 
425
  if(panel != -1) {  
 
426
    panel_scroll(PANEL_HANDLE_1+panel, direction);
 
427
  }
 
428
}
 
429
 
402
430
/*
403
431
#define EDIT_ITEM_START_X        (EDIT_COORD_START_X)
404
432
#define EDIT_ITEM_START_Y        (EDIT_COORD_START_Y+EDIT_COORD_DY)
415
443
  p_font->alignment_set(LEFT);
416
444
  p_grf->fill(EDIT_ITEM_START_X,EDIT_ITEM_START_Y,EDIT_ITEM_DX,EDIT_ITEM_DY,0);
417
445
  p_font->print(NULL,EDIT_ITEM_START_X,EDIT_ITEM_START_Y,_("I:%d V:%d R:%d L:%d"),
418
 
                sel.item, sel.variant, sel.rotation, 
419
 
                p_repo->item_get_layer(sel.item));
 
446
                selected_editor_item.item, 
 
447
                selected_editor_item.variant, 
 
448
                selected_editor_item.rotation, 
 
449
                p_repo->item_get_layer(selected_editor_item.item));
420
450
  p_grf->redraw_add(EDIT_ITEM_START_X,EDIT_ITEM_START_Y,EDIT_ITEM_DX,EDIT_ITEM_DY);
421
451
 
422
452
  {
431
461
  
432
462
    p_grf->fill(&r,p_grf->color_map(COLOR_BACK_R, COLOR_BACK_G, COLOR_BACK_B));
433
463
    p_repo->draw(EDIT_ITEM_PICT_START_X+CELL_SIZE_X,EDIT_ITEM_PICT_START_Y+CELL_SIZE_Y,
434
 
                 sel.item, sel.variant, sel.rotation);
 
464
                 selected_editor_item.item,
 
465
                 selected_editor_item.variant,
 
466
                 selected_editor_item.rotation);
435
467
    p_grf->redraw_add(&r);
436
468
  }
437
469
  {
443
475
  
444
476
    p_grf->fill(&r,0);
445
477
    p_font->print(&dr,r.x,r.y,_("Item: %s\nVariation: %d\nRotation: %s"),
446
 
            p_repo->item_get_name(sel.item),
447
 
            sel.variant,
448
 
            p_repo->item_get_rotation(sel.rotation));
 
478
            p_repo->item_get_name(selected_editor_item.item),
 
479
            selected_editor_item.variant,
 
480
            p_repo->item_get_rotation(selected_editor_item.rotation));
449
481
    r.h = dr.h;
450
482
    p_grf->redraw_add(&r);
451
483
  }  
493
525
 
494
526
/* Side menu - general
495
527
*/
496
 
 
497
 
#define SIDE_MENU_X       (EDITOR_SCREEN_START_X+GAME_RESOLUTION_X+10)
498
 
#define SIDE_MENU_Y       (EDITOR_SCREEN_START_Y+100)
499
 
#define SIDE_MENU_DX      (EDITOR_RESOLUTION_X-SIDE_MENU_X)
500
 
#define SIDE_MENU_DY      (EDITOR_RESOLUTION_Y-SIDE_MENU_Y)
501
 
#define SIDE_MENU_X_DIFF   0
502
 
#define SIDE_MENU_Y_DIFF   35
503
 
 
 
528
#define SIDE_MENU_X         (EDITOR_SCREEN_START_X+GAME_RESOLUTION_X+10)
 
529
#define SIDE_MENU_Y         (EDITOR_SCREEN_START_Y+60)
 
530
#define SIDE_MENU_DX        (EDITOR_RESOLUTION_X-SIDE_MENU_X)
 
531
#define SIDE_MENU_DY        (EDITOR_RESOLUTION_Y-SIDE_MENU_Y)
 
532
#define SIDE_MENU_X_DIFF    0
 
533
#define SIDE_MENU_Y_DIFF    35
504
534
 
505
535
static char *side_menu[] = 
506
536
507
 
  _("(1) floor"),
508
 
  _("(2) items"),
509
 
  _("(3) players"),
510
 
  _("(4) all")
 
537
  _("help (f1)"),
 
538
  _("new level"),
 
539
  _("save (f2)"),
 
540
  _("save as (ct+f2)"),
 
541
  _("load (f3)"),
 
542
  _("quit (esc)"),
 
543
  _("run level (f9)"),
 
544
  _("undo (ctrl+u)"),
 
545
  _("redo (ctrl+r)"),
 
546
  _("rotate (shft+r)"),
 
547
  _("shade floor"),
 
548
  _("background (b)"),
511
549
};
512
550
 
513
551
void editor_gui::side_menu_create(void)
514
552
{
515
 
  p_font->print(NULL,SIDE_MENU_X, SIDE_MENU_Y, "Select layer:");
 
553
  p_font->print(NULL,SIDE_MENU_X, SIDE_MENU_Y, "Editor menu:");
516
554
 
517
555
  menu_item_set_pos(SIDE_MENU_X, SIDE_MENU_Y+SIDE_MENU_Y_DIFF);
518
556
  menu_item_set_diff(SIDE_MENU_X_DIFF, SIDE_MENU_Y_DIFF);
519
557
 
520
 
  menu_item_draw(side_menu[0], LEFT_NO_ARROW, TRUE, LEVEL_EVENT(ED_LEVEL_SELECT_LAYER,LAYER_FLOOR));
521
 
  menu_item_draw(side_menu[1], LEFT_NO_ARROW, TRUE, LEVEL_EVENT(ED_LEVEL_SELECT_LAYER,LAYER_ITEMS));
522
 
  menu_item_draw(side_menu[2], LEFT_NO_ARROW, TRUE, LEVEL_EVENT(ED_LEVEL_SELECT_LAYER,LAYER_PLAYER));
523
 
  menu_item_draw(side_menu[3], LEFT_NO_ARROW, TRUE, LEVEL_EVENT(ED_LEVEL_SELECT_LAYER,ALL_LEVEL_LAYERS));
 
558
  menu_item_draw(side_menu[0], LEFT, TRUE, LEVEL_EVENT(ED_HELP));
 
559
  menu_item_draw(side_menu[1], LEFT, TRUE, LEVEL_EVENT(ED_LEVEL_NEW));
 
560
  menu_item_draw(side_menu[2], LEFT, TRUE, LEVEL_EVENT(ED_LEVEL_SAVE));
 
561
  menu_item_draw(side_menu[3], LEFT, TRUE, LEVEL_EVENT(ED_LEVEL_SAVE_AS));
 
562
  menu_item_draw(side_menu[4], LEFT, TRUE, LEVEL_EVENT(ED_LEVEL_LOAD));
 
563
  menu_item_draw(side_menu[5], LEFT, TRUE, LEVEL_EVENT(ED_QUIT));
 
564
  menu_item_draw(side_menu[6], LEFT, TRUE, LEVEL_EVENT(ED_LEVEL_RUN));
 
565
  menu_item_draw(side_menu[7], LEFT, TRUE, LEVEL_EVENT(ED_UNDO));
 
566
  menu_item_draw(side_menu[9], LEFT, TRUE, LEVEL_EVENT(ED_ROTATE_SELECTION));
 
567
  menu_item_draw(side_menu[10],LEFT, TRUE, LEVEL_EVENT(ED_LEVEL_SHADER));
 
568
  menu_item_draw(side_menu[11],LEFT, TRUE, LEVEL_EVENT(ED_LEVEL_CHANGE_BACKGROUND));
524
569
 
525
570
  p_grf->redraw_add(SIDE_MENU_X,SIDE_MENU_Y,SIDE_MENU_DX,SIDE_MENU_DY);
526
571
}
528
573
#define SIDE_STATUS_X     (EDITOR_SCREEN_START_X+GAME_RESOLUTION_X+10)
529
574
#define SIDE_STATUS_Y     (EDITOR_SCREEN_START_Y)
530
575
#define SIDE_STATUS_DX    (EDITOR_RESOLUTION_X-SIDE_STATUS_X)
531
 
#define SIDE_STATUS_DY    100
 
576
#define SIDE_STATUS_DY    40
532
577
 
533
 
void editor_gui::side_menu_update(void)
 
578
void editor_gui::side_menu_draw(void)
534
579
{
535
580
  p_font->select(FONT_DEFAULT);
536
581
  p_font->alignment_set(LEFT);
558
603
      break;
559
604
  }
560
605
  if(p_act)
561
 
    p_font->print(NULL,SIDE_STATUS_X,SIDE_STATUS_Y,_("active layer:\n\n%s"),p_act);
 
606
    p_font->print(NULL,SIDE_STATUS_X,SIDE_STATUS_Y,_("edited layer:\n%s"),p_act);
562
607
  p_grf->redraw_add(SIDE_STATUS_X,SIDE_STATUS_Y,SIDE_STATUS_DX,SIDE_STATUS_DY);
563
608
}
564
609
 
579
624
 
580
625
  static char *layer_names[ALL_LEVEL_LAYERS] = 
581
626
  {   
582
 
    _("(1)Grid:"),
583
 
    _("(2)Floor:"),
584
 
    _("(3)Items:"),
585
 
    _("(4)Players:")
 
627
    _("Grid:"),
 
628
    _("Floor:"),
 
629
    _("Items:"),
 
630
    _("Players:")
586
631
  };
587
632
 
588
633
  static int layer_handle[] = 
658
703
void editor_gui::layer_active_set(int layer)
659
704
{
660
705
  config.lc.set_active(layer);  
661
 
  side_menu_update();
 
706
  side_menu_draw();
662
707
}
663
708
 
664
709
int editor_gui::layer_active_get(void)
751
796
  }
752
797
}
753
798
 
754
 
void editor_gui::level_load(char *p_file, bool force)
 
799
char *editor_gui::level_name_get(void)
 
800
{
 
801
  return(level_name);
 
802
}
 
803
 
 
804
void editor_gui::level_name_set(char *p_name)
 
805
{
 
806
  strncpy(level_name,p_name,MAX_FILENAME);  
 
807
  level_caption_update();
 
808
}
 
809
 
 
810
void editor_gui::level_load(char *p_file, int force)
755
811
{
756
812
  static char file[MAX_FILENAME] = "";
757
813
 
771
827
    }
772
828
  }
773
829
 
774
 
  // Save undo
775
 
  undo_store();  
776
 
 
777
 
  // Load given level
778
 
  char *p_paths[] = { p_dir->levels_user_get(), p_dir->cwd_get(), NULL };
779
 
 
780
 
  bool loaded = level.level_load(p_file,p_paths,sizeof(p_paths)/sizeof(p_paths[0]));
781
 
  if(loaded) {
782
 
    strncpy(level_name,p_file,MAX_FILENAME);
783
 
    level_edited_clear();
784
 
    level_caption_update();
785
 
  } else {
786
 
    console.print(_("Unable to load level %s"),p_file);
 
830
  // Do we have a valid filename?
 
831
  if(p_file[0]) {
 
832
    // Save undo
 
833
    undo_store();
 
834
  
 
835
    // Load given level
 
836
    const char *p_paths[] = { p_dir->levels_user_get(), p_dir->cwd_get(), NULL };
 
837
  
 
838
    bool loaded = level.level_load(p_file,p_paths,sizeof(p_paths)/sizeof(p_paths[0]));
 
839
    if(loaded) {
 
840
      level_name_set(p_file);
 
841
      level_edited_clear();
 
842
    } else {
 
843
      console.print(_("Unable to load level %s"),p_file);
 
844
    }
 
845
  
 
846
    // Clear internal name
 
847
    file[0] = '\0';
787
848
  }
788
 
 
789
 
  // Clear internal name
790
 
  file[0] = '\0';
791
849
}
792
850
 
793
851
void editor_gui::level_load_callback(void)
806
864
  }
807
865
}
808
866
 
809
 
void editor_gui::level_save_as(char *p_file, bool force)
 
867
void editor_gui::level_save_as(char *p_file, int force)
810
868
{
811
869
  static char file[MAX_FILENAME] = "";
812
870
  static int  force_saved = BOOL_UNDEFINED;
826
884
  }
827
885
 
828
886
  if(!force && level.level_exists(p_file)) {
829
 
    input_start(&editor_gui::level_save_as_callback, HANDLE_2, INPUT_BOOLEAN, _("file %s exists! overwrite?:"));
 
887
    input_start(&editor_gui::level_save_as_callback, HANDLE_2, INPUT_BOOLEAN, _("file %s exists! overwrite?:"),p_file);
830
888
    return;
831
 
  }  
832
 
 
833
 
  if(level.level_save(p_file)) {
834
 
    level_edited_clear();
835
 
  }
836
 
  else {
837
 
    console.print(_("Unable to save level %s"),p_file);
838
 
  }
839
 
 
840
 
  console.print(_("Saved as %s"),p_file);
 
889
  }
 
890
 
 
891
  // Do we have a corect filename?
 
892
  if(p_file[0]) {
 
893
    if(level.level_save(p_file)) {
 
894
      level_edited_clear();
 
895
      level_name_set(p_file);
 
896
    }
 
897
    else {
 
898
      console.print(_("Unable to save level %s"),p_file);
 
899
    }
 
900
    console.print(_("Saved as %s"),p_file);
 
901
  }
841
902
  file[0] = '\0';
842
903
  force_saved = BOOL_UNDEFINED;
843
904
}
858
919
  }  
859
920
}
860
921
 
861
 
void editor_gui::level_save(bool force)
 
922
void editor_gui::help_print_line(tpos x_pos, tpos &y_pos, char *p_key, char *p_name = NULL)
 
923
{
 
924
  p_font->print(NULL,x_pos,y_pos,p_key);
 
925
  if(p_name) {
 
926
    p_font->print(NULL,x_pos+EDIT_HELP_KEY_DX,y_pos,p_name);
 
927
  }
 
928
  y_pos += p_font->height_get();
 
929
  y_pos += EDIT_HELP_DY;
 
930
}
 
931
 
 
932
void editor_gui::help(void)
 
933
{
 
934
  p_grf->fill(0,0,EDITOR_RESOLUTION_X,EDITOR_RESOLUTION_Y,0);
 
935
  
 
936
  p_font->select(FONT_DEFAULT);
 
937
 
 
938
  tpos x_pos = EDIT_HELP_KEY_X;
 
939
  tpos y_pos = EDIT_HELP_START_Y;
 
940
 
 
941
  help_print_line(x_pos,y_pos,_("Keyboard control:"));
 
942
  y_pos += EDIT_HELP_DY;
 
943
  help_print_line(x_pos,y_pos,_("F1"),_("- Help"));
 
944
  help_print_line(x_pos,y_pos,_("ESC"),_("- Quit"));
 
945
  y_pos += EDIT_HELP_DY;
 
946
  help_print_line(x_pos,y_pos,_("CTRL+N"),_("- New level"));
 
947
  help_print_line(x_pos,y_pos,_("f2"),_("- Save level"));
 
948
  help_print_line(x_pos,y_pos,_("CTRL+F2"),_("- Save level as"));
 
949
  help_print_line(x_pos,y_pos,_("F3"),_("- Load level"));
 
950
  y_pos += EDIT_HELP_DY;
 
951
  help_print_line(x_pos,y_pos,_("F9"),_("- Run level"));
 
952
  y_pos += EDIT_HELP_DY;
 
953
  help_print_line(x_pos,y_pos,_("SHIFT+R"),_("- Rotate item"));
 
954
  help_print_line(x_pos,y_pos,_("CTRL+U"),_("- Undo"));
 
955
  help_print_line(x_pos,y_pos,_("CTRL+S"),_("- Shade level"));
 
956
  help_print_line(x_pos,y_pos,_("B"),_("- Background"));
 
957
  y_pos += EDIT_HELP_DY;
 
958
  help_print_line(x_pos,y_pos,_("1"),_("- Select floor layer"));
 
959
  help_print_line(x_pos,y_pos,_("2"),_("- Select items layer"));
 
960
  help_print_line(x_pos,y_pos,_("3"),_("- Select players layer"));
 
961
  help_print_line(x_pos,y_pos,_("4"),_("- Select all layer"));
 
962
  y_pos += EDIT_HELP_DY;
 
963
  help_print_line(x_pos,y_pos,_("CTRL+1"),_("- on/off background"));
 
964
  help_print_line(x_pos,y_pos,_("CTRL+2"),_("- on/off floor layer"));
 
965
  help_print_line(x_pos,y_pos,_("CTRL+3"),_("- on/off items layer"));
 
966
  help_print_line(x_pos,y_pos,_("CTRL+4"),_("- on/off players layer"));
 
967
 
 
968
  x_pos = EDIT_HELP_MOUSE_X;
 
969
  y_pos = EDIT_HELP_START_Y;
 
970
  help_print_line(x_pos,y_pos,_("Mouse control:"));
 
971
  y_pos += EDIT_HELP_DY;
 
972
  help_print_line(x_pos,y_pos,_("first"),_("- insert selected item"));
 
973
  help_print_line(x_pos,y_pos,_("third"),_("- clear selected cell"));
 
974
  y_pos += EDIT_HELP_DY;
 
975
  help_print_line(x_pos,y_pos,_("R+wheel"),_("- in place rotation"));
 
976
  help_print_line(x_pos,y_pos,_("V+wheel"),_("- in place variation"));
 
977
  y_pos += EDIT_HELP_DY;
 
978
  help_print_line(x_pos,y_pos,_("F+first"),_("- fill rect with item"));
 
979
  help_print_line(x_pos,y_pos,_("D+first"),_("- draw rect with item"));
 
980
  y_pos += EDIT_HELP_DY;
 
981
  help_print_line(x_pos,y_pos,_("F+third"),_("- clear solid rect"));
 
982
  help_print_line(x_pos,y_pos,_("D+third"),_("- clear empty rect"));
 
983
 
 
984
  x_pos = EDIT_HELP_MOUSE_X+70;
 
985
  y_pos += EDIT_HELP_DY*6;
 
986
  help_print_line(x_pos,y_pos,_("item panel mouse control:"));
 
987
  y_pos += EDIT_HELP_DY;
 
988
  help_print_line(x_pos,y_pos,_("wheel"),_("- scroll by one"));
 
989
  y_pos += EDIT_HELP_DY;
 
990
  help_print_line(x_pos,y_pos,_("PgUp"),_("- scroll page up"));
 
991
  help_print_line(x_pos,y_pos,_("PgDown"),_("- scroll page down"));
 
992
  y_pos += EDIT_HELP_DY;
 
993
  help_print_line(x_pos,y_pos,_("Home"),_("- first item"));
 
994
  help_print_line(x_pos,y_pos,_("End"),_("- last item"));
 
995
 
 
996
  p_grf->redraw_add(0,0,EDITOR_RESOLUTION_X,EDITOR_RESOLUTION_Y);
 
997
 
 
998
  menu_key_input.set((GUI_BASE *)this,(GUI_BASE_FUNC)&editor_gui::console_wait);
 
999
  console.input_start(INPUT_WAIT, NULL);  
 
1000
  
 
1001
  draw_level = FALSE;
 
1002
}
 
1003
 
 
1004
void editor_gui::help_quit(void)
 
1005
{
 
1006
  editor_reset();
 
1007
}
 
1008
 
 
1009
void editor_gui::level_save(int force)
862
1010
{
863
1011
  level_save_as(level_name,force);
864
1012
}
865
1013
 
866
1014
void editor_gui::level_cursor_set(tpos x, tpos y)
867
1015
{
868
 
  bool state;
869
 
  
 
1016
  bool state;  
870
1017
 
871
1018
  if((state = level.coord_in_level(x,y))) {
872
1019
    level.coord_to_cell(&x,&y);
882
1029
  if(level.selection_get()) {
883
1030
    undo_store();
884
1031
  
885
 
    tpos layer = p_repo->item_get_layer(sel.item);
 
1032
    tpos layer = p_repo->item_get_layer(selected_editor_item.item);
886
1033
  
887
1034
    bool rect = level.selection_rectangle_get();  
888
1035
    if(rect) {
890
1037
      tpos sx,sy,dx,dy;
891
1038
    
892
1039
      level.selection_rectangle_get(&sx,&sy,&dx,&dy);
893
 
      level.cell_set(sx, sy, dx, dy, layer, sel.item, sel.variant, sel.rotation, TRUE, fill);
 
1040
      level.cell_set(sx, sy, dx, dy, layer, 
 
1041
                     selected_editor_item.item, 
 
1042
                     selected_editor_item.variant, 
 
1043
                     selected_editor_item.rotation, 
 
1044
                     TRUE, fill);
894
1045
    
895
1046
      level.selection_rectangle_set(FALSE);
896
 
      console.print(_("Inserted item %d at %dx%d - %dx%d layer %d"),sel.item,sx,sy,dx,dy,layer);
 
1047
      console.print(_("Inserted item %d at %dx%d - %dx%d layer %d"),
 
1048
                    selected_editor_item.item,sx,sy,dx,dy,layer);
897
1049
    }
898
1050
    else {
899
1051
      tpos x, y;
900
1052
    
901
1053
      level.selection_get(&x, &y);
902
 
      level.cell_set(x, y, layer, sel.item, sel.variant, sel.rotation, TRUE);
 
1054
      level.cell_set(x, y, layer, 
 
1055
                     selected_editor_item.item, 
 
1056
                     selected_editor_item.variant, 
 
1057
                     selected_editor_item.rotation, TRUE);
903
1058
    
904
 
      console.print(_("Inserted item %d at %dx%d layer %d"),sel.item,x,y,layer);
 
1059
      console.print(_("Inserted item %d at %dx%d layer %d"),
 
1060
                    selected_editor_item.item,x,y,layer);
905
1061
    }
906
1062
  
907
1063
    level_edited_set();
964
1120
      if(type == ITEM_MODIFY) {
965
1121
        level.cell_modify_variation(x,y, layer, variant, TRUE, TRUE);
966
1122
        console.print(_("[Modify] Variating item at %dx%d layer %d"),x,y,layer);
967
 
      } 
 
1123
      }
968
1124
      else if(type == ITEM_SET) {
969
1125
        level.cell_set_variation(x,y, layer, variant, TRUE, TRUE);
970
1126
        console.print(_("[Set] Variating item at %dx%d layer %d"),x,y,layer);
1017
1173
 
1018
1174
void editor_gui::selection_rotate(int direction)
1019
1175
{
1020
 
  if(p_repo->item_can_rotate(sel.item)) {
1021
 
    ROTATE_ITEM(sel.rotation, direction);
 
1176
  if(p_repo->item_can_rotate(selected_editor_item.item)) {
 
1177
    ROTATE_ITEM(selected_editor_item.rotation, direction);
1022
1178
    selection_draw();
1023
1179
  } else {
1024
 
    console.print(_("Can't rotate item %d"),sel.item);
 
1180
    console.print(_("Can't rotate item %d"),selected_editor_item.item);
1025
1181
  }
1026
1182
}
1027
1183
 
1033
1189
  switch(ev.param_int_get(PARAM_0)) {
1034
1190
    case SCREEN_HANDLE_IN:
1035
1191
      p_queue->add(LEVEL_EVENT(ED_LEVEL_SET_CURSOR,ev.param_get(PARAM_1),ev.param_get(PARAM_2),ET(TRUE)));
1036
 
      p_queue->commit();  
 
1192
      p_queue->commit();
1037
1193
      break;
1038
1194
    case SCREEN_HANDLE_OUT:
1039
1195
      p_queue->add(LEVEL_EVENT(ED_LEVEL_SET_CURSOR,-1,-1,TRUE));
1045
1201
      if(button == BUTTON_LEFT)
1046
1202
        p_queue->add(LEVEL_EVENT(ED_LEVEL_DRAW_CURSOR_INSERT_ITEM));
1047
1203
      else if(button == BUTTON_MIDDLE)
1048
 
        ;        
 
1204
        ;
1049
1205
      else if(button == BUTTON_RIGHT)
1050
 
        p_queue->add(LEVEL_EVENT(ED_LEVEL_DRAW_CURSOR_CLEAR_ITEM));        
1051
 
      p_queue->commit();      
 
1206
        p_queue->add(LEVEL_EVENT(ED_LEVEL_DRAW_CURSOR_CLEAR_ITEM));
 
1207
      p_queue->commit();
1052
1208
      break;
1053
1209
    case SCREEN_HANDLE_ROTATE:
1054
 
      direction = (ev.param_int_get(PARAM_4) == WHEEL_UP) ? -1 : 1;  
 
1210
      direction = (ev.param_int_get(PARAM_4) == WHEEL_UP) ? -1 : 1;
1055
1211
      p_queue->add(LEVEL_EVENT(ED_LEVEL_SET_CURSOR,ev.param_get(PARAM_1),ev.param_get(PARAM_2)));
1056
1212
      p_queue->add(LEVEL_EVENT(ED_LEVEL_DRAW_CURSOR_ROTATE_ITEM, ITEM_MODIFY, direction));
1057
1213
      p_queue->commit();
1058
1214
      break;
1059
1215
    case SCREEN_HANDLE_VARIATE:
1060
 
      direction = (ev.param_int_get(PARAM_4) == WHEEL_UP) ? -1 : 1;    
 
1216
      direction = (ev.param_int_get(PARAM_4) == WHEEL_UP) ? -1 : 1;
1061
1217
      p_queue->add(LEVEL_EVENT(ED_LEVEL_SET_CURSOR,ev.param_get(PARAM_1),ev.param_get(PARAM_2)));
1062
1218
      p_queue->add(LEVEL_EVENT(ED_LEVEL_DRAW_CURSOR_VARIATE_ITEM,ITEM_MODIFY,direction));
1063
1219
      p_queue->commit();
1104
1260
  return_path(p_dir->tmp_get(), TMP_LEVEL, filename, MAX_FILENAME);
1105
1261
 
1106
1262
  if(level.level_save(filename)) {
1107
 
    bprintf("Saved as %s",filename);
 
1263
#ifdef LINUX
1108
1264
    int pid = fork();
1109
1265
    if(!pid) {
1110
1266
      char level_name[MAX_FILENAME];
1121
1277
      waitpid(pid,&status,0);
1122
1278
      bprintf("Pid %d done",pid);
1123
1279
    }
 
1280
#elif WINDOWS  
 
1281
    bprintf("Saved as %s",filename);
 
1282
    char level_name[MAX_FILENAME];
 
1283
    return_path(p_dir->tmp_get(), TMP_LEVEL, level_name, MAX_FILENAME);
 
1284
    bprintf("%s -u %s",p_dir->game_binary_get(),level_name);    
 
1285
    int ret = _spawnl( _P_WAIT, p_dir->game_binary_get(),p_dir->game_binary_get(),"-u",level_name,NULL);
 
1286
    if(ret == -1) {
 
1287
      bprintf("Error: %s",strerror(errno));
 
1288
    }
 
1289
#endif  
1124
1290
  }
1125
1291
}
1126
1292
 
1228
1394
        case EV_TEST:
1229
1395
          test();
1230
1396
          break;
1231
 
      
 
1397
 
 
1398
        case ED_HELP:
 
1399
          // Clear all waiting events
 
1400
          queue.clear();
 
1401
          tmp_queue.clear();
 
1402
        
 
1403
          // Print help page
 
1404
          help();        
 
1405
          break;
 
1406
        
1232
1407
        case ED_LEVEL_NEW:
1233
1408
          level_new(ev.param_int_get(PARAM_0));
1234
1409
          break;
1270
1445
        case ED_LEVEL_IPANEL_SCROLL:
1271
1446
          panel_scroll(ev.param_int_get(PARAM_0), ev.param_int_get(PARAM_1));
1272
1447
          break;
 
1448
        
 
1449
        case ED_LEVEL_MOUSE_PANEL_SCROLL:
 
1450
          panel_scroll_mouse(ev.param_int_get(PARAM_0));
 
1451
          break;
1273
1452
  
1274
1453
        case ED_LEVEL_LAYER:        
1275
1454
          layer_status_switch(ev.param_int_get(PARAM_0),(LAYER_STATE)(ev.param_int_get(PARAM_1)));
1287
1466
          undo_restore();
1288
1467
          break;
1289
1468
        case ED_REDO:
1290
 
          break;        
 
1469
          break;
1291
1470
        
1292
1471
        case ED_LEVEL_RUN:
1293
1472
          editor_run_level();
1339
1518
  
1340
1519
  } while(!queue.empty());
1341
1520
 
1342
 
  // Draw all changes    
1343
 
  level.draw();
 
1521
  // Draw all changes in level
 
1522
  if(draw_level) {
 
1523
    level.draw();
 
1524
  }
1344
1525
  level.flip();
1345
1526
 
1346
1527
  return(TRUE);
1445
1626
{
1446
1627
  menu_key_input.clear();
1447
1628
  console.input_stop();
1448
 
  (this->*console_callback)();
 
1629
  if(console_callback) {
 
1630
    (this->*console_callback)();
 
1631
  }
 
1632
}
 
1633
 
 
1634
/* Wait for a key
 
1635
*/
 
1636
void editor_gui::console_wait(MENU_STATE state, int data, int data1)
 
1637
 
1638
  switch(data) {
 
1639
    default:
 
1640
      help_quit();
 
1641
      input_stop(TRUE);
 
1642
      break;
 
1643
  }
1449
1644
}
1450
1645
 
1451
1646
// ----------------------------------------------------------------------
1452
1647
//  An editor console code
1453
1648
// ----------------------------------------------------------------------
1454
1649
 
1455
 
char * editor_console::boolean_yes = _("y");
1456
 
char * editor_console::boolean_no = _("n");
 
1650
const char * editor_console::boolean_yes = _("y");
 
1651
const char * editor_console::boolean_no = _("n");
1457
1652
 
1458
1653
editor_console::editor_console(INPUT *p_input_, tpos sx, tpos sy, tpos dx, int lines_)
1459
1654
{
1490
1685
  if(itype == INPUT_BOOLEAN) {
1491
1686
    sprintf(input_line_title+strlen(input_line_title)," (%s/%s) ",
1492
1687
            boolean_yes,boolean_no);
1493
 
  } else {
 
1688
  } 
 
1689
  else if(itype == INPUT_STRING) {
1494
1690
    sprintf(input_line_title+strlen(input_line_title)," ");
1495
1691
  }
 
1692
  else if(type == INPUT_WAIT) {
 
1693
  }
1496
1694
 
1497
1695
  p_input->block(TRUE);
1498
1696
  p_input->key_repeat(TRUE);
1503
1701
void editor_console::input_stop(bool redraw)
1504
1702
{  
1505
1703
  p_input->block(FALSE);
1506
 
  p_input->key_repeat(FALSE);  
 
1704
  p_input->key_repeat(FALSE);
1507
1705
 
1508
1706
  istate = INPUT_NONE;
1509
1707
  input_redraw();
1544
1742
      case INPUT_BOOLEAN:
1545
1743
        if(c == boolean_yes[0]) {
1546
1744
          input_boolean = TRUE;
1547
 
        }
 
1745
        }      
1548
1746
        else if(c == boolean_no[0]) {
1549
1747
          input_boolean = FALSE;
1550
1748
        }
1566
1764
 
1567
1765
void editor_console::input_redraw(void)
1568
1766
1569
 
  if(istate == INPUT_READY) {  
 
1767
  if(itype == INPUT_WAIT) {
 
1768
    // nothing here...
 
1769
  } 
 
1770
  else if(istate == INPUT_READY) {  
1570
1771
    p_grf->fill(ix_title,iy_title,w,CONSOLE_INPUT_LINE_HEIGHT,COLOR_MAP(0,0,255));
1571
1772
 
1572
1773
    p_font->select(FONT_DEFAULT);
1579
1780
    iy_input = iy_title;
1580
1781
      
1581
1782
    if(itype == INPUT_BOOLEAN) {
1582
 
      char *p_tmp;
 
1783
      const char *p_tmp;
1583
1784
    
1584
1785
      if(input_boolean == CONSOLE_BOOLEAN_NO_INPUT)
1585
1786
        p_tmp = "_";
1600
1801
  p_grf->redraw_add(ix_title,iy_title,w,CONSOLE_INPUT_LINE_HEIGHT);
1601
1802
}
1602
1803
 
1603
 
void editor_console::print(char *p_text,...)
 
1804
void editor_console::print(const char *p_text,...)
1604
1805
{
1605
1806
  strncpy(output_lines[0],output_lines[1],CONSOLE_MAX_INPUT_LINE);
1606
1807
  
1607
1808
  va_list   arguments;
1608
1809
  va_start(arguments,p_text);
1609
 
  vsnprintf(output_lines[1]+2,CONSOLE_MAX_INPUT_LINE,p_text,arguments);
 
1810
  vsnprintf(output_lines[1]+2,CONSOLE_MAX_INPUT_LINE-2,p_text,arguments);
1610
1811
  va_end(arguments);  
1611
1812
  output_lines[1][0] = '*';
1612
1813
  output_lines[1][1] = ' ';