ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/client/widgets/map_widget.cpp
Revision: 1.8
Committed: Mon Oct 25 01:05:44 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +2 -2 lines
Log Message:
fixed player location

File Contents

# Content
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 #define HIGHLIGHT_PLAYER 0
12
13 map_widget::map_widget (ndk::panel *parent)
14 : frame ("", parent)
15 , map (nullptr)
16 {
17 }
18
19 void
20 map_widget::update (data::map const &map)
21 {
22 this->map = &map;
23 }
24
25
26 static u16
27 select_face (u16 const (&face)[3], int layer)
28 {
29 if (layer == -1)
30 return face[2]
31 ? face[2]
32 : face[1]
33 ? face[1]
34 : face[0]
35 ;
36 return face[layer];
37 }
38
39 void
40 map_widget::draw ()
41 {
42 frame::draw ();
43
44 if (!map)
45 return;
46
47 static int const layer = -1;
48
49 int const W = this->width () / 2;
50 int const H = this->height ();
51 ndk::pen pen (*this);
52
53 static data::glyph const space = { { { 0, 0, L' ' }, { 0, 0, L' ' } } };
54 #if HIGHLIGHT_PLAYER
55 static data::glyph const player = { { { 0, 0, L'@' }, { 13, 13, L'@' } } };
56 #endif
57
58 #if HIGHLIGHT_PLAYER
59 int const playerx = (W - !(W % 2)) / 2;
60 int const playery = (H - !(H % 2)) / 2;
61 #endif
62
63 int const offx = (map->w - W) / 2;
64 int const offy = (map->h - H) / 2;
65
66 return_unless (!data::glyphs.empty ());
67
68 for (int y = 1; y < H - 1; y++)
69 {
70 int const mapy = y + map->y + offy;
71 if (!map->rows.has (mapy))
72 continue;
73 auto const &row = map->rows[mapy];
74 for (int x = 1; x < W - 1; x++)
75 {
76 int const mapx = x + map->x + offx;
77 if (!row.has (mapx))
78 continue;
79 data::map::cell const &cell = row[mapx];
80 u32 const face = select_face (cell.face, layer);
81
82 data::glyph const *glyph;
83
84 int const winy = y * 1;
85 int const winx = x * 2;
86
87 #if HIGHLIGHT_PLAYER
88 if (x == playerx && y == playery)
89 glyph = &player;
90 #else
91 if (0)
92 ;
93 #endif
94 else if (face && face < data::glyphs.size ()) // TODO: warn about face >= size
95 glyph = &data::glyphs[face];
96 else
97 glyph = &space;
98
99 return_unless (winy >= 0);
100 return_unless (winx >= 0);
101 return_unless (winy < H);
102 return_unless (winx < W * 2);
103
104 return_unless (pen.move (winx, winy));
105 write (pen, *glyph, cell.darkness);
106 }
107 }
108
109 #if HIGHLIGHT_PLAYER
110 // 19:15 < n0nsense> pippijn: kannst du nethack-mäßig noch den cursor auf den player setzen?
111 if (active ())
112 {
113 pen.move (playerx, playery);
114 ndk::app->cursor_on ();
115 }
116 else
117 ndk::app->cursor_off ();
118 #endif
119
120 if (getenv ("DCLIENT_ONESHOT"))
121 {
122 delete ndk::app;
123 exit (0);
124 }
125
126 pen.set_color ({ }); // reset
127 }