summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file.list1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/game.cpp199
-rw-r--r--src/game.h8
-rw-r--r--src/gui/allegroinput.cpp70
-rw-r--r--src/gui/allegroinput.h49
-rw-r--r--src/gui/gui.cpp3
7 files changed, 235 insertions, 96 deletions
diff --git a/file.list b/file.list
index 80a8b7c5..4e661684 100644
--- a/file.list
+++ b/file.list
@@ -2,6 +2,7 @@ MODULES = src/sound/sound.cpp \
src/graphic/2xsai.cpp \
src/graphic/graphic.cpp \
src/graphic/image.cpp \
+ src/gui/allegroinput.cpp \
src/gui/button.cpp \
src/gui/buy.cpp \
src/gui/buysell.cpp \
diff --git a/src/Makefile.am b/src/Makefile.am
index e6dbd2ad..3821f835 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,6 +3,7 @@ tmw_SOURCES = sound/sound.cpp \
graphic/2xsai.cpp \
graphic/graphic.cpp \
graphic/image.cpp \
+ gui/allegroinput.cpp \
gui/button.cpp \
gui/buy.cpp \
gui/buysell.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 8e8c8036..4419b00c 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -18,9 +18,7 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * By ElvenProgrammer aka Eugenio Favalli (umperio@users.upagiro.net)
- * kth5 aka Alexander Baldeck
- * SimEdw
+ * $Id$
*/
#include "main.h"
@@ -168,52 +166,52 @@ void do_exit() {
* Check user input
*/
void do_input() {
- if(walk_status==0) {
+ if (walk_status == 0) {
int x = get_x(player_node->coordinates);
int y = get_y(player_node->coordinates);
-
- if(key[KEY_8_PAD] || key[KEY_UP]) {
- if(get_walk(x, y-1)!=0) {
+
+ if (key[KEY_8_PAD] || key[KEY_UP]) {
+ if (get_walk(x, y - 1) != 0) {
walk(x, y-1, NORTH);
- walk_status = 1;
- src_x = x;
- src_y = y;
- player_node->action = WALK;
- player_node->tick_time = tick_time;
- set_coordinates(player_node->coordinates, x, y-1, NORTH);
- } else set_coordinates(player_node->coordinates, x, y, NORTH);
- } else if(key[KEY_2_PAD] || key[KEY_DOWN]) {
- if(get_walk(x, y+1)!=0) {
- walk(x, y+1, SOUTH);
- walk_status = 1;
- src_x = x;
- src_y = y;
- player_node->action = WALK;
- player_node->tick_time = tick_time;
- set_coordinates(player_node->coordinates, x, y+1, SOUTH);
- } else set_coordinates(player_node->coordinates, x, y, SOUTH);
- } else if(key[KEY_4_PAD] || key[KEY_LEFT]) {
- if(get_walk(x-1, y)!=0) {
- walk(x-1, y, WEST);
- walk_status = 1;
- src_x = x;
- src_y = y;
- player_node->action = WALK;
- player_node->tick_time = tick_time;
- set_coordinates(player_node->coordinates, x-1, y, WEST);
- } else set_coordinates(player_node->coordinates, x, y, WEST);
- } else if(key[KEY_6_PAD] || key[KEY_RIGHT]) {
- if(get_walk(x+1, y)!=0) {
- walk(x+1, y, EAST);
- walk_status = 1;
- src_x = x;
- src_y = y;
- player_node->action = WALK;
- player_node->tick_time = tick_time;
- set_coordinates(player_node->coordinates, x+1, y, EAST);
- } else set_coordinates(player_node->coordinates, x, y, EAST);
+ walk_status = 1;
+ src_x = x;
+ src_y = y;
+ player_node->action = WALK;
+ player_node->tick_time = tick_time;
+ set_coordinates(player_node->coordinates, x, y - 1, NORTH);
+ } else set_coordinates(player_node->coordinates, x, y, NORTH);
+ } else if (key[KEY_2_PAD] || key[KEY_DOWN]) {
+ if(get_walk(x, y + 1) != 0) {
+ walk(x, y + 1, SOUTH);
+ walk_status = 1;
+ src_x = x;
+ src_y = y;
+ player_node->action = WALK;
+ player_node->tick_time = tick_time;
+ set_coordinates(player_node->coordinates, x, y + 1, SOUTH);
+ } else set_coordinates(player_node->coordinates, x, y, SOUTH);
+ } else if (key[KEY_4_PAD] || key[KEY_LEFT]) {
+ if (get_walk(x - 1, y) != 0) {
+ walk(x - 1, y, WEST);
+ walk_status = 1;
+ src_x = x;
+ src_y = y;
+ player_node->action = WALK;
+ player_node->tick_time = tick_time;
+ set_coordinates(player_node->coordinates, x - 1, y, WEST);
+ } else set_coordinates(player_node->coordinates, x, y, WEST);
+ } else if (key[KEY_6_PAD] || key[KEY_RIGHT]) {
+ if (get_walk(x + 1, y) != 0) {
+ walk(x + 1, y, EAST);
+ walk_status = 1;
+ src_x = x;
+ src_y = y;
+ player_node->action = WALK;
+ player_node->tick_time = tick_time;
+ set_coordinates(player_node->coordinates, x + 1, y, EAST);
+ } else set_coordinates(player_node->coordinates, x, y, EAST);
+ }
}
- }
if (player_node->action == STAND) {
if (key[KEY_LCONTROL]) {
@@ -225,13 +223,6 @@ void do_input() {
}
}
- if (key[KEY_F1]) {
- save_bitmap("./data/graphic/screenshot.bmp", buffer, NULL);
- } else if (key[KEY_F12]){
- sound.adjustVolume(1);
- } else if (key[KEY_F11]){
- sound.adjustVolume(-1);
- }
if (key[KEY_F5] && action_time) {
if (player_node->action == STAND)
action(2, 0);
@@ -241,20 +232,6 @@ void do_input() {
//alert("","","","","",0,0);
}
- if (key[KEY_F10] && action_time == true) {
- // was 3 goes to 0
- // was 0 goes to 3
- screen_mode = 3 - screen_mode;
- if (set_gfx_mode(screen_mode, 800, 600, 0, 0) != 0) {
- // less than: to add support for other hardware platforms
- error(allegro_error);
- }
- }
-
- if (key[KEY_F9] && action_time == true) {
- setup = Setup::create_setup();
- }
-
// Emotions, Skill dialog
if (key_shifts & KB_ALT_FLAG && action_time == true) {
if (player_node->emotion == 0) {
@@ -276,40 +253,71 @@ void do_input() {
action_time = false;
}
}
-
- if (key[KEY_S]) {
- if (stats == NULL)
- stats = StatsWindow::create_statswindow();
- else {
- stats->setVisible(!stats->isVisible());
- }
- action_time = false;
- } else if (key[KEY_I]) {
- inventoryWindow->setVisible(!inventoryWindow->isVisible());
- action_time = false;
- } else if (key[KEY_K]) {
- show_skill_list_dialog = !show_skill_dialog;
- action_time = false;
+ }
+
+ if (mouse_b & 2) {
+ //if(show_npc_dialog==0) {
+ int npc_x = mouse_x/32+camera_x;
+ int npc_y = mouse_y/32+camera_y;
+ int id = find_npc(npc_x, npc_y);
+ if(id!=0) {
+ WFIFOW(0) = net_w_value(0x0090);
+ WFIFOL(2) = net_l_value(id);
+ WFIFOB(6) = 0;
+ WFIFOSET(7);
}
+ //}
}
+}
- if (mouse_b & 2) {
- //if(show_npc_dialog==0) {
- int npc_x = mouse_x/32+camera_x;
- int npc_y = mouse_y/32+camera_y;
- int id = find_npc(npc_x, npc_y);
- if(id!=0) {
- WFIFOW(0) = net_w_value(0x0090);
- WFIFOL(2) = net_l_value(id);
- WFIFOB(6) = 0;
- WFIFOSET(7);
- }
- //}
- }
+bool handle_key(int unicode, int scancode)
+{
+ switch (scancode) {
+ case KEY_ESC:
+ state = EXIT;
+ return true;
+ case KEY_F1:
+ save_bitmap("./data/graphic/screenshot.bmp", buffer, NULL);
+ return true;
+ case KEY_F12:
+ sound.adjustVolume(1);
+ return true;
+ case KEY_F11:
+ sound.adjustVolume(-1);
+ return true;
+ case KEY_F9:
+ setup = Setup::create_setup();
+ return true;
+ case KEY_F10:
+ // was 3 goes to 0
+ // was 0 goes to 3
+ screen_mode = 3 - screen_mode;
+ if (set_gfx_mode(screen_mode, 800, 600, 0, 0) != 0) {
+ // less than: to add support for other hardware platforms
+ error(allegro_error);
+ }
+ return true;
+ }
- if (key[KEY_ESC]) {
- state = EXIT;
+ if (key_shifts & KB_ALT_FLAG) {
+ switch (scancode) {
+ case KEY_I:
+ inventoryWindow->setVisible(!inventoryWindow->isVisible());
+ return true;
+ case KEY_S:
+ if (stats == NULL)
+ stats = StatsWindow::create_statswindow();
+ else {
+ stats->setVisible(!stats->isVisible());
+ }
+ return true;
+ case KEY_K:
+ show_skill_list_dialog = !show_skill_dialog;
+ return true;
+ }
}
+
+ return false;
}
/** Calculate packet length */
@@ -746,6 +754,7 @@ void do_parse() {
// Buy/Sell dialog
case 0x00c4:
buyDialog->setVisible(false);
+ sellDialog->setVisible(false);
buySellDialog->setVisible(true);
current_npc = RFIFOL(2);
break;
diff --git a/src/game.h b/src/game.h
index fc9376f4..1a7e6433 100644
--- a/src/game.h
+++ b/src/game.h
@@ -75,6 +75,14 @@ extern unsigned short src_x, src_y, x, y;
extern volatile int tick_time;
extern int server_tick;
+/**
+ * Handle a key press.
+ *
+ * @return <code>true</code> when the key is used, <code>false</code>
+ * otherwise.
+ */
+bool handle_key(int unicode, int scancode);
+
void game();
void do_init();
void do_input();
diff --git a/src/gui/allegroinput.cpp b/src/gui/allegroinput.cpp
new file mode 100644
index 00000000..8ca077c1
--- /dev/null
+++ b/src/gui/allegroinput.cpp
@@ -0,0 +1,70 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "allegroinput.h"
+#include "../game.h"
+#include <allegro.h>
+
+AllegroInput::AllegroInput() :
+ gcn::AllegroInput()
+{
+}
+
+void AllegroInput::pollKeyInput()
+{
+ int unicode, scancode;
+
+ if (keyboard_needs_poll())
+ {
+ poll_keyboard();
+ }
+
+ while (keypressed())
+ {
+ unicode = ureadkey(&scancode);
+
+ if (!handle_key(unicode, scancode))
+ {
+ gcn::Key keyObj = convertToKey(scancode, unicode);
+ mKeyQueue.push(gcn::KeyInput(keyObj, gcn::KeyInput::PRESS));
+ mPressedKeys[scancode] = keyObj;
+ }
+ }
+
+ // Check for released keys
+ std::map<int, gcn::Key>::iterator iter, tempIter;
+ for (iter = mPressedKeys.begin(); iter != mPressedKeys.end(); )
+ {
+ if (!key[iter->first])
+ {
+ mKeyQueue.push(gcn::KeyInput(iter->second, gcn::KeyInput::RELEASE));
+ tempIter = iter;
+ iter++;
+ mPressedKeys.erase(tempIter);
+ }
+ else
+ {
+ iter++;
+ }
+ }
+}
diff --git a/src/gui/allegroinput.h b/src/gui/allegroinput.h
new file mode 100644
index 00000000..ab1a1301
--- /dev/null
+++ b/src/gui/allegroinput.h
@@ -0,0 +1,49 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_ALLEGRO_INPUT_H__
+#define _TMW_ALLEGRO_INPUT_H__
+
+#include <guichan.hpp>
+#include <guichan/allegro.hpp>
+
+/**
+ * Allegro input handler that gives us a chance to handle some shortkeys.
+ *
+ * \ingroup GUI
+ */
+class AllegroInput : public gcn::AllegroInput
+{
+ public:
+ /**
+ * Constructor.
+ */
+ AllegroInput();
+
+ /**
+ * Polls key input.
+ */
+ void pollKeyInput();
+};
+
+#endif
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index e8217cf8..a64ff457 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -27,6 +27,7 @@
#include <math.h>
#include "../log.h"
#include "../sound/sound.h"
+#include "allegroinput.h"
#ifndef WIN32
#define __cdecl __attribute__((cdecl))
@@ -77,7 +78,7 @@ void init_gui(BITMAP *bitmap, const char *skin) {
guiGraphics = new gcn::AllegroGraphics();
guiGraphics->setTarget(bitmap);
- guiInput = new gcn::AllegroInput();
+ guiInput = new AllegroInput();
guiTop = new gcn::Container();
guiTop->setDimension(gcn::Rectangle(0, 0, SCREEN_W, SCREEN_H));