-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add painting tiles to the world map port #4711
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ distribution. | |
|
||
#include "df/viewscreen.h" | ||
#include "df/graphic_viewportst.h" | ||
#include "df/graphic_map_portst.h" | ||
|
||
#include <set> | ||
#include <memory> | ||
|
@@ -203,6 +204,12 @@ namespace DFHack | |
/// Retrieves one screen tile from the buffer | ||
DFHACK_EXPORT Pen readTile(int x, int y, bool map = false, int32_t * df::graphic_viewportst::*texpos_field = NULL); | ||
|
||
/// Paint one world map tile with the given pen | ||
DFHACK_EXPORT bool paintTileMapPort(const Pen &pen, int x, int y, int32_t * df::graphic_map_portst::*texpos_field = NULL); | ||
|
||
/// Retrieves one world map tile from the buffer | ||
// DFHACK_EXPORT Pen readTile(int x, int y, int32_t * df::graphic_map_portst::*texpos_field = NULL); | ||
|
||
/// Paint a string onto the screen. Ignores ch and tile of pen. | ||
DFHACK_EXPORT bool paintString(const Pen &pen, int x, int y, const std::string &text, bool map = false); | ||
|
||
|
@@ -315,6 +322,8 @@ namespace DFHack | |
namespace Hooks { | ||
GUI_HOOK_DECLARE(get_tile, Pen, (int x, int y, bool map, int32_t * df::graphic_viewportst::*texpos_field)); | ||
GUI_HOOK_DECLARE(set_tile, bool, (const Pen &pen, int x, int y, bool map, int32_t * df::graphic_viewportst::*texpos_field)); | ||
// GUI_HOOK_DECLARE(get_tile_map_port, Pen, (int x, int y, int32_t * df::graphic_map_portst::*texpos_field)); | ||
GUI_HOOK_DECLARE(set_tile_map_port, bool, (const Pen &pen, int x, int y, int32_t * df::graphic_map_portst::*texpos_field)); | ||
Comment on lines
+325
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't bother with this. This is a deprecated construct leftover from TWBT. You can just directly implement the new paint function without the GUI_HOOK redirection. |
||
} | ||
|
||
//! Temporary hide a screen until destructor is called | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,6 +365,41 @@ Pen Screen::readTile(int x, int y, bool map, int32_t * df::graphic_viewportst::* | |
return doGetTile(x, y, map, texpos_field); | ||
} | ||
|
||
static bool doSetTile_map_port(const Pen &pen, int x, int y, int32_t * df::graphic_map_portst::*texpos_field) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure you handle ASCII mode properly |
||
auto &vp = gps->main_map_port; | ||
if (!texpos_field) | ||
texpos_field = &df::graphic_map_portst::screentexpos_interface; | ||
|
||
if (x < 0 || x >= vp->dim_x || y < 0 || y >= vp->dim_y) | ||
return false; | ||
|
||
size_t max_index = vp->dim_y * vp->dim_x - 1; | ||
size_t index = (y * vp->dim_x) + x; | ||
|
||
if (index > max_index) | ||
return false; | ||
|
||
long texpos = pen.tile; | ||
if (!texpos && pen.ch) | ||
texpos = init->font.large_font_texpos[(uint8_t)pen.ch]; | ||
(vp->*texpos_field)[index] = texpos; | ||
return true; | ||
} | ||
|
||
GUI_HOOK_DEFINE(Screen::Hooks::set_tile_map_port, doSetTile_map_port); | ||
static bool doSetTileMapPort(const Pen &pen, int x, int y, int32_t * df::graphic_map_portst::*texpos_field = NULL) | ||
{ | ||
return GUI_HOOK_TOP(Screen::Hooks::set_tile_map_port)(pen, x, y, texpos_field); | ||
} | ||
|
||
bool Screen::paintTileMapPort(const Pen &pen, int x, int y, int32_t * df::graphic_map_portst::*texpos_field) | ||
{ | ||
if (!gps || !pen.valid()) return false; | ||
|
||
doSetTileMapPort(pen, x, y, texpos_field); | ||
return true; | ||
} | ||
|
||
bool Screen::paintString(const Pen &pen, int x, int y, const std::string &text, bool map) | ||
{ | ||
auto dim = getWindowSize(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not support this too?