2012-08-18 23:31:09 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2012-08-18 23:31:09 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "Export.h"
|
|
|
|
#include "Module.h"
|
|
|
|
#include "BitArray.h"
|
|
|
|
#include "ColorText.h"
|
2012-11-19 07:11:26 -07:00
|
|
|
#include "Types.h"
|
2012-11-22 08:38:45 -07:00
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
#include <string>
|
2012-11-22 08:38:45 -07:00
|
|
|
#include <set>
|
2018-06-14 08:12:06 -06:00
|
|
|
#include <memory>
|
2012-08-18 23:31:09 -06:00
|
|
|
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/graphic.h"
|
|
|
|
#include "df/viewscreen.h"
|
2018-06-30 12:12:29 -06:00
|
|
|
#include "df/zoom_commands.h"
|
2012-08-18 23:31:09 -06:00
|
|
|
|
2015-11-13 18:10:29 -07:00
|
|
|
#include "modules/GuiHooks.h"
|
|
|
|
|
2012-09-20 01:11:20 -06:00
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct job;
|
|
|
|
struct item;
|
|
|
|
struct unit;
|
|
|
|
struct building;
|
2017-05-05 12:45:46 -06:00
|
|
|
struct plant;
|
2012-09-20 01:11:20 -06:00
|
|
|
}
|
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
/**
|
|
|
|
* \defgroup grp_screen utilities for painting to the screen
|
|
|
|
* @ingroup grp_screen
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace DFHack
|
|
|
|
{
|
|
|
|
class Core;
|
2016-01-01 09:15:29 -07:00
|
|
|
class Plugin;
|
2012-08-18 23:31:09 -06:00
|
|
|
|
2012-11-22 08:38:45 -07:00
|
|
|
typedef std::set<df::interface_key> interface_key_set;
|
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
/**
|
|
|
|
* The Screen module
|
|
|
|
* \ingroup grp_modules
|
|
|
|
* \ingroup grp_screen
|
|
|
|
*/
|
|
|
|
namespace Screen
|
|
|
|
{
|
|
|
|
/// Data structure describing all properties a screen tile can have
|
|
|
|
struct Pen {
|
|
|
|
// Ordinary text symbol
|
|
|
|
char ch;
|
|
|
|
int8_t fg, bg;
|
|
|
|
bool bold;
|
|
|
|
|
|
|
|
// Graphics tile
|
|
|
|
int tile;
|
|
|
|
enum TileMode {
|
|
|
|
AsIs, // Tile colors used without modification
|
|
|
|
CharColor, // The fg/bg pair is used
|
|
|
|
TileColor // The fields below are used
|
|
|
|
} tile_mode;
|
|
|
|
int8_t tile_fg, tile_bg;
|
|
|
|
|
2023-01-11 19:23:16 -07:00
|
|
|
bool write_to_lower = false;
|
|
|
|
bool keep_lower = false;
|
2023-02-01 18:39:32 -07:00
|
|
|
bool top_of_text = false;
|
|
|
|
bool bottom_of_text = false;
|
2023-01-11 19:23:16 -07:00
|
|
|
|
2012-09-07 01:36:45 -06:00
|
|
|
bool valid() const { return tile >= 0; }
|
|
|
|
bool empty() const { return ch == 0 && tile == 0; }
|
|
|
|
|
2012-11-03 10:06:33 -06:00
|
|
|
// NOTE: LuaApi.cpp assumes this struct is plain data and has empty destructor
|
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
Pen(char ch = 0, int8_t fg = 7, int8_t bg = 0, int tile = 0, bool color_tile = false)
|
|
|
|
: ch(ch), fg(fg&7), bg(bg), bold(!!(fg&8)),
|
|
|
|
tile(tile), tile_mode(color_tile ? CharColor : AsIs), tile_fg(0), tile_bg(0)
|
|
|
|
{}
|
|
|
|
Pen(char ch, int8_t fg, int8_t bg, bool bold, int tile = 0, bool color_tile = false)
|
|
|
|
: ch(ch), fg(fg), bg(bg), bold(bold),
|
|
|
|
tile(tile), tile_mode(color_tile ? CharColor : AsIs), tile_fg(0), tile_bg(0)
|
|
|
|
{}
|
|
|
|
Pen(char ch, int8_t fg, int8_t bg, int tile, int8_t tile_fg, int8_t tile_bg)
|
|
|
|
: ch(ch), fg(fg&7), bg(bg), bold(!!(fg&8)),
|
|
|
|
tile(tile), tile_mode(TileColor), tile_fg(tile_fg), tile_bg(tile_bg)
|
|
|
|
{}
|
|
|
|
Pen(char ch, int8_t fg, int8_t bg, bool bold, int tile, int8_t tile_fg, int8_t tile_bg)
|
|
|
|
: ch(ch), fg(fg), bg(bg), bold(bold),
|
|
|
|
tile(tile), tile_mode(TileColor), tile_fg(tile_fg), tile_bg(tile_bg)
|
|
|
|
{}
|
2012-11-19 07:11:26 -07:00
|
|
|
|
|
|
|
void adjust(int8_t nfg) { fg = nfg&7; bold = !!(nfg&8); }
|
|
|
|
void adjust(int8_t nfg, bool nbold) { fg = nfg; bold = nbold; }
|
|
|
|
void adjust(int8_t nfg, int8_t nbg) { adjust(nfg); bg = nbg; }
|
|
|
|
void adjust(int8_t nfg, bool nbold, int8_t nbg) { adjust(nfg, nbold); bg = nbg; }
|
|
|
|
|
|
|
|
Pen color(int8_t nfg) const { Pen cp(*this); cp.adjust(nfg); return cp; }
|
|
|
|
Pen color(int8_t nfg, bool nbold) const { Pen cp(*this); cp.adjust(nfg, nbold); return cp; }
|
|
|
|
Pen color(int8_t nfg, int8_t nbg) const { Pen cp(*this); cp.adjust(nfg, nbg); return cp; }
|
|
|
|
Pen color(int8_t nfg, bool nbold, int8_t nbg) const { Pen cp(*this); cp.adjust(nfg, nbold, nbg); return cp; }
|
|
|
|
|
|
|
|
Pen chtile(char ch) { Pen cp(*this); cp.ch = ch; return cp; }
|
|
|
|
Pen chtile(char ch, int tile) { Pen cp(*this); cp.ch = ch; cp.tile = tile; return cp; }
|
|
|
|
};
|
|
|
|
|
2015-03-27 20:56:20 -06:00
|
|
|
class DFHACK_EXPORT PenArray {
|
|
|
|
Pen *buffer;
|
|
|
|
unsigned int dimx;
|
|
|
|
unsigned int dimy;
|
2015-03-28 09:27:47 -06:00
|
|
|
bool static_alloc;
|
2015-03-27 20:56:20 -06:00
|
|
|
public:
|
|
|
|
PenArray(unsigned int bufwidth, unsigned int bufheight);
|
2015-03-28 09:27:47 -06:00
|
|
|
PenArray(unsigned int bufwidth, unsigned int bufheight, void *buf);
|
2015-03-27 20:56:20 -06:00
|
|
|
~PenArray();
|
|
|
|
void clear();
|
2015-03-28 16:35:07 -06:00
|
|
|
unsigned int get_dimx() { return dimx; }
|
|
|
|
unsigned int get_dimy() { return dimy; }
|
|
|
|
Pen get_tile(unsigned int x, unsigned int y);
|
2015-03-27 20:56:20 -06:00
|
|
|
void set_tile(unsigned int x, unsigned int y, Screen::Pen pen);
|
|
|
|
void draw(unsigned int x, unsigned int y, unsigned int width, unsigned int height,
|
|
|
|
unsigned int bufx = 0, unsigned int bufy = 0);
|
|
|
|
};
|
|
|
|
|
2012-11-20 08:32:04 -07:00
|
|
|
struct DFHACK_EXPORT ViewRect {
|
2012-11-19 07:11:26 -07:00
|
|
|
rect2d view, clip;
|
|
|
|
|
|
|
|
ViewRect(rect2d area) : view(area), clip(area) {}
|
|
|
|
ViewRect(rect2d area, rect2d clip) : view(area), clip(clip) {}
|
|
|
|
|
|
|
|
bool isDefunct() const {
|
|
|
|
return clip.first.x > clip.second.x || clip.first.y > clip.second.y;
|
|
|
|
}
|
|
|
|
int width() const { return view.second.x-view.first.x+1; }
|
|
|
|
int height() const { return view.second.y-view.first.y+1; }
|
|
|
|
df::coord2d local(df::coord2d pos) const {
|
|
|
|
return df::coord2d(pos.x - view.first.x, pos.y - view.first.y);
|
|
|
|
}
|
|
|
|
df::coord2d global(df::coord2d pos) const {
|
|
|
|
return df::coord2d(pos.x + view.first.x, pos.y + view.first.y);
|
|
|
|
}
|
|
|
|
df::coord2d global(int x, int y) const {
|
|
|
|
return df::coord2d(x + view.first.x, y + view.first.y);
|
|
|
|
}
|
|
|
|
bool inClipGlobal(int x, int y) const {
|
|
|
|
return x >= clip.first.x && x <= clip.second.x &&
|
|
|
|
y >= clip.first.y && y <= clip.second.y;
|
|
|
|
}
|
|
|
|
bool inClipGlobal(df::coord2d pos) const {
|
|
|
|
return inClipGlobal(pos.x, pos.y);
|
|
|
|
}
|
|
|
|
bool inClipLocal(int x, int y) const {
|
|
|
|
return inClipGlobal(x + view.first.x, y + view.first.y);
|
|
|
|
}
|
|
|
|
bool inClipLocal(df::coord2d pos) const {
|
|
|
|
return inClipLocal(pos.x, pos.y);
|
|
|
|
}
|
|
|
|
ViewRect viewport(rect2d area) const {
|
|
|
|
rect2d nview(global(area.first), global(area.second));
|
|
|
|
return ViewRect(nview, intersect(nview, clip));
|
|
|
|
}
|
2012-08-18 23:31:09 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
DFHACK_EXPORT df::coord2d getMousePos();
|
2022-12-16 12:53:44 -07:00
|
|
|
DFHACK_EXPORT df::coord2d getMousePixels();
|
2012-08-18 23:31:09 -06:00
|
|
|
DFHACK_EXPORT df::coord2d getWindowSize();
|
|
|
|
|
2012-11-19 07:11:26 -07:00
|
|
|
inline rect2d getScreenRect() {
|
|
|
|
return rect2d(df::coord2d(0,0), getWindowSize()-df::coord2d(1,1));
|
|
|
|
}
|
|
|
|
|
2018-06-30 12:12:29 -06:00
|
|
|
/// Wrapper to call enabler->zoom_display from plugins
|
|
|
|
DFHACK_EXPORT void zoom(df::zoom_commands cmd);
|
|
|
|
|
2012-08-19 10:00:10 -06:00
|
|
|
/// Returns the state of [GRAPHICS:YES/NO]
|
|
|
|
DFHACK_EXPORT bool inGraphicsMode();
|
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
/// Paint one screen tile with the given pen
|
2015-12-22 09:42:51 -07:00
|
|
|
DFHACK_EXPORT bool paintTile(const Pen &pen, int x, int y, bool map = false);
|
2012-08-18 23:31:09 -06:00
|
|
|
|
2012-09-07 01:36:45 -06:00
|
|
|
/// Retrieves one screen tile from the buffer
|
2017-05-31 10:12:15 -06:00
|
|
|
DFHACK_EXPORT Pen readTile(int x, int y, bool map = false);
|
2012-09-07 01:36:45 -06:00
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
/// Paint a string onto the screen. Ignores ch and tile of pen.
|
2015-12-22 09:42:51 -07:00
|
|
|
DFHACK_EXPORT bool paintString(const Pen &pen, int x, int y, const std::string &text, bool map = false);
|
2012-08-18 23:31:09 -06:00
|
|
|
|
|
|
|
/// Fills a rectangle with one pen. Possibly more efficient than a loop over paintTile.
|
2015-12-22 09:42:51 -07:00
|
|
|
DFHACK_EXPORT bool fillRect(const Pen &pen, int x1, int y1, int x2, int y2, bool map = false);
|
2012-08-18 23:31:09 -06:00
|
|
|
|
2012-08-21 14:28:11 -06:00
|
|
|
/// Draws a standard dark gray window border with a title string
|
|
|
|
DFHACK_EXPORT bool drawBorder(const std::string &title);
|
|
|
|
|
2012-08-19 04:27:44 -06:00
|
|
|
/// Wipes the screen to full black
|
|
|
|
DFHACK_EXPORT bool clear();
|
|
|
|
|
|
|
|
/// Requests repaint
|
|
|
|
DFHACK_EXPORT bool invalidate();
|
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
/// Find a loaded graphics tile from graphics raws.
|
|
|
|
DFHACK_EXPORT bool findGraphicsTile(const std::string &page, int x, int y, int *ptile, int *pgs = NULL);
|
|
|
|
|
|
|
|
// Push and remove viewscreens
|
2018-06-14 08:12:06 -06:00
|
|
|
DFHACK_EXPORT bool show(std::unique_ptr<df::viewscreen> screen, df::viewscreen *before = NULL, Plugin *p = NULL);
|
|
|
|
inline bool show(std::unique_ptr<df::viewscreen> screen, Plugin *p)
|
|
|
|
{ return show(std::move(screen), NULL, p); }
|
2012-08-24 03:20:08 -06:00
|
|
|
DFHACK_EXPORT void dismiss(df::viewscreen *screen, bool to_first = false);
|
2012-08-18 23:31:09 -06:00
|
|
|
DFHACK_EXPORT bool isDismissed(df::viewscreen *screen);
|
2016-01-01 09:15:29 -07:00
|
|
|
DFHACK_EXPORT bool hasActiveScreens(Plugin *p);
|
2023-01-04 14:36:46 -07:00
|
|
|
DFHACK_EXPORT void raise(df::viewscreen *screen);
|
2012-10-02 03:49:31 -06:00
|
|
|
|
|
|
|
/// Retrieve the string representation of the bound key.
|
|
|
|
DFHACK_EXPORT std::string getKeyDisplay(df::interface_key key);
|
2012-11-19 07:11:26 -07:00
|
|
|
|
2014-08-11 04:23:19 -06:00
|
|
|
/// Return the character represented by this key, or -1
|
|
|
|
DFHACK_EXPORT int keyToChar(df::interface_key key);
|
|
|
|
/// Return the key code matching this character, or NONE
|
|
|
|
DFHACK_EXPORT df::interface_key charToKey(char code);
|
|
|
|
|
2012-11-19 07:11:26 -07:00
|
|
|
/// A painter class that implements a clipping area and cursor/pen state
|
|
|
|
struct DFHACK_EXPORT Painter : ViewRect {
|
|
|
|
df::coord2d gcursor;
|
|
|
|
Pen cur_pen, cur_key_pen;
|
|
|
|
|
|
|
|
static const Pen default_pen;
|
|
|
|
static const Pen default_key_pen;
|
|
|
|
|
|
|
|
Painter(const ViewRect &area, const Pen &pen = default_pen, const Pen &kpen = default_key_pen)
|
|
|
|
: ViewRect(area), gcursor(area.view.first), cur_pen(pen), cur_key_pen(kpen)
|
|
|
|
{}
|
|
|
|
|
|
|
|
df::coord2d cursor() const { return local(gcursor); }
|
|
|
|
int cursorX() const { return gcursor.x - view.first.x; }
|
|
|
|
int cursorY() const { return gcursor.y - view.first.y; }
|
|
|
|
|
|
|
|
bool isValidPos() const { return inClipGlobal(gcursor); }
|
|
|
|
|
|
|
|
Painter viewport(rect2d area) const {
|
|
|
|
return Painter(ViewRect::viewport(area), cur_pen, cur_key_pen);
|
|
|
|
}
|
|
|
|
|
|
|
|
Painter &seek(df::coord2d pos) { gcursor = global(pos); return *this; }
|
|
|
|
Painter &seek(int x, int y) { gcursor = global(x,y); return *this; }
|
|
|
|
Painter &advance(int dx) { gcursor.x += dx; return *this; }
|
|
|
|
Painter &advance(int dx, int dy) { gcursor.x += dx; gcursor.y += dy; return *this; }
|
|
|
|
Painter &newline(int dx = 0) { gcursor.y++; gcursor.x = view.first.x + dx; return *this; }
|
|
|
|
|
|
|
|
const Pen &pen() const { return cur_pen; }
|
|
|
|
Painter &pen(const Pen &np) { cur_pen = np; return *this; }
|
|
|
|
Painter &pen(int8_t fg) { cur_pen.adjust(fg); return *this; }
|
|
|
|
|
|
|
|
const Pen &key_pen() const { return cur_key_pen; }
|
|
|
|
Painter &key_pen(const Pen &np) { cur_key_pen = np; return *this; }
|
|
|
|
Painter &key_pen(int8_t fg) { cur_key_pen.adjust(fg); return *this; }
|
|
|
|
|
|
|
|
Painter &clear() {
|
|
|
|
fillRect(Pen(' ',0,0,false), clip.first.x, clip.first.y, clip.second.x, clip.second.y);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &fill(const rect2d &area, const Pen &pen, bool map = false) {
|
2012-11-19 07:11:26 -07:00
|
|
|
rect2d irect = intersect(area, clip);
|
2015-12-22 09:42:51 -07:00
|
|
|
fillRect(pen, irect.first.x, irect.first.y, irect.second.x, irect.second.y, map);
|
2012-11-19 07:11:26 -07:00
|
|
|
return *this;
|
|
|
|
}
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &fill(const rect2d &area, bool map = false) { return fill(area, cur_pen, map); }
|
2012-11-19 07:11:26 -07:00
|
|
|
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &tile(const Pen &pen, bool map = false) {
|
|
|
|
if (isValidPos()) paintTile(pen, gcursor.x, gcursor.y, map);
|
2012-11-19 07:11:26 -07:00
|
|
|
return advance(1);
|
|
|
|
}
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &tile(bool map = false) { return tile(cur_pen, map); }
|
|
|
|
Painter &tile(char ch, bool map = false) { return tile(cur_pen.chtile(ch), map); }
|
|
|
|
Painter &tile(char ch, int tileid, bool map = false) { return tile(cur_pen.chtile(ch, tileid), map); }
|
2012-11-19 07:11:26 -07:00
|
|
|
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &string(const std::string &str, const Pen &pen, bool map = false) {
|
|
|
|
do_paint_string(str, pen, map); return advance(str.size());
|
2012-11-19 07:11:26 -07:00
|
|
|
}
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &string(const std::string &str, bool map = false) { return string(str, cur_pen, map); }
|
|
|
|
Painter &string(const std::string &str, int8_t fg, bool map = false) { return string(str, cur_pen.color(fg), map); }
|
2012-11-19 07:11:26 -07:00
|
|
|
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &key(df::interface_key kc, const Pen &pen, bool map = false) {
|
|
|
|
return string(getKeyDisplay(kc), pen, map);
|
2012-11-19 07:11:26 -07:00
|
|
|
}
|
2015-12-22 09:42:51 -07:00
|
|
|
Painter &key(df::interface_key kc, bool map = false) { return key(kc, cur_key_pen, map); }
|
2012-11-19 07:11:26 -07:00
|
|
|
|
|
|
|
private:
|
2015-12-22 09:42:51 -07:00
|
|
|
void do_paint_string(const std::string &str, const Pen &pen, bool map = false);
|
2012-11-19 07:11:26 -07:00
|
|
|
};
|
2015-11-13 18:10:29 -07:00
|
|
|
|
|
|
|
namespace Hooks {
|
2017-05-31 10:12:15 -06:00
|
|
|
GUI_HOOK_DECLARE(get_tile, Pen, (int x, int y, bool map));
|
2017-06-01 22:40:14 -06:00
|
|
|
GUI_HOOK_DECLARE(set_tile, bool, (const Pen &pen, int x, int y, bool map));
|
2015-11-13 18:10:29 -07:00
|
|
|
}
|
|
|
|
|
2018-06-20 11:08:35 -06:00
|
|
|
//! Temporary hide a screen until destructor is called
|
|
|
|
struct DFHACK_EXPORT Hide {
|
2021-03-21 18:42:50 -06:00
|
|
|
Hide(df::viewscreen* screen, int flags = 0);
|
2018-06-20 11:08:35 -06:00
|
|
|
~Hide();
|
2021-03-21 18:42:50 -06:00
|
|
|
|
|
|
|
static const int RESTORE_AT_TOP = 0x1;
|
2018-06-20 11:08:35 -06:00
|
|
|
private:
|
2023-01-28 09:02:46 -07:00
|
|
|
void extract();
|
|
|
|
void merge();
|
2021-03-21 18:42:50 -06:00
|
|
|
df::viewscreen* screen;
|
2023-01-28 09:02:46 -07:00
|
|
|
df::viewscreen* prev_parent;
|
2021-03-21 18:42:50 -06:00
|
|
|
int flags;
|
2018-06-20 11:08:35 -06:00
|
|
|
};
|
2012-08-18 23:31:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
class DFHACK_EXPORT dfhack_viewscreen : public df::viewscreen {
|
2012-08-22 08:18:19 -06:00
|
|
|
df::coord2d last_size;
|
|
|
|
void check_resize();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool text_input_mode;
|
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
public:
|
|
|
|
dfhack_viewscreen();
|
|
|
|
virtual ~dfhack_viewscreen();
|
|
|
|
|
|
|
|
static bool is_instance(df::viewscreen *screen);
|
2012-09-20 01:11:20 -06:00
|
|
|
static dfhack_viewscreen *try_cast(df::viewscreen *screen);
|
2012-08-18 23:31:09 -06:00
|
|
|
|
2012-08-22 08:18:19 -06:00
|
|
|
virtual void logic();
|
|
|
|
virtual void render();
|
2022-12-16 12:26:05 -07:00
|
|
|
virtual void resize(int w, int h) { return; }
|
2012-08-22 08:18:19 -06:00
|
|
|
|
2012-08-22 02:23:56 -06:00
|
|
|
virtual int8_t movies_okay() { return 1; }
|
|
|
|
virtual bool key_conflict(df::interface_key key);
|
|
|
|
|
2012-08-19 04:27:44 -06:00
|
|
|
virtual bool is_lua_screen() { return false; }
|
2012-08-24 03:20:08 -06:00
|
|
|
|
2023-02-05 19:01:46 -07:00
|
|
|
virtual bool isFocused() { return true; }
|
2012-08-18 23:31:09 -06:00
|
|
|
virtual std::string getFocusString() = 0;
|
2012-08-24 03:20:08 -06:00
|
|
|
virtual void onShow() {};
|
|
|
|
virtual void onDismiss() {};
|
2017-05-05 12:45:46 -06:00
|
|
|
virtual df::unit *getSelectedUnit() { return nullptr; }
|
|
|
|
virtual df::item *getSelectedItem() { return nullptr; }
|
|
|
|
virtual df::job *getSelectedJob() { return nullptr; }
|
|
|
|
virtual df::building *getSelectedBuilding() { return nullptr; }
|
|
|
|
virtual df::plant *getSelectedPlant() { return nullptr; }
|
2018-07-22 16:27:22 -06:00
|
|
|
|
|
|
|
static virtual_identity _identity;
|
2012-08-18 23:31:09 -06:00
|
|
|
};
|
2012-08-19 04:27:44 -06:00
|
|
|
|
|
|
|
class DFHACK_EXPORT dfhack_lua_viewscreen : public dfhack_viewscreen {
|
|
|
|
std::string focus;
|
2023-02-05 19:01:46 -07:00
|
|
|
bool defocused = false;
|
2012-08-19 04:27:44 -06:00
|
|
|
|
|
|
|
void update_focus(lua_State *L, int idx);
|
|
|
|
|
|
|
|
bool safe_call_lua(int (*pf)(lua_State *), int args, int rvs);
|
|
|
|
static dfhack_lua_viewscreen *get_self(lua_State *L);
|
|
|
|
|
|
|
|
static int do_destroy(lua_State *L);
|
|
|
|
static int do_render(lua_State *L);
|
|
|
|
static int do_notify(lua_State *L);
|
|
|
|
static int do_input(lua_State *L);
|
|
|
|
|
2015-06-05 16:45:52 -06:00
|
|
|
bool allow_options;
|
2012-08-19 04:27:44 -06:00
|
|
|
public:
|
|
|
|
dfhack_lua_viewscreen(lua_State *L, int table_idx);
|
|
|
|
virtual ~dfhack_lua_viewscreen();
|
|
|
|
|
|
|
|
static df::viewscreen *get_pointer(lua_State *L, int idx, bool make);
|
|
|
|
|
|
|
|
virtual bool is_lua_screen() { return true; }
|
2023-02-05 19:01:46 -07:00
|
|
|
virtual bool isFocused() { return !defocused; }
|
2012-08-19 04:27:44 -06:00
|
|
|
virtual std::string getFocusString() { return focus; }
|
|
|
|
|
|
|
|
virtual void render();
|
|
|
|
virtual void logic();
|
|
|
|
virtual void help();
|
|
|
|
virtual void resize(int w, int h);
|
|
|
|
virtual void feed(std::set<df::interface_key> *keys);
|
2015-06-05 16:45:52 -06:00
|
|
|
virtual bool key_conflict(df::interface_key key);
|
2012-08-24 03:20:08 -06:00
|
|
|
|
|
|
|
virtual void onShow();
|
|
|
|
virtual void onDismiss();
|
2012-09-20 01:11:20 -06:00
|
|
|
|
|
|
|
virtual df::unit *getSelectedUnit();
|
|
|
|
virtual df::item *getSelectedItem();
|
|
|
|
virtual df::job *getSelectedJob();
|
|
|
|
virtual df::building *getSelectedBuilding();
|
2017-05-05 12:45:46 -06:00
|
|
|
virtual df::plant *getSelectedPlant();
|
2018-07-22 16:27:22 -06:00
|
|
|
|
|
|
|
static virtual_identity _identity;
|
2012-08-19 04:27:44 -06:00
|
|
|
};
|
2018-06-20 11:08:35 -06:00
|
|
|
|
2012-08-18 23:31:09 -06:00
|
|
|
}
|