5 |
* modify it under the terms of the GNU General Public License |
* modify it under the terms of the GNU General Public License |
6 |
* as published by the Free Software Foundation; either version 2 |
* as published by the Free Software Foundation; either version 2 |
7 |
* of the License, or (at your option) any later version. |
* of the License, or (at your option) any later version. |
8 |
* |
* |
9 |
* This program is distributed in the hope that it will be useful, |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
47 |
EditorDisplay(const ScreenArea &a); |
EditorDisplay(const ScreenArea &a); |
48 |
~EditorDisplay() {} |
~EditorDisplay() {} |
49 |
|
|
50 |
void tick(double dtime) {} |
void tick(double /*dtime*/) {} |
51 |
|
|
52 |
Model *make_model (const std::string &name); |
Model *make_model (const std::string &name); |
53 |
private: |
private: |
56 |
|
|
57 |
class IconBar : public gui::Container { |
class IconBar : public gui::Container { |
58 |
public: |
public: |
59 |
IconBar (const ScreenArea &a, int rows, int cols) |
IconBar (const ScreenArea &a, int rows, int cols) |
60 |
: m_area (a), m_rows (rows), m_cols(cols), |
: m_area (a), m_rows (rows), m_cols(cols), |
61 |
m_bgcolor (150,150,150) |
m_bgcolor (150,150,150) |
62 |
{} |
{} |
63 |
|
|
66 |
ScreenArea get_area() const { return m_area; } |
ScreenArea get_area() const { return m_area; } |
67 |
|
|
68 |
// Widget interface. |
// Widget interface. |
69 |
void draw (px::GC &gc, const px::Rect &area) { |
void draw (px::GC &gc, const px::Rect &area_) { |
70 |
set_color (gc, m_bgcolor); |
set_color (gc, m_bgcolor); |
71 |
box (gc, area); |
box (gc, area_); |
72 |
} |
} |
73 |
|
|
74 |
private: |
private: |
76 |
ScreenArea m_area; |
ScreenArea m_area; |
77 |
int m_rows, m_cols; |
int m_rows, m_cols; |
78 |
px::RGB m_bgcolor; |
px::RGB m_bgcolor; |
79 |
|
|
80 |
}; |
}; |
81 |
|
|
82 |
|
|
90 |
class Level { |
class Level { |
91 |
public: |
public: |
92 |
Level (); |
Level (); |
93 |
|
|
94 |
|
|
95 |
private: |
private: |
96 |
/* |
/* |
175 |
bool on_mousemotion (SDL_Event &e); |
bool on_mousemotion (SDL_Event &e); |
176 |
bool on_mousebutton (SDL_Event &e); |
bool on_mousebutton (SDL_Event &e); |
177 |
bool on_keydown (SDL_Event &e); |
bool on_keydown (SDL_Event &e); |
178 |
|
|
179 |
// Variables. |
// Variables. |
180 |
ScreenArea m_editarea; |
ScreenArea m_editarea; |
181 |
ScreenArea m_iconarea; |
ScreenArea m_iconarea; |
211 |
// Display engine for the editor |
// Display engine for the editor |
212 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
213 |
|
|
214 |
EditorDisplay::EditorDisplay(const ScreenArea &a) |
EditorDisplay::EditorDisplay(const ScreenArea &a) |
215 |
: CommonDisplay(a) |
: CommonDisplay(a) |
216 |
{} |
{} |
217 |
|
|
226 |
OBJFLAG_SignalRecipient = 0x2, |
OBJFLAG_SignalRecipient = 0x2, |
227 |
}; |
}; |
228 |
|
|
229 |
char *signal_names[] = { |
const char *signal_names[] = { |
230 |
"trigger", |
"trigger", |
231 |
"open", |
"open", |
232 |
"close", |
"close", |
236 |
"on / off" |
"on / off" |
237 |
}; |
}; |
238 |
|
|
239 |
|
|
240 |
class AvailableObjects { |
class AvailableObjects { |
241 |
public: |
public: |
242 |
AvailableObjects(); |
AvailableObjects(); |
288 |
video::GetScreen()->flush_updates(); |
video::GetScreen()->flush_updates(); |
289 |
|
|
290 |
SDL_Event e; |
SDL_Event e; |
291 |
if (SDL_PollEvent (&e)) |
if (SDL_PollEvent (&e)) |
292 |
dispatch_event (e); |
dispatch_event (e); |
293 |
|
|
294 |
SDL_Delay (10); |
SDL_Delay (10); |
295 |
} |
} |
296 |
} |
} |
297 |
|
|
298 |
void |
void |
299 |
Editor::set_mode (EditMode m) |
Editor::set_mode (EditMode m) |
300 |
{ |
{ |
301 |
m_editmode = m; |
m_editmode = m; |
302 |
} |
} |
303 |
|
|
304 |
void |
void |
305 |
Editor::set_floor (int x, int y, const std::string &name) |
Editor::set_floor (int x, int y, const std::string &name) |
306 |
{ |
{ |
307 |
m_display.set_floor (x, y, display::MakeModel (name)); |
m_display.set_floor (x, y, display::MakeModel (name)); |
308 |
} |
} |
309 |
|
|
310 |
void |
void |
311 |
Editor::set_item (int x, int y, const string &name) |
Editor::set_item (int x, int y, const string &name) |
312 |
{ |
{ |
313 |
m_display.set_item (x, y, display::MakeModel (name)); |
m_display.set_item (x, y, display::MakeModel (name)); |
314 |
} |
} |
315 |
|
|
316 |
void |
void |
317 |
Editor::set_stone (int x, int y, const string &name) |
Editor::set_stone (int x, int y, const string &name) |
318 |
{ |
{ |
319 |
m_display.set_stone (x, y, display::MakeModel (name)); |
m_display.set_stone (x, y, display::MakeModel (name)); |
330 |
m_cursor = m_display.add_effect(V2(), display::MakeModel("it-hammer")); |
m_cursor = m_display.add_effect(V2(), display::MakeModel("it-hammer")); |
331 |
} |
} |
332 |
|
|
333 |
void |
void |
334 |
Editor::set_cursor (const string &name) |
Editor::set_cursor (const string &name) |
335 |
{ |
{ |
336 |
m_cursor.replace_model (display::MakeModel (name)); |
m_cursor.replace_model (display::MakeModel (name)); |
337 |
} |
} |
338 |
|
|
339 |
|
|
340 |
void |
void |
341 |
Editor::scroll (double xoff, double yoff) |
Editor::scroll (double xoff, double yoff) |
342 |
{ |
{ |
343 |
DisplayEngine *engine = m_display.get_engine(); |
DisplayEngine *engine = m_display.get_engine(); |
356 |
video::ShowMouse(); |
video::ShowMouse(); |
357 |
} |
} |
358 |
|
|
359 |
bool |
bool |
360 |
Editor::on_mousemotion(SDL_Event &e) |
Editor::on_mousemotion(SDL_Event &e) |
361 |
{ |
{ |
362 |
DisplayEngine *engine = m_display.get_engine(); |
DisplayEngine *engine = m_display.get_engine(); |
367 |
return true; |
return true; |
368 |
} |
} |
369 |
|
|
370 |
bool |
bool |
371 |
Editor::on_mousebutton (SDL_Event &e) |
Editor::on_mousebutton (SDL_Event &e) |
372 |
{ |
{ |
373 |
if (e.button.type == SDL_MOUSEBUTTONDOWN) |
if (e.button.type == SDL_MOUSEBUTTONDOWN) |
374 |
{ |
{ |
375 |
DisplayEngine *engine = m_display.get_engine(); |
DisplayEngine *engine = m_display.get_engine(); |
376 |
V2 worldpos = engine->to_world (V2(e.motion.x, e.motion.y)); |
V2 worldpos = engine->to_world (V2(e.motion.x, e.motion.y)); |
395 |
return false; |
return false; |
396 |
} |
} |
397 |
|
|
398 |
bool |
bool |
399 |
Editor::on_keydown(SDL_Event &e) |
Editor::on_keydown(SDL_Event &e) |
400 |
{ |
{ |
401 |
switch (e.key.keysym.sym) { |
switch (e.key.keysym.sym) { |
402 |
case SDLK_ESCAPE: |
case SDLK_ESCAPE: |
403 |
m_quit_editor = true; |
m_quit_editor = true; |
404 |
break; |
break; |
405 |
case SDLK_LEFT: |
case SDLK_LEFT: |
406 |
if (e.key.keysym.mod & KMOD_CTRL) |
if (e.key.keysym.mod & KMOD_CTRL) |
407 |
scroll (-19, 0); |
scroll (-19, 0); |
408 |
else |
else |
409 |
scroll (-1, 0); |
scroll (-1, 0); |
410 |
break; |
break; |
411 |
case SDLK_RIGHT: |
case SDLK_RIGHT: |
412 |
if (e.key.keysym.mod & KMOD_CTRL) |
if (e.key.keysym.mod & KMOD_CTRL) |
413 |
scroll (+19, 0); |
scroll (+19, 0); |
414 |
else |
else |
415 |
scroll (+1, 0); |
scroll (+1, 0); |
416 |
break; |
break; |
417 |
case SDLK_DOWN: |
case SDLK_DOWN: |
418 |
if (e.key.keysym.mod & KMOD_CTRL) |
if (e.key.keysym.mod & KMOD_CTRL) |
419 |
scroll (0, +12); |
scroll (0, +12); |
420 |
else |
else |
421 |
scroll (0, +1); |
scroll (0, +1); |
422 |
break; |
break; |
423 |
case SDLK_UP: |
case SDLK_UP: |
424 |
if (e.key.keysym.mod & KMOD_CTRL) |
if (e.key.keysym.mod & KMOD_CTRL) |
425 |
scroll (0, -12); |
scroll (0, -12); |
426 |
else |
else |
427 |
scroll (0, -1); |
scroll (0, -1); |
428 |
break; |
break; |
429 |
case SDLK_HOME: |
case SDLK_HOME: |
430 |
scroll_abs (0,0); |
scroll_abs (0,0); |
431 |
break; |
break; |
432 |
|
|
433 |
case SDLK_a: |
case SDLK_a: |
434 |
if (e.key.keysym.mod & KMOD_SHIFT) |
if (e.key.keysym.mod & KMOD_SHIFT) |
435 |
; |
; |
436 |
else |
else |
437 |
set_mode(MODE_ACTORS); |
set_mode(MODE_ACTORS); |
438 |
break; |
break; |
439 |
case SDLK_f: |
case SDLK_f: |
440 |
if (e.key.keysym.mod & KMOD_SHIFT) |
if (e.key.keysym.mod & KMOD_SHIFT) |
441 |
; |
; |
442 |
else |
else |
443 |
set_mode(MODE_FLOOR); |
set_mode(MODE_FLOOR); |
444 |
break; |
break; |
445 |
case SDLK_i: |
case SDLK_i: |
446 |
if (e.key.keysym.mod & KMOD_SHIFT) |
if (e.key.keysym.mod & KMOD_SHIFT) |
447 |
; |
; |
448 |
else |
else |
449 |
set_mode(MODE_ITEMS); |
set_mode(MODE_ITEMS); |
450 |
break; |
break; |
451 |
case SDLK_s: |
case SDLK_s: |
452 |
if (e.key.keysym.mod & KMOD_SHIFT) |
if (e.key.keysym.mod & KMOD_SHIFT) |
453 |
; |
; |
454 |
else |
else |
455 |
set_mode (MODE_STONES); |
set_mode (MODE_STONES); |