Put some compatibility features into the base dfhack viewscreen.

develop
Alexander Gavrilov 2012-08-22 18:18:19 +04:00
parent 6e8b68fb29
commit 7987ea9a98
6 changed files with 80 additions and 17 deletions

@ -1179,7 +1179,14 @@ int screen_show(lua_State *L)
before = Lua::CheckDFObject<df::viewscreen>(L, 2); before = Lua::CheckDFObject<df::viewscreen>(L, 2);
df::viewscreen *screen = dfhack_lua_viewscreen::get_pointer(L, 1, true); df::viewscreen *screen = dfhack_lua_viewscreen::get_pointer(L, 1, true);
lua_pushboolean(L, Screen::show(screen, before));
bool ok = Screen::show(screen, before);
// If it is a table, get_pointer created a new object. Don't leak it.
if (!ok && lua_istable(L, 1))
delete screen;
lua_pushboolean(L, ok);
return 1; return 1;
} }

@ -117,12 +117,21 @@ namespace DFHack
} }
class DFHACK_EXPORT dfhack_viewscreen : public df::viewscreen { class DFHACK_EXPORT dfhack_viewscreen : public df::viewscreen {
df::coord2d last_size;
void check_resize();
protected:
bool text_input_mode;
public: public:
dfhack_viewscreen(); dfhack_viewscreen();
virtual ~dfhack_viewscreen(); virtual ~dfhack_viewscreen();
static bool is_instance(df::viewscreen *screen); static bool is_instance(df::viewscreen *screen);
virtual void logic();
virtual void render();
virtual int8_t movies_okay() { return 1; } virtual int8_t movies_okay() { return 1; }
virtual bool key_conflict(df::interface_key key); virtual bool key_conflict(df::interface_key key);

@ -203,6 +203,8 @@ end
Screen = defclass(Screen, dfhack.screen) Screen = defclass(Screen, dfhack.screen)
Screen.text_input_mode = false
function Screen:isShown() function Screen:isShown()
return self._native ~= nil return self._native ~= nil
end end
@ -219,7 +221,7 @@ function Screen:renderParent()
end end
end end
function Screen:inputToParent(...) function Screen:sendInputToParent(...)
if self._native and self._native.parent then if self._native and self._native.parent then
simulateInput(self._native.parent, ...) simulateInput(self._native.parent, ...)
end end
@ -232,6 +234,8 @@ function Screen:show(below)
self:onAboutToShow(below) self:onAboutToShow(below)
if dscreen.show(self, below) then if dscreen.show(self, below) then
self:onShown() self:onShown()
else
error('Could not show screen')
end end
end end

@ -127,17 +127,12 @@ local move_keys = {
function DwarfOverlay:propagateMoveKeys(keys) function DwarfOverlay:propagateMoveKeys(keys)
for _,v in ipairs(move_keys) do for _,v in ipairs(move_keys) do
if keys[v] then if keys[v] then
self:inputToParent(v) self:sendInputToParent(v)
return return v
end end
end end
end end
function DwarfOverlay:onIdle()
-- Dwarfmode constantly needs repainting
dscreen.invalidate()
end
function DwarfOverlay:onAboutToShow(below) function DwarfOverlay:onAboutToShow(below)
local screen = dfhack.gui.getCurViewscreen() local screen = dfhack.gui.getCurViewscreen()
if below then screen = below.parent end if below then screen = below.parent end

@ -258,7 +258,7 @@ bool Screen::isDismissed(df::viewscreen *screen)
static std::set<df::viewscreen*> dfhack_screens; static std::set<df::viewscreen*> dfhack_screens;
dfhack_viewscreen::dfhack_viewscreen() dfhack_viewscreen::dfhack_viewscreen() : text_input_mode(false)
{ {
dfhack_screens.insert(this); dfhack_screens.insert(this);
} }
@ -273,9 +273,42 @@ bool dfhack_viewscreen::is_instance(df::viewscreen *screen)
return dfhack_screens.count(screen) != 0; return dfhack_screens.count(screen) != 0;
} }
void dfhack_viewscreen::check_resize()
{
auto size = Screen::getWindowSize();
if (size != last_size)
{
last_size = size;
resize(size.x, size.y);
}
}
void dfhack_viewscreen::logic()
{
check_resize();
// Various stuff works poorly unless always repainting
Screen::invalidate();
}
void dfhack_viewscreen::render()
{
check_resize();
}
bool dfhack_viewscreen::key_conflict(df::interface_key key) bool dfhack_viewscreen::key_conflict(df::interface_key key)
{ {
return key == interface_key::OPTIONS; if (key == interface_key::OPTIONS)
return true;
if (text_input_mode)
{
if (key == interface_key::HELP || key == interface_key::MOVIES)
return true;
}
return false;
} }
/* /*
@ -364,6 +397,10 @@ int dfhack_lua_viewscreen::do_destroy(lua_State *L)
void dfhack_lua_viewscreen::update_focus(lua_State *L, int idx) void dfhack_lua_viewscreen::update_focus(lua_State *L, int idx)
{ {
lua_getfield(L, idx, "text_input_mode");
text_input_mode = lua_toboolean(L, -1);
lua_pop(L, 1);
lua_getfield(L, idx, "focus_path"); lua_getfield(L, idx, "focus_path");
auto str = lua_tostring(L, -1); auto str = lua_tostring(L, -1);
if (!str) str = ""; if (!str) str = "";
@ -496,23 +533,35 @@ dfhack_lua_viewscreen::~dfhack_lua_viewscreen()
void dfhack_lua_viewscreen::render() void dfhack_lua_viewscreen::render()
{ {
if (Screen::isDismissed(this)) return;
dfhack_viewscreen::render();
safe_call_lua(do_render, 0, 0); safe_call_lua(do_render, 0, 0);
} }
void dfhack_lua_viewscreen::logic() void dfhack_lua_viewscreen::logic()
{ {
if (Screen::isDismissed(this)) return;
dfhack_viewscreen::logic();
lua_pushstring(Lua::Core::State, "onIdle"); lua_pushstring(Lua::Core::State, "onIdle");
safe_call_lua(do_notify, 1, 0); safe_call_lua(do_notify, 1, 0);
} }
void dfhack_lua_viewscreen::help() void dfhack_lua_viewscreen::help()
{ {
if (Screen::isDismissed(this)) return;
lua_pushstring(Lua::Core::State, "onHelp"); lua_pushstring(Lua::Core::State, "onHelp");
safe_call_lua(do_notify, 1, 0); safe_call_lua(do_notify, 1, 0);
} }
void dfhack_lua_viewscreen::resize(int w, int h) void dfhack_lua_viewscreen::resize(int w, int h)
{ {
if (Screen::isDismissed(this)) return;
auto L = Lua::Core::State; auto L = Lua::Core::State;
lua_pushstring(L, "onResize"); lua_pushstring(L, "onResize");
lua_pushinteger(L, w); lua_pushinteger(L, w);
@ -522,6 +571,8 @@ void dfhack_lua_viewscreen::resize(int w, int h)
void dfhack_lua_viewscreen::feed(std::set<df::interface_key> *keys) void dfhack_lua_viewscreen::feed(std::set<df::interface_key> *keys)
{ {
if (Screen::isDismissed(this)) return;
lua_pushlightuserdata(Lua::Core::State, keys); lua_pushlightuserdata(Lua::Core::State, keys);
safe_call_lua(do_input, 1, 0); safe_call_lua(do_input, 1, 0);
} }

@ -246,7 +246,7 @@ public:
static viewscreen_unitlaborsst *create (char pushtype, df::viewscreen *scr = NULL); static viewscreen_unitlaborsst *create (char pushtype, df::viewscreen *scr = NULL);
void feed(set<df::interface_key> *events); void feed(set<df::interface_key> *events);
void logic();
void render(); void render();
void resize(int w, int h) { calcSize(); } void resize(int w, int h) { calcSize(); }
@ -444,16 +444,13 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
// TODO: add sorting // TODO: add sorting
} }
void viewscreen_unitlaborsst::logic()
{
enabler->flag.bits.render = true;
}
void viewscreen_unitlaborsst::render() void viewscreen_unitlaborsst::render()
{ {
if (Screen::isDismissed(this)) if (Screen::isDismissed(this))
return; return;
dfhack_viewscreen::render();
Screen::clear(); Screen::clear();
Screen::drawBorder(" Manage Labors "); Screen::drawBorder(" Manage Labors ");