| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "LevelInput.h" |
| 10 |
|
| 11 |
#include "Level.h" |
| 12 |
#include "Keymap.h" |
| 13 |
|
| 14 |
#include "KeyStroke.h" |
| 15 |
#include "OptionAgent.h" |
| 16 |
#include "MenuOptions.h" |
| 17 |
#include "SubTitleAgent.h" |
| 18 |
|
| 19 |
//----------------------------------------------------------------- |
| 20 |
LevelInput::LevelInput(Level *level) |
| 21 |
: GameInput(level) |
| 22 |
{ |
| 23 |
m_keymap->registerKey(KeyStroke(SDLK_SPACE, KMOD_NONE), |
| 24 |
KeyDesc(KEY_SWITCH, "switch")); |
| 25 |
m_keymap->registerKey(KeyStroke(SDLK_F2, KMOD_NONE), |
| 26 |
KeyDesc(KEY_SAVE, "save")); |
| 27 |
m_keymap->registerKey(KeyStroke(SDLK_F3, KMOD_NONE), |
| 28 |
KeyDesc(KEY_LOAD, "load")); |
| 29 |
m_keymap->registerKey(KeyStroke(SDLK_BACKSPACE, KMOD_NONE), |
| 30 |
KeyDesc(KEY_RESTART, "restart")); |
| 31 |
m_keymap->registerKey(KeyStroke(SDLK_F5, KMOD_NONE), |
| 32 |
KeyDesc(KEY_SHOW_STEPS, "show number of steps")); |
| 33 |
|
| 34 |
KeyDesc undo = KeyDesc(KEY_UNDO, "undo"); |
| 35 |
m_keymap->registerKey(KeyStroke(SDLK_MINUS, KMOD_NONE), undo); |
| 36 |
m_keymap->registerKey(KeyStroke(SDLK_KP_MINUS, KMOD_NONE), undo); |
| 37 |
|
| 38 |
KeyDesc redo = KeyDesc(KEY_REDO, "redo"); |
| 39 |
m_keymap->registerKey(KeyStroke(SDLK_PLUS, KMOD_NONE), redo); |
| 40 |
m_keymap->registerKey(KeyStroke(SDLK_EQUALS, KMOD_NONE), redo); |
| 41 |
m_keymap->registerKey(KeyStroke(SDLK_KP_PLUS, KMOD_NONE), redo); |
| 42 |
} |
| 43 |
//----------------------------------------------------------------- |
| 44 |
Level * |
| 45 |
LevelInput::getLevel() |
| 46 |
{ |
| 47 |
return dynamic_cast<Level*>(m_state); |
| 48 |
} |
| 49 |
//----------------------------------------------------------------- |
| 50 |
void |
| 51 |
LevelInput::specKey(int keyIndex) |
| 52 |
{ |
| 53 |
switch (keyIndex) { |
| 54 |
case KEY_SWITCH: |
| 55 |
if (!getLevel()->isActing()) { |
| 56 |
getLevel()->switchFish(); |
| 57 |
} |
| 58 |
break; |
| 59 |
case KEY_SAVE: |
| 60 |
if (!getLevel()->isActing()) { |
| 61 |
getLevel()->action_save(); |
| 62 |
} |
| 63 |
break; |
| 64 |
case KEY_LOAD: |
| 65 |
if (!getLevel()->isShowing()) { |
| 66 |
getLevel()->action_load(); |
| 67 |
} |
| 68 |
break; |
| 69 |
case KEY_RESTART: |
| 70 |
getLevel()->interruptShow(); |
| 71 |
getLevel()->action_restart(1); |
| 72 |
break; |
| 73 |
case KEY_UNDO: |
| 74 |
if (!getLevel()->isShowing()) { |
| 75 |
getLevel()->action_undo(1); |
| 76 |
} |
| 77 |
break; |
| 78 |
case KEY_REDO: |
| 79 |
if (!getLevel()->isShowing()) { |
| 80 |
getLevel()->action_undo(-1); |
| 81 |
} |
| 82 |
break; |
| 83 |
case KEY_SHOW_STEPS: |
| 84 |
toggleParam("show_steps"); |
| 85 |
break; |
| 86 |
default: |
| 87 |
GameInput::specKey(keyIndex); |
| 88 |
} |
| 89 |
} |
| 90 |
//----------------------------------------------------------------- |
| 91 |
void |
| 92 |
LevelInput::specStroke(const KeyStroke &stroke) |
| 93 |
{ |
| 94 |
if (!getLevel()->isActing()) { |
| 95 |
getLevel()->controlEvent(stroke); |
| 96 |
} |
| 97 |
} |
| 98 |
//----------------------------------------------------------------- |
| 99 |
void |
| 100 |
LevelInput::mouseEvent(const MouseStroke &buttons) |
| 101 |
{ |
| 102 |
getLevel()->controlMouse(buttons); |
| 103 |
} |
| 104 |
//----------------------------------------------------------------- |
| 105 |
void |
| 106 |
LevelInput::keyUp(const KeyStroke &stroke) { |
| 107 |
int index = m_keymap->indexPressed(stroke); |
| 108 |
switch (index) { |
| 109 |
case KEY_UNDO: |
| 110 |
case KEY_REDO: |
| 111 |
getLevel()->action_undo_finish(); |
| 112 |
break; |
| 113 |
default: |
| 114 |
break; |
| 115 |
} |
| 116 |
} |
| 117 |
|