1 |
1 |
2 #include "Graphics.hh" |
2 #include "Graphics.hh" |
3 #include "GameState.hh" |
3 #include "GameState.hh" |
4 #include <cmath> |
4 #include <cmath> |
5 #include <sstream> |
5 #include <sstream> |
|
6 |
|
7 /* |
|
8 * XXX: until we figure out a better way to layout stuff |
|
9 */ |
|
10 static PixelArea getMessageViewArea (PixelCoordinate resolution) { |
|
11 return PixelArea( |
|
12 400, |
|
13 resolution.y - 100, |
|
14 resolution.x, |
|
15 resolution.y |
|
16 ); |
|
17 } |
6 |
18 |
7 Graphics::Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen) : |
19 Graphics::Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen) : |
8 CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen), |
20 CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen), |
9 engine(engine), |
21 engine(engine), |
10 state(state), |
22 state(state), |
11 resolution(resolution), |
23 resolution(resolution), |
12 update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
24 update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
13 input(get_ic()->get_keyboard()), |
25 input(get_ic()->get_keyboard()), |
14 simple_font("Font2", engine.getResourceManager()) |
26 simple_font("Font2", engine.getResourceManager()), |
|
27 message_view(getMessageViewArea(resolution)) |
15 { |
28 { |
16 |
29 |
17 // connect timer signal |
30 // connect timer signal |
18 slots.connect(update_timer.sig_tick(), this, &Graphics::on_update); |
31 slots.connect(update_timer.sig_tick(), this, &Graphics::on_update); |
19 |
32 |
20 // enable |
33 // enable |
21 update_timer.start(); |
34 update_timer.start(); |
|
35 |
|
36 // push something to message_view |
|
37 message_view.add_message(CL_Color::white, "Hello World"); |
|
38 |
|
39 // GameState events.... |
|
40 state.setEventHandler(this); |
22 } |
41 } |
23 |
42 |
24 const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) { |
43 const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) { |
25 return CL_DisplayMode::get_display_modes(); |
44 return CL_DisplayMode::get_display_modes(); |
26 } |
45 } |
73 |
92 |
74 return; |
93 return; |
75 } |
94 } |
76 |
95 |
77 // dump player debug info on stderr |
96 // dump player debug info on stderr |
78 if ((flags & GUI_INPUT_DEBUG_PLAYER) && state.getLocalPlayer()) |
97 if ((flags & GUI_INPUT_DEBUG_PLAYER) && state.getLocalPlayer()) { |
79 state.getLocalPlayer()->printDebugInfo(); |
98 state.getLocalPlayer()->printDebugInfo(); |
|
99 |
|
100 message_view.add_message(CL_Color::green, "..."); |
|
101 } |
80 |
102 |
81 // toggle fullscreen? |
103 // toggle fullscreen? |
82 if (flags & GUI_INPUT_TOGGLE_FULLSCREEN) { |
104 if (flags & GUI_INPUT_TOGGLE_FULLSCREEN) { |
83 if (is_fullscreen()) |
105 if (is_fullscreen()) |
84 set_windowed(); |
106 set_windowed(); |
126 // Black background |
148 // Black background |
127 gc->clear(CL_Color::black); |
149 gc->clear(CL_Color::black); |
128 |
150 |
129 // Draw the game |
151 // Draw the game |
130 state.draw(this, camera, flags & GUI_INPUT_DISPLAY_WEAPON); |
152 state.draw(this, camera, flags & GUI_INPUT_DISPLAY_WEAPON); |
131 |
153 |
|
154 // draw player info box |
132 if (player != NULL) { |
155 if (player != NULL) { |
133 // draw player info box |
|
134 draw_player_info(gc, player); |
156 draw_player_info(gc, player); |
135 } |
157 } |
|
158 |
|
159 // draw messages |
|
160 message_view.draw(this); |
136 |
161 |
137 // Flip window buffer, sync |
162 // Flip window buffer, sync |
138 flip(1); |
163 flip(1); |
139 } |
164 } |
140 |
165 |
259 box_left + 20 + 100 * bar_length, |
284 box_left + 20 + 100 * bar_length, |
260 box_top + 70, |
285 box_top + 70, |
261 p->getCurrentWeapon()->getName(), |
286 p->getCurrentWeapon()->getName(), |
262 get_gc() |
287 get_gc() |
263 ); |
288 ); |
264 } |
289 |
265 |
290 } |
|
291 |
|
292 |
|
293 void Graphics::on_player_joined (Player *p) { |
|
294 message_view.add_message(CL_Color::white, " *** Player joined"); |
|
295 } |
|
296 |
|
297 void Graphics::on_player_left (Player *p) { |
|
298 message_view.add_message(CL_Color::white, " *** Player left"); |
|
299 } |