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

# User Rev Content
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 sf-pippijn 1.6 #include <ndk/application.hh>
8     #include <ndk/color.hh>
9     #include <ndk/pen.hh>
10 sf-pippijn 1.1
11 sf-pippijn 1.6 #define HIGHLIGHT_PLAYER 0
12 sf-pippijn 1.5
13 sf-pippijn 1.1 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 sf-pippijn 1.7 int const W = this->width () / 2;
50     int const H = this->height ();
51 sf-pippijn 1.1 ndk::pen pen (*this);
52    
53 sf-pippijn 1.5 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 sf-pippijn 1.2 #endif
57 sf-pippijn 1.1
58 sf-pippijn 1.5 #if HIGHLIGHT_PLAYER
59 sf-pippijn 1.8 int const playerx = (W - !(W % 2)) / 2;
60     int const playery = (H - !(H % 2)) / 2;
61 sf-pippijn 1.2 #endif
62 sf-pippijn 1.1
63 sf-pippijn 1.7 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 sf-pippijn 1.1 {
70 sf-pippijn 1.7 int const mapy = y + map->y + offy;
71 sf-pippijn 1.1 if (!map->rows.has (mapy))
72     continue;
73 sf-pippijn 1.5 auto const &row = map->rows[mapy];
74 sf-pippijn 1.7 for (int x = 1; x < W - 1; x++)
75 sf-pippijn 1.1 {
76 sf-pippijn 1.7 int const mapx = x + map->x + offx;
77 sf-pippijn 1.1 if (!row.has (mapx))
78     continue;
79 sf-pippijn 1.5 data::map::cell const &cell = row[mapx];
80 sf-pippijn 1.1 u32 const face = select_face (cell.face, layer);
81    
82     data::glyph const *glyph;
83    
84 sf-pippijn 1.7 int const winy = y * 1;
85     int const winx = x * 2;
86 sf-pippijn 1.1
87 sf-pippijn 1.6 #if HIGHLIGHT_PLAYER
88 sf-pippijn 1.7 if (x == playerx && y == playery)
89 sf-pippijn 1.1 glyph = &player;
90 sf-pippijn 1.6 #else
91     if (0)
92     ;
93     #endif
94 sf-pippijn 1.1 else if (face && face < data::glyphs.size ()) // TODO: warn about face >= size
95     glyph = &data::glyphs[face];
96     else
97     glyph = &space;
98    
99 sf-pippijn 1.7 return_unless (winy >= 0);
100     return_unless (winx >= 0);
101     return_unless (winy < H);
102     return_unless (winx < W * 2);
103    
104 sf-pippijn 1.2 return_unless (pen.move (winx, winy));
105 sf-pippijn 1.1 write (pen, *glyph, cell.darkness);
106     }
107     }
108    
109 sf-pippijn 1.5 #if HIGHLIGHT_PLAYER
110 sf-pippijn 1.1 // 19:15 < n0nsense> pippijn: kannst du nethack-mäßig noch den cursor auf den player setzen?
111 sf-pippijn 1.5 if (active ())
112     {
113     pen.move (playerx, playery);
114     ndk::app->cursor_on ();
115     }
116     else
117     ndk::app->cursor_off ();
118 sf-pippijn 1.1 #endif
119    
120     if (getenv ("DCLIENT_ONESHOT"))
121     {
122 sf-pippijn 1.4 delete ndk::app;
123 sf-pippijn 1.1 exit (0);
124     }
125 sf-pippijn 1.5
126     pen.set_color ({ }); // reset
127 sf-pippijn 1.1 }