Hotkey commands work with TEXT mode (limited).

develop
Petr Mrázek 2011-08-01 04:40:23 +02:00
parent 331ada8f91
commit fa970fc8fa
4 changed files with 67 additions and 0 deletions

@ -532,6 +532,43 @@ int Core::Shutdown ( void )
return -1;
}
// from ncurses
#define KEY_F0 0410 /* Function keys. Space for 64 */
#define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */
bool Core::ncurses_wgetch(int in, int & out)
{
if(!started)
{
out = in;
return true;
}
if(in >= KEY_F(1) && in <= KEY_F(8))
{
int idx = in - KEY_F(1);
// FIXME: copypasta, push into a method!
Gui * g = getGui();
if(g->hotkeys && g->df_interface && g->df_menu_state)
{
t_viewscreen * ws = g->GetCurrentScreen();
// FIXME: put hardcoded values into memory.xml
if(ws->getClassName() == "viewscreen_dwarfmodest" && *g->df_menu_state == 0x23)
{
out = in;
return true;
}
else
{
t_hotkey & hotkey = (*g->hotkeys)[idx];
setHotkeyCmd(hotkey.name);
return false;
}
}
}
out = in;
return true;
}
int Core::SDL_Event(SDL::Event* ev, int orig_return)
{
// do NOT process events before we are ready.

@ -104,6 +104,30 @@ DFhackCExport int SDL_PollEvent(SDL::Event* event)
return orig_return;
}
struct WINDOW;
DFhackCExport int wgetch(WINDOW *win)
{
static int (*_wgetch)(WINDOW * win) = (int (*)( WINDOW * )) dlsym(RTLD_NEXT, "wgetch");
if(!_wgetch)
{
exit(EXIT_FAILURE);
}
DFHack::Core & c = DFHack::Core::getInstance();
wgetch_again:
int in = _wgetch(win);
int out;
if(c.ncurses_wgetch(in, out))
{
// not consumed, give to DF
return out;
}
else
{
// consumed, repeat
goto wgetch_again;
}
}
// hook - called at program start, initialize some stuffs we'll use later
static int (*_SDL_Init)(uint32_t flags) = 0;
DFhackCExport int SDL_Init(uint32_t flags)

@ -33,6 +33,8 @@ distribution.
#include <stdint.h>
#include "dfhack/Console.h"
struct WINDOW;
namespace tthread
{
class mutex;
@ -77,6 +79,7 @@ namespace DFHack
friend void ::SDL_Quit(void);
friend int ::SDL_PollEvent(SDL::Event *);
friend int ::SDL_Init(uint32_t flags);
friend int ::wgetch(WINDOW * w);
public:
/// Get the single Core instance or make one.
static Core& getInstance()
@ -132,6 +135,7 @@ namespace DFHack
int Update (void);
int Shutdown (void);
int SDL_Event(SDL::Event* event, int orig_return);
bool ncurses_wgetch(int in, int & out);
Core(Core const&); // Don't Implement
void operator=(Core const&); // Don't implement
bool errorstate;

@ -37,6 +37,7 @@ distribution.
typedef void * fPtr;
typedef void * vPtr;
struct WINDOW;
namespace SDL
{
union Event;
@ -66,5 +67,6 @@ DFhackCExport int SDL_NumJoysticks(void);
DFhackCExport void SDL_Quit(void);
DFhackCExport int SDL_PollEvent(SDL::Event* event);
DFhackCExport int SDL_Init(uint32_t flags);
DFhackCExport int wgetch(WINDOW * win);
// Other crud is in the OS-specific core files.