Allow arrowkeys to move player, including diagonals by pressing multiple

keys before releasing. Works well on handheld's thumbpad, perhaps less
useful on a fullsize keyboard.
Also some Qtopia-only fixes for Qt windowport.
This commit is contained in:
warwick
2002-08-14 05:01:56 +00:00
parent 6682df52d2
commit 8285ca28c6
2 changed files with 48 additions and 17 deletions
+3 -1
View File
@@ -22,7 +22,7 @@
#include <qlabel.h> #include <qlabel.h>
#include <qlineedit.h> #include <qlineedit.h>
#if defined(QWS) #if defined(QWS)
#include <qpeapplication.h> #include <qpe/qpeapplication.h>
#else #else
#include <qapplication.h> #include <qapplication.h>
#endif #endif
@@ -711,6 +711,7 @@ public slots:
protected: protected:
virtual void resizeEvent(QResizeEvent*); virtual void resizeEvent(QResizeEvent*);
virtual void keyPressEvent(QKeyEvent*); virtual void keyPressEvent(QKeyEvent*);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void closeEvent(QCloseEvent*); virtual void closeEvent(QCloseEvent*);
private slots: private slots:
@@ -734,6 +735,7 @@ private:
NetHackQtKeyBuffer& keysink; NetHackQtKeyBuffer& keysink;
QWidgetStack* stack; QWidgetStack* stack;
int dirkey;
const char* *macro; const char* *macro;
}; };
+45 -16
View File
@@ -3482,7 +3482,7 @@ public:
NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) : NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
message(0), map(0), status(0), invusage(0), message(0), map(0), status(0), invusage(0),
keysink(ks) keysink(ks), dirkey(0)
{ {
QToolBar* toolbar = new QToolBar(this); QToolBar* toolbar = new QToolBar(this);
#if QT_VERSION >= 210 #if QT_VERSION >= 210
@@ -3889,6 +3889,15 @@ void NetHackQtMainWindow::resizeEvent(QResizeEvent*)
#endif #endif
} }
void NetHackQtMainWindow::keyReleaseEvent(QKeyEvent* event)
{
if ( dirkey ) {
doKeys(QString(QChar(dirkey)));
if ( !event->isAutoRepeat() )
dirkey = 0;
}
}
void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event) void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event)
{ {
// Global key controls // Global key controls
@@ -3897,33 +3906,52 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event)
// to think that's the way to move. For handhelds, the normal way is to // to think that's the way to move. For handhelds, the normal way is to
// click-to-travel, so we allow the cursor keys for fine movements. // click-to-travel, so we allow the cursor keys for fine movements.
// 321
// 4 0
// 567
if ( event->isAutoRepeat() &&
event->key() >= Key_Left && event->key() <= Key_Down )
return;
const char* d = iflags.num_pad ? ndir : sdir; const char* d = iflags.num_pad ? ndir : sdir;
switch (event->key()) { switch (event->key()) {
case Key_Up: case Key_Up:
if (qt_compact_mode) if ( dirkey == d[0] )
keysink.Put(d[2]); dirkey = d[1];
else if ( dirkey == d[4] )
dirkey = d[3];
else else
if (map) map->Scroll(0,-1); dirkey = d[2];
break; case Key_Down: break; case Key_Down:
if (qt_compact_mode) if ( dirkey == d[0] )
keysink.Put(d[6]); dirkey = d[7];
else if ( dirkey == d[4] )
dirkey = d[5];
else else
if (map) map->Scroll(0,+1); dirkey = d[6];
break; case Key_Left: break; case Key_Left:
if (qt_compact_mode) if ( dirkey == d[2] )
keysink.Put(d[0]); dirkey = d[1];
else if ( dirkey == d[6] )
dirkey = d[7];
else else
if (map) map->Scroll(-1,0); dirkey = d[0];
break; case Key_Right: break; case Key_Right:
if (qt_compact_mode) if ( dirkey == d[2] )
keysink.Put(d[4]); dirkey = d[3];
else if ( dirkey == d[6] )
dirkey = d[5];
else else
if (map) map->Scroll(+1,0); dirkey = d[4];
break; case Key_Prior: break; case Key_Prior:
dirkey = 0;
if (message) message->Scroll(0,-1); if (message) message->Scroll(0,-1);
break; case Key_Next: break; case Key_Next:
dirkey = 0;
if (message) message->Scroll(0,+1); if (message) message->Scroll(0,+1);
break; default: break; default:
dirkey = 0;
event->ignore(); event->ignore();
} }
} }
@@ -4391,7 +4419,7 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) :
void NetHackQtBind::qt_init_nhwindows(int* argc, char** argv) void NetHackQtBind::qt_init_nhwindows(int* argc, char** argv)
{ {
#ifdef _WS_X11_ #ifdef UNIX
// Userid control // Userid control
// //
// Michael Hohmuth <hohmuth@inf.tu-dresden.de>... // Michael Hohmuth <hohmuth@inf.tu-dresden.de>...
@@ -4409,7 +4437,7 @@ void NetHackQtBind::qt_init_nhwindows(int* argc, char** argv)
QApplication::setColorSpec(ManyColor); QApplication::setColorSpec(ManyColor);
instance=new NetHackQtBind(*argc,argv); instance=new NetHackQtBind(*argc,argv);
#ifdef _WS_X11_ #ifdef UNIX
seteuid(gamesuid); seteuid(gamesuid);
#endif #endif
@@ -5019,7 +5047,8 @@ bool NetHackQtBind::notify(QObject *receiver, QEvent *event)
{ {
// Ignore Alt-key navigation to menubar, it's annoying when you // Ignore Alt-key navigation to menubar, it's annoying when you
// use Alt-Direction to move around. // use Alt-Direction to move around.
if ( main && event->type()==QEvent::KeyRelease && main==receiver ) if ( main && event->type()==QEvent::KeyRelease && main==receiver
&& ((QKeyEvent*)event)->key() == Key_Alt )
return TRUE; return TRUE;
bool result=QApplication::notify(receiver,event); bool result=QApplication::notify(receiver,event);