| 1 |
sf-pippijn |
1.1 |
#include "dclient/widgets/map.h" |
| 2 |
|
|
#include "dclient/render_glyph.h" |
| 3 |
|
|
|
| 4 |
|
|
#include "deliantra/data/glyph.h" |
| 5 |
|
|
#include "deliantra/data/map.h" |
| 6 |
|
|
|
| 7 |
|
|
#include <ndk++/application.hh> |
| 8 |
|
|
#include <ndk++/color.hh> |
| 9 |
|
|
#include <ndk++/pen.hh> |
| 10 |
|
|
|
| 11 |
|
|
map_widget::map_widget (ndk::panel *parent) |
| 12 |
|
|
: frame ("", parent) |
| 13 |
|
|
, map (nullptr) |
| 14 |
|
|
{ |
| 15 |
|
|
} |
| 16 |
|
|
|
| 17 |
|
|
void |
| 18 |
|
|
map_widget::update (data::map const &map) |
| 19 |
|
|
{ |
| 20 |
|
|
this->map = ↦ |
| 21 |
|
|
} |
| 22 |
|
|
|
| 23 |
|
|
|
| 24 |
|
|
static u16 |
| 25 |
|
|
select_face (u16 const (&face)[3], int layer) |
| 26 |
|
|
{ |
| 27 |
|
|
if (layer == -1) |
| 28 |
|
|
return face[2] |
| 29 |
|
|
? face[2] |
| 30 |
|
|
: face[1] |
| 31 |
|
|
? face[1] |
| 32 |
|
|
: face[0] |
| 33 |
|
|
; |
| 34 |
|
|
return face[layer]; |
| 35 |
|
|
} |
| 36 |
|
|
|
| 37 |
|
|
|
| 38 |
|
|
void |
| 39 |
|
|
map_widget::draw () |
| 40 |
|
|
{ |
| 41 |
|
|
frame::draw (); |
| 42 |
|
|
|
| 43 |
|
|
if (!map) |
| 44 |
|
|
return; |
| 45 |
|
|
|
| 46 |
|
|
static int const layer = -1; |
| 47 |
|
|
|
| 48 |
|
|
int const W = this->width () - 2; |
| 49 |
|
|
int const H = this->height () - 2; |
| 50 |
|
|
ndk::pen pen (*this); |
| 51 |
|
|
|
| 52 |
|
|
static data::glyph const space = { 0, 0, " " }; |
| 53 |
|
|
static data::glyph const player = { 0, 0, "@" }; |
| 54 |
|
|
|
| 55 |
|
|
int const zerox = -(W - map->w) / 2; |
| 56 |
|
|
int const zeroy = -(H - map->h) / 2; |
| 57 |
|
|
|
| 58 |
|
|
int const playerx = (W + 1 + (zerox > 0)) / 2; |
| 59 |
|
|
int const playery = (H + 1 + (zeroy > 0)) / 2; |
| 60 |
|
|
|
| 61 |
|
|
for (int y = zeroy; y < H + zeroy; y++) |
| 62 |
|
|
{ |
| 63 |
|
|
int const mapy = y + map->y; |
| 64 |
|
|
if (!map->rows.has (mapy)) |
| 65 |
|
|
continue; |
| 66 |
|
|
auto const &row = map->rows.at (mapy); |
| 67 |
|
|
for (int x = zerox; x < W + zerox; x++) |
| 68 |
|
|
{ |
| 69 |
|
|
int const mapx = x + map->x; |
| 70 |
|
|
if (!row.has (mapx)) |
| 71 |
|
|
continue; |
| 72 |
|
|
data::map::cell const &cell = row.at (mapx); |
| 73 |
|
|
u32 const face = select_face (cell.face, layer); |
| 74 |
|
|
|
| 75 |
|
|
data::glyph const *glyph; |
| 76 |
|
|
|
| 77 |
|
|
int const winy = y - zeroy + 1; |
| 78 |
|
|
int const winx = x - zerox + 1; |
| 79 |
|
|
|
| 80 |
|
|
if (winx == playerx && winy == playery) |
| 81 |
|
|
glyph = &player; |
| 82 |
|
|
else if (face && face < data::glyphs.size ()) // TODO: warn about face >= size |
| 83 |
|
|
glyph = &data::glyphs[face]; |
| 84 |
|
|
else |
| 85 |
|
|
glyph = &space; |
| 86 |
|
|
|
| 87 |
|
|
pen.move (winx, winy); |
| 88 |
|
|
write (pen, *glyph, cell.darkness); |
| 89 |
|
|
} |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
#if 0 |
| 93 |
|
|
// 19:15 < n0nsense> pippijn: kannst du nethack-mäßig noch den cursor auf den player setzen? |
| 94 |
|
|
pen.move (playerx, playery); |
| 95 |
|
|
ndk::app ().cursor_on (); |
| 96 |
|
|
#endif |
| 97 |
|
|
|
| 98 |
|
|
if (getenv ("DCLIENT_ONESHOT")) |
| 99 |
|
|
{ |
| 100 |
|
|
delete &ndk::app (); |
| 101 |
|
|
exit (0); |
| 102 |
|
|
} |
| 103 |
|
|
} |