1 | package CFClient::MapWidget; |
1 | package CFPlus::MapWidget; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use List::Util qw(min max); |
6 | use List::Util qw(min max); |
7 | |
7 | |
|
|
8 | use CFPlus; |
8 | use CFClient::OpenGL; |
9 | use CFPlus::OpenGL; |
|
|
10 | use CFPlus::UI; |
9 | |
11 | |
10 | our @ISA = CFClient::UI::Base::; |
12 | our @ISA = CFPlus::UI::Base::; |
|
|
13 | |
|
|
14 | my $magicmap_tex = |
|
|
15 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
|
|
16 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
11 | |
17 | |
12 | sub new { |
18 | sub new { |
13 | my $class = shift; |
19 | my $class = shift; |
14 | |
20 | |
15 | my $self = $class->SUPER::new ( |
21 | my $self = $class->SUPER::new ( |
… | |
… | |
24 | ], |
30 | ], |
25 | |
31 | |
26 | @_ |
32 | @_ |
27 | ); |
33 | ); |
28 | |
34 | |
29 | $self->{completer} = new CFClient::MapWidget::Command:: |
35 | $self->{completer} = new CFPlus::MapWidget::Command:: |
30 | command => $self->{command}, |
36 | command => $self->{command}, |
31 | can_focus => 1, |
37 | tooltip => "#completer_help", |
32 | tooltip => "<b>The Command Completer</b>\n\n" |
|
|
33 | . "This is your central interface to send text commands to the server. " |
|
|
34 | . "To enter a verbatim command to send to the server, just type the command, " |
|
|
35 | . "followed by a space, and press return. " |
|
|
36 | . "Typing the initial letters of words (or just any letters) displays guesses " |
|
|
37 | . "for commands you might want to use.\n" |
|
|
38 | . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" |
|
|
39 | . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.", |
|
|
40 | ; |
38 | ; |
41 | |
39 | |
42 | $self |
40 | $self |
43 | } |
41 | } |
44 | |
42 | |
… | |
… | |
56 | |
54 | |
57 | sub clr_commands { |
55 | sub clr_commands { |
58 | my ($self) = @_; |
56 | my ($self) = @_; |
59 | |
57 | |
60 | %{$self->{completer}{command}} = (); |
58 | %{$self->{completer}{command}} = (); |
61 | } |
|
|
62 | |
59 | |
|
|
60 | $self->{completer}->hide |
|
|
61 | if $self->{completer}; |
|
|
62 | } |
|
|
63 | |
|
|
64 | sub test_server_login { |
|
|
65 | return unless |
|
|
66 | $::CONN && length $::CONN->{test_server}; |
|
|
67 | |
|
|
68 | my $server = $::CONN->{test_server}; |
|
|
69 | ::stop_game (); |
|
|
70 | local $::PROFILE->{host} = $server; |
|
|
71 | ::start_game (); |
|
|
72 | } |
|
|
73 | |
|
|
74 | sub editor_invoke { |
|
|
75 | return unless $::CONN; |
|
|
76 | |
|
|
77 | # putting the password into the env is somewhat tasteless |
|
|
78 | local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user}; |
|
|
79 | local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password}; |
|
|
80 | local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload}; |
|
|
81 | local $ENV{CROSSFIRE_MAPDIR} = $::CONN->{cvs_root}; |
|
|
82 | |
|
|
83 | # CFPlus::set_proxy; |
|
|
84 | |
|
|
85 | # TODO: move into editor |
|
|
86 | require LWP::Simple; |
|
|
87 | } |
|
|
88 | |
63 | sub button_down { |
89 | sub invoke_button_down { |
64 | my ($self, $ev, $x, $y) = @_; |
90 | my ($self, $ev, $x, $y) = @_; |
65 | |
91 | |
66 | $self->focus_in; |
|
|
67 | |
|
|
68 | if ($ev->{button} == 1) { |
92 | if ($ev->{button} == 1) { |
69 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
93 | $self->grab_focus; |
70 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
94 | return unless $::CONN; |
71 | |
95 | |
72 | my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99; |
96 | my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
73 | my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99; |
97 | my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
74 | |
98 | |
75 | $::CONN->send (sprintf "lookat %d %d", $fx, $fy) |
99 | $x -= int 0.5 * $self->{sw}; |
|
|
100 | $y -= int 0.5 * $self->{sh}; |
|
|
101 | |
|
|
102 | $::CONN->lookat ($x, $y) |
76 | if $::CONN; |
103 | if $::CONN; |
77 | |
104 | |
78 | } elsif ($ev->{button} == 2) { |
105 | } elsif ($ev->{button} == 2) { |
|
|
106 | $self->grab_focus; |
|
|
107 | return unless $::CONN; |
|
|
108 | |
79 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
109 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
80 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
110 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
81 | |
111 | |
82 | $self->{motion} = sub { |
112 | $self->{motion} = sub { |
83 | my ($ev, $x, $y) = @_; |
113 | my ($ev, $x, $y) = @_; |
… | |
… | |
87 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
117 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
88 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
118 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
89 | |
119 | |
90 | $self->update; |
120 | $self->update; |
91 | }; |
121 | }; |
|
|
122 | } elsif ($ev->{button} == 3) { |
|
|
123 | (new CFPlus::UI::Menu |
|
|
124 | items => [ |
|
|
125 | ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], |
|
|
126 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
|
|
127 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
|
|
128 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
|
|
129 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
|
|
130 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
|
|
131 | ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
|
|
132 | [ |
|
|
133 | $::PICKUP_ENABLE->{state} |
|
|
134 | ? "Disable automatic pickup" |
|
|
135 | : "Enable automatic pickup", |
|
|
136 | sub { $::PICKUP_ENABLE->toggle } |
|
|
137 | ], |
|
|
138 | $::CONN && length $::CONN->{cvs_root} |
|
|
139 | ? ["Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", \&editor_invoke] |
|
|
140 | : (), |
|
|
141 | $::CONN && length $::CONN->{test_server} |
|
|
142 | ? ["Login on Test Server", \&test_server_login] |
|
|
143 | : (), |
|
|
144 | ["Quit", |
|
|
145 | sub { |
|
|
146 | if ($::CONN) { |
|
|
147 | &::open_quit_dialog; |
|
|
148 | } else { |
|
|
149 | exit; |
|
|
150 | } |
|
|
151 | } |
|
|
152 | ], |
|
|
153 | ], |
|
|
154 | )->popup ($ev); |
92 | } |
155 | } |
93 | |
156 | |
94 | 1 |
157 | 1 |
95 | } |
158 | } |
96 | |
159 | |
97 | sub button_up { |
160 | sub invoke_button_up { |
98 | my ($self, $ev, $x, $y) = @_; |
161 | my ($self, $ev, $x, $y) = @_; |
99 | |
162 | |
100 | delete $self->{motion}; |
163 | delete $self->{motion}; |
101 | |
164 | |
102 | 1 |
165 | 1 |
103 | } |
166 | } |
104 | |
167 | |
105 | sub mouse_motion { |
168 | sub invoke_mouse_motion { |
106 | my ($self, $ev, $x, $y) = @_; |
169 | my ($self, $ev, $x, $y) = @_; |
107 | |
170 | |
108 | if ($self->{motion}) { |
171 | if ($self->{motion}) { |
109 | $self->{motion}->($ev, $x, $y); |
172 | $self->{motion}->($ev, $x, $y); |
110 | } else { |
173 | } else { |
… | |
… | |
114 | 1 |
177 | 1 |
115 | } |
178 | } |
116 | |
179 | |
117 | sub size_request { |
180 | sub size_request { |
118 | ( |
181 | ( |
119 | 1 + 32 * int $::WIDTH / 32, |
182 | 32 * CFPlus::ceil $::WIDTH / 32, |
120 | 1 + 32 * int $::HEIGHT / 32, |
183 | 32 * CFPlus::ceil $::HEIGHT / 32, |
121 | ) |
184 | ) |
122 | } |
185 | } |
123 | |
186 | |
124 | sub update { |
187 | sub update { |
125 | my ($self) = @_; |
188 | my ($self) = @_; |
… | |
… | |
127 | $self->{need_update} = 1; |
190 | $self->{need_update} = 1; |
128 | $self->SUPER::update; |
191 | $self->SUPER::update; |
129 | } |
192 | } |
130 | |
193 | |
131 | my %DIR = ( |
194 | my %DIR = ( |
132 | CFClient::SDLK_KP8, [1, "north"], |
195 | CFPlus::SDLK_KP8, [1, "north"], |
133 | CFClient::SDLK_KP9, [2, "northeast"], |
196 | CFPlus::SDLK_KP9, [2, "northeast"], |
134 | CFClient::SDLK_KP6, [3, "east"], |
197 | CFPlus::SDLK_KP6, [3, "east"], |
135 | CFClient::SDLK_KP3, [4, "southeast"], |
198 | CFPlus::SDLK_KP3, [4, "southeast"], |
136 | CFClient::SDLK_KP2, [5, "south"], |
199 | CFPlus::SDLK_KP2, [5, "south"], |
137 | CFClient::SDLK_KP1, [6, "southwest"], |
200 | CFPlus::SDLK_KP1, [6, "southwest"], |
138 | CFClient::SDLK_KP4, [7, "west"], |
201 | CFPlus::SDLK_KP4, [7, "west"], |
139 | CFClient::SDLK_KP7, [8, "northwest"], |
202 | CFPlus::SDLK_KP7, [8, "northwest"], |
140 | |
203 | |
141 | CFClient::SDLK_UP, [1, "north"], |
204 | CFPlus::SDLK_UP, [1, "north"], |
142 | CFClient::SDLK_RIGHT, [3, "east"], |
205 | CFPlus::SDLK_RIGHT, [3, "east"], |
143 | CFClient::SDLK_DOWN, [5, "south"], |
206 | CFPlus::SDLK_DOWN, [5, "south"], |
144 | CFClient::SDLK_LEFT, [7, "west"], |
207 | CFPlus::SDLK_LEFT, [7, "west"], |
145 | ); |
208 | ); |
146 | |
209 | |
147 | sub key_down { |
210 | sub invoke_key_down { |
148 | my ($self, $ev) = @_; |
211 | my ($self, $ev) = @_; |
149 | |
|
|
150 | return 0 unless $::CONN; |
|
|
151 | |
212 | |
152 | my $mod = $ev->{mod}; |
213 | my $mod = $ev->{mod}; |
153 | my $sym = $ev->{sym}; |
214 | my $sym = $ev->{sym}; |
154 | my $uni = $ev->{unicode}; |
215 | my $uni = $ev->{unicode}; |
155 | |
216 | |
156 | if ($sym == CFClient::SDLK_KP5) { |
217 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
|
|
218 | |
|
|
219 | if ($uni == ord "\t") { |
|
|
220 | $::PL_WINDOW->toggle_visibility; |
|
|
221 | } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { |
|
|
222 | $::HELP_WINDOW->toggle_visibility; |
|
|
223 | } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { |
|
|
224 | ::toggle_player_page ($::STATS_PAGE); |
|
|
225 | } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { |
|
|
226 | ::toggle_player_page ($::SKILL_PAGE); |
|
|
227 | } elsif ($sym == CFPlus::SDLK_F4 && !$mod) { |
|
|
228 | ::toggle_player_page ($::SPELL_PAGE); |
|
|
229 | } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { |
|
|
230 | ::toggle_player_page ($::INVENTORY_PAGE); |
|
|
231 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
|
|
232 | $::SETUP_DIALOG->toggle_visibility; |
|
|
233 | } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) { |
|
|
234 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
235 | sub { |
|
|
236 | my ($mod, $sym, $cmds) = @_; |
|
|
237 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
|
|
238 | }); |
|
|
239 | $::BIND_EDITOR->start; |
|
|
240 | $::BIND_EDITOR->show; |
|
|
241 | #TODO: elmex, what was this supposed to do? it currently crashes the client. |
|
|
242 | # } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { |
|
|
243 | # $::BIND_EDITOR->stop; |
|
|
244 | # $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
245 | # $::BIND_EDITOR->hide; |
|
|
246 | } elsif (!$::CONN) { |
|
|
247 | return 0; # bindings further down need a valid connection |
|
|
248 | |
|
|
249 | } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { |
157 | $::CONN->user_send ("stay fire"); |
250 | $::CONN->user_send ("stay fire"); |
158 | } elsif ($uni == ord ",") { |
251 | } elsif ($uni == ord ",") { |
159 | $::CONN->user_send ("take"); |
252 | $::CONN->user_send ("take"); |
160 | } elsif ($uni == ord " ") { |
253 | } elsif ($uni == ord " ") { |
161 | $::CONN->user_send ("apply"); |
254 | $::CONN->user_send ("apply"); |
|
|
255 | } elsif ($uni == 13) { |
|
|
256 | $::CONN->user_send ("examine"); |
162 | } elsif ($uni == ord ".") { |
257 | } elsif ($uni == ord ".") { |
163 | $::CONN->user_send ($self->{completer}{last_command}) |
258 | $::CONN->user_send ($self->{completer}{last_command}) |
164 | if exists $self->{completer}{last_command}; |
259 | if exists $self->{completer}{last_command}; |
165 | } elsif ($uni == ord "\t") { |
260 | } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) { |
166 | $::INV_WINDOW->toggle_visibility; |
261 | $::CONN->user_send ($_) for @$bind_cmd; |
167 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
262 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
168 | $::CONN->user_send ("rotateshoottype +"); |
263 | $::CONN->user_send ("rotateshoottype +"); |
169 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
264 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
170 | $::CONN->user_send ("rotateshoottype -"); |
265 | $::CONN->user_send ("rotateshoottype -"); |
171 | } elsif ($uni == ord '"') { |
266 | } elsif ($uni == ord '"') { |
172 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
267 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
173 | $self->{completer}->show; |
268 | $self->{completer}->show; |
174 | } elsif ($uni == ord "'") { |
269 | } elsif ($uni == ord "'") { |
175 | $self->{completer}->set_prefix (""); |
270 | $self->{completer}->set_prefix (""); |
176 | $self->{completer}->show; |
271 | $self->{completer}->show; |
177 | } elsif (exists $DIR{$sym}) { |
272 | } elsif (exists $DIR{$sym}) { |
178 | if ($mod & CFClient::KMOD_SHIFT) { |
273 | if ($mod & CFPlus::KMOD_SHIFT) { |
179 | $self->{shft}++; |
274 | $self->{shft}++; |
|
|
275 | if ($DIR{$sym}[0] != $self->{fire_dir}) { |
180 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
276 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
277 | } |
|
|
278 | $self->{fire_dir} = $DIR{$sym}[0]; |
181 | } elsif ($mod & CFClient::KMOD_CTRL) { |
279 | } elsif ($mod & CFPlus::KMOD_CTRL) { |
182 | $self->{ctrl}++; |
280 | $self->{ctrl}++; |
183 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
281 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
184 | } else { |
282 | } else { |
185 | $::CONN->user_send ("$DIR{$sym}[1]"); |
283 | $::CONN->user_send ("$DIR{$sym}[1]"); |
186 | } |
284 | } |
187 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
188 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
189 | sub { |
|
|
190 | my ($mod, $sym, $cmds) = @_; |
|
|
191 | $::CFG->{bindings}->{$mod}->{$sym} = $cmds; |
|
|
192 | }); |
|
|
193 | $::BIND_EDITOR->start; |
|
|
194 | $::BIND_EDITOR->show; |
|
|
195 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
196 | $::BIND_EDITOR->stop; |
|
|
197 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
198 | $::BIND_EDITOR->hide; |
|
|
199 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
|
|
200 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
201 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
285 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
202 | $self->{completer}->key_down ($ev); |
286 | $self->{completer}->inject_key_down ($ev); |
203 | $self->{completer}->show; |
287 | $self->{completer}->show; |
204 | } else { |
288 | } else { |
205 | return 0; |
289 | return 0; |
206 | } |
290 | } |
207 | |
291 | |
208 | 1 |
292 | 1 |
209 | } |
293 | } |
210 | |
294 | |
211 | sub key_up { |
295 | sub invoke_key_up { |
212 | my ($self, $ev) = @_; |
296 | my ($self, $ev) = @_; |
213 | |
297 | |
214 | my $res = 0; |
298 | my $res = 0; |
215 | my $mod = $ev->{mod}; |
299 | my $mod = $ev->{mod}; |
216 | my $sym = $ev->{sym}; |
300 | my $sym = $ev->{sym}; |
217 | |
301 | |
|
|
302 | if ($::CFG->{shift_fire_stop}) { |
218 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
303 | if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) { |
219 | $::CONN->user_send ("fire_stop"); |
304 | $::CONN->user_send ("fire_stop"); |
|
|
305 | delete $self->{fire_dir}; |
220 | $res = 1; |
306 | $res = 1; |
|
|
307 | } |
|
|
308 | } else { |
|
|
309 | if (exists $DIR{$sym} && delete $self->{shft}) { |
|
|
310 | $::CONN->user_send ("fire_stop"); |
|
|
311 | delete $self->{fire_dir}; |
|
|
312 | $res = 1; |
|
|
313 | } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? |
|
|
314 | $::CONN->user_send ("fire_stop"); |
|
|
315 | delete $self->{fire_dir}; |
|
|
316 | $res = 1; |
|
|
317 | } |
221 | } |
318 | } |
222 | |
319 | |
223 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
320 | if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) { |
224 | $::CONN->user_send ("run_stop"); |
321 | $::CONN->user_send ("run_stop"); |
225 | $res = 1; |
322 | $res = 1; |
226 | } |
323 | } |
227 | |
324 | |
228 | $res |
325 | $res |
229 | } |
326 | } |
230 | |
327 | |
|
|
328 | sub set_magicmap { |
|
|
329 | my ($self, $w, $h, $x, $y, $data) = @_; |
|
|
330 | |
|
|
331 | $x -= $::MAP->ox + int 0.5 * $::MAP->w; |
|
|
332 | $y -= $::MAP->oy + int 0.5 * $::MAP->h; |
|
|
333 | |
|
|
334 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
|
|
335 | |
|
|
336 | $self->update; |
|
|
337 | } |
|
|
338 | |
231 | sub draw { |
339 | sub draw { |
232 | my ($self) = @_; |
340 | my ($self) = @_; |
233 | |
341 | |
|
|
342 | return unless $::MAP; |
|
|
343 | |
234 | my $focused = $CFClient::UI::FOCUS == $self |
344 | my $focused = $CFPlus::UI::FOCUS == $self |
235 | || $CFClient::UI::FOCUS == $self->{completer}{entry}; |
345 | || $CFPlus::UI::FOCUS == $self->{completer}{entry}; |
236 | |
346 | |
237 | return |
347 | return |
238 | unless $focused || !$::FAST; |
348 | unless $focused || !$::FAST; |
239 | |
349 | |
240 | if (delete $self->{need_update}) { |
350 | if (delete $self->{need_update}) { |
|
|
351 | my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; |
|
|
352 | |
|
|
353 | my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
|
|
354 | my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
|
|
355 | |
|
|
356 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
|
|
357 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
|
|
358 | |
|
|
359 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
|
|
360 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
|
|
361 | |
|
|
362 | if ($::CFG->{fow_enable}) { |
|
|
363 | my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); |
|
|
364 | |
|
|
365 | if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
366 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
367 | glConvolutionFilter2D ( |
|
|
368 | GL_CONVOLUTION_2D, |
|
|
369 | GL_ALPHA, |
|
|
370 | 3, 3, |
|
|
371 | GL_ALPHA, GL_FLOAT, |
|
|
372 | (pack "f*", @{ $self->{smooth_matrix} }), |
|
|
373 | ); |
|
|
374 | glEnable GL_CONVOLUTION_2D; |
|
|
375 | } |
|
|
376 | |
|
|
377 | $self->{fow_texture} = new CFPlus::Texture |
|
|
378 | w => $w, |
|
|
379 | h => $h, |
|
|
380 | data => $data, |
|
|
381 | internalformat => GL_ALPHA, |
|
|
382 | format => GL_ALPHA; |
|
|
383 | |
|
|
384 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
385 | } else { |
|
|
386 | delete $self->{fow_texture}; |
|
|
387 | } |
|
|
388 | |
241 | glNewList $self->{list}; |
389 | glNewList $self->{list}; |
242 | |
390 | |
243 | if ($::MAP) { |
|
|
244 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
245 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
246 | |
|
|
247 | my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
248 | my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
249 | |
|
|
250 | glPushMatrix; |
391 | glPushMatrix; |
|
|
392 | glTranslate $sx0, $sy0; |
251 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
393 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
252 | |
394 | |
253 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
395 | $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); |
254 | |
396 | |
255 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
397 | glScale 32, 32; |
256 | |
398 | |
257 | if ($::CFG->{fow_enable}) { |
399 | if (my $tex = $self->{fow_texture}) { |
258 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
259 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
260 | glConvolutionFilter2D ( |
|
|
261 | GL_CONVOLUTION_2D, |
|
|
262 | GL_ALPHA, |
|
|
263 | 3, 3, |
|
|
264 | GL_ALPHA, GL_FLOAT, |
|
|
265 | (pack "f*", @{ $self->{smooth_matrix} }), |
|
|
266 | ); |
|
|
267 | glEnable GL_CONVOLUTION_2D; |
|
|
268 | } |
|
|
269 | |
|
|
270 | $self->{fow_texture_name} ||= glGenTexture; |
|
|
271 | # try to re-use the texture name: TODO improve texture class instead |
|
|
272 | |
|
|
273 | $self->{fow_texture} = new CFClient::Texture |
|
|
274 | w => $w, |
|
|
275 | h => $h, |
|
|
276 | data => $data, |
|
|
277 | name => $self->{fow_texture_name}, |
|
|
278 | internalformat => GL_ALPHA, |
|
|
279 | format => GL_ALPHA; |
|
|
280 | |
|
|
281 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
282 | |
|
|
283 | glEnable GL_TEXTURE_2D; |
400 | glEnable GL_TEXTURE_2D; |
284 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
401 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
285 | |
402 | |
286 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
403 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
287 | $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); |
404 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
288 | |
405 | |
289 | glDisable GL_TEXTURE_2D; |
406 | glDisable GL_TEXTURE_2D; |
290 | } |
407 | } |
291 | |
408 | |
|
|
409 | if ($self->{magicmap}) { |
|
|
410 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
|
|
411 | |
|
|
412 | $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); |
|
|
413 | $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); |
|
|
414 | |
|
|
415 | glTranslate - $x - 1, - $y - 1; |
|
|
416 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
|
|
417 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
|
|
418 | } |
|
|
419 | |
292 | glPopMatrix; |
420 | glPopMatrix; |
293 | } |
|
|
294 | |
|
|
295 | glEndList; |
421 | glEndList; |
296 | } |
422 | } |
297 | |
423 | |
298 | glPushMatrix; |
|
|
299 | glCallList $self->{list}; |
424 | glCallList $self->{list}; |
300 | glPopMatrix; |
|
|
301 | |
425 | |
302 | # TNT2 emulates logops in software (or worse :) |
426 | # TNT2 emulates logops in software (or worse :) |
303 | if ($focused) { |
427 | unless ($focused) { |
304 | (delete $self->{out_of_focus})->destroy |
|
|
305 | if $self->{out_of_focus}; |
|
|
306 | } else { |
|
|
307 | glColor 0.4, 0.2, 0.2, 0.6; |
428 | glColor 0.4, 0.2, 0.2, 0.6; |
308 | glEnable GL_BLEND; |
429 | glEnable GL_BLEND; |
309 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
430 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
310 | glBegin GL_QUADS; |
431 | glBegin GL_QUADS; |
311 | glVertex 0, 0; |
432 | glVertex 0, 0; |
312 | glVertex 0, $::HEIGHT; |
433 | glVertex 0, $::HEIGHT; |
313 | glVertex $::WIDTH, $::HEIGHT; |
434 | glVertex $::WIDTH, $::HEIGHT; |
314 | glVertex $::WIDTH, 0; |
435 | glVertex $::WIDTH, 0; |
315 | glEnd; |
436 | glEnd; |
316 | glDisable GL_BLEND; |
437 | glDisable GL_BLEND; |
317 | |
|
|
318 | # $self->{out_of_focus} ||= do { |
|
|
319 | # my $label = new CFClient::UI::Label |
|
|
320 | # x => 0, |
|
|
321 | # y => 0, |
|
|
322 | # z => 1, |
|
|
323 | # ellipsise => 0, |
|
|
324 | # text => "map out of focus (click map to play)"; |
|
|
325 | # |
|
|
326 | # $label->show; |
|
|
327 | # $label->update; |
|
|
328 | # |
|
|
329 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
|
|
330 | # $label->move_abs ( |
|
|
331 | # ($::WIDTH - $label->{w}) * 0.5, |
|
|
332 | # ($::HEIGHT - $label->{h}) * 0.5, |
|
|
333 | # ); |
|
|
334 | # }); |
|
|
335 | # |
|
|
336 | # $label |
|
|
337 | # }; |
|
|
338 | } |
438 | } |
339 | } |
439 | } |
340 | |
440 | |
341 | sub DESTROY { |
441 | sub DESTROY { |
342 | my $self = shift; |
442 | my $self = shift; |
… | |
… | |
344 | glDeleteList $self->{list}; |
444 | glDeleteList $self->{list}; |
345 | |
445 | |
346 | $self->SUPER::DESTROY; |
446 | $self->SUPER::DESTROY; |
347 | } |
447 | } |
348 | |
448 | |
349 | package CFClient::MapWidget::MapMap; |
449 | package CFPlus::MapWidget::MapMap; |
350 | |
450 | |
351 | our @ISA = CFClient::UI::Base::; |
451 | our @ISA = CFPlus::UI::Base::; |
352 | |
452 | |
353 | use Time::HiRes qw(time); |
453 | use Time::HiRes qw(time); |
354 | use CFClient::OpenGL; |
454 | use CFPlus::OpenGL; |
355 | |
455 | |
356 | sub size_request { |
456 | sub size_request { |
357 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
457 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
358 | } |
458 | } |
359 | |
459 | |
360 | sub size_allocate { |
460 | sub invoke_size_allocate { |
361 | my ($self, $w, $h) = @_; |
461 | my ($self, $w, $h) = @_; |
362 | |
462 | |
363 | $self->SUPER::size_allocate ($w, $h); |
|
|
364 | $self->update; |
463 | $self->update; |
|
|
464 | |
|
|
465 | 1 |
365 | } |
466 | } |
366 | |
467 | |
367 | sub update { |
468 | sub update { |
368 | my ($self) = @_; |
469 | my ($self) = @_; |
369 | |
470 | |
… | |
… | |
394 | |
495 | |
395 | if ($self->{texture_atime} < time) { |
496 | if ($self->{texture_atime} < time) { |
396 | $self->{texture_atime} = time + 1/3; |
497 | $self->{texture_atime} = time + 1/3; |
397 | |
498 | |
398 | $self->{texture} = |
499 | $self->{texture} = |
399 | new CFClient::Texture |
500 | new CFPlus::Texture |
400 | w => $w, |
501 | w => $w, |
401 | h => $h, |
502 | h => $h, |
402 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
503 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
403 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
504 | type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
404 | } |
505 | } |
405 | |
506 | |
406 | $self->{texture}->draw_quad (0, 0); |
507 | $self->{texture}->draw_quad (0, 0); |
407 | |
508 | |
408 | glDisable GL_TEXTURE_2D; |
509 | glDisable GL_TEXTURE_2D; |
… | |
… | |
423 | glEnd; |
524 | glEnd; |
424 | |
525 | |
425 | glDisable GL_BLEND; |
526 | glDisable GL_BLEND; |
426 | } |
527 | } |
427 | |
528 | |
428 | package CFClient::MapWidget::Command; |
529 | package CFPlus::MapWidget::Command; |
429 | |
530 | |
430 | use strict; |
531 | use strict; |
431 | |
532 | |
432 | use CFClient::OpenGL; |
533 | use CFPlus::OpenGL; |
433 | |
534 | |
434 | our @ISA = CFClient::UI::Frame::; |
535 | our @ISA = CFPlus::UI::Frame::; |
435 | |
536 | |
436 | sub new { |
537 | sub new { |
437 | my $class = shift; |
538 | my $class = shift; |
438 | |
539 | |
439 | my $self = $class->SUPER::new ( |
540 | my $self = $class->SUPER::new ( |
440 | bg => [0, 0, 0, 0.8], |
541 | bg => [0, 0, 0, 0.8], |
441 | @_, |
542 | @_, |
442 | ); |
543 | ); |
443 | |
544 | |
444 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
545 | $self->add ($self->{vbox} = new CFPlus::UI::VBox); |
445 | |
546 | |
446 | $self->{label} = [ |
547 | $self->{label} = [ |
447 | map |
548 | map |
448 | CFClient::UI::Label->new ( |
549 | CFPlus::UI::Label->new ( |
449 | can_hover => 1, |
550 | can_hover => 1, |
450 | can_events => 1, |
551 | can_events => 1, |
451 | tooltip_width => 0.33, |
552 | tooltip_width => 0.33, |
452 | fontsize => $_, |
553 | fontsize => $_, |
453 | ), (0.8) x 16 |
554 | ), (0.8) x 16 |
454 | ]; |
555 | ]; |
455 | |
556 | |
456 | $self->{entry} = new CFClient::UI::Entry |
557 | $self->{entry} = new CFPlus::UI::Entry |
457 | on_changed => sub { |
558 | on_changed => sub { |
458 | $self->update_labels; |
559 | $self->update_labels; |
|
|
560 | 0 |
|
|
561 | }, |
|
|
562 | on_button_down => sub { |
|
|
563 | my ($entry, $ev, $x, $y) = @_; |
|
|
564 | |
|
|
565 | if ($ev->{button} == 3) { |
|
|
566 | (new CFPlus::UI::Menu |
|
|
567 | items => [ |
|
|
568 | ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" |
|
|
569 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
|
|
570 | ], |
|
|
571 | )->popup ($ev); |
|
|
572 | return 1; |
|
|
573 | } |
|
|
574 | 0 |
459 | }, |
575 | }, |
460 | on_key_down => sub { |
576 | on_key_down => sub { |
461 | my ($entry, $ev) = @_; |
577 | my ($entry, $ev) = @_; |
462 | |
578 | |
463 | my $self = $entry->{parent}{parent}; |
579 | my $self = $entry->{parent}{parent}; |
… | |
… | |
465 | if ($ev->{sym} == 13) { |
581 | if ($ev->{sym} == 13) { |
466 | if (exists $self->{select}) { |
582 | if (exists $self->{select}) { |
467 | $self->{last_command} = $self->{select}; |
583 | $self->{last_command} = $self->{select}; |
468 | $::CONN->user_send ($self->{select}); |
584 | $::CONN->user_send ($self->{select}); |
469 | |
585 | |
470 | unshift @{$self->{history}}, $self->{select}; |
586 | unshift @{$self->{history}}, $self->{entry}->get_text; |
471 | $self->{hist_ptr} = 0; |
587 | $self->{hist_ptr} = 0; |
472 | |
588 | |
473 | $self->hide; |
589 | $self->hide; |
474 | } |
590 | } |
475 | } elsif ($ev->{sym} == 27) { |
591 | } elsif ($ev->{sym} == 27) { |
476 | $self->{hist_ptr} = 0; |
592 | $self->{hist_ptr} = 0; |
477 | $self->hide; |
593 | $self->hide; |
478 | return; |
|
|
479 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
594 | } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) { |
480 | if ($self->{hist_ptr} > 1) { |
595 | if ($self->{hist_ptr} > 1) { |
481 | $self->{hist_ptr}--; |
596 | $self->{hist_ptr}--; |
482 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
597 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
483 | } elsif ($self->{hist_ptr} > 0) { |
598 | } elsif ($self->{hist_ptr} > 0) { |
484 | $self->{hist_ptr}--; |
599 | $self->{hist_ptr}--; |
… | |
… | |
486 | } else { |
601 | } else { |
487 | ++$self->{select_offset} |
602 | ++$self->{select_offset} |
488 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
603 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
489 | } |
604 | } |
490 | $self->update_labels; |
605 | $self->update_labels; |
491 | } elsif ($ev->{sym} == CFClient::SDLK_UP) { |
606 | } elsif ($ev->{sym} == CFPlus::SDLK_UP) { |
492 | if ($self->{select_offset}) { |
607 | if ($self->{select_offset}) { |
493 | --$self->{select_offset} |
608 | --$self->{select_offset} |
494 | } else { |
609 | } else { |
495 | unless ($self->{hist_ptr}) { |
610 | unless ($self->{hist_ptr}) { |
496 | $self->{hist_saveback} = $self->{entry}->get_text; |
611 | $self->{hist_saveback} = $self->{entry}->get_text; |
… | |
… | |
523 | |
638 | |
524 | $self->{entry}->set_text ($prefix); |
639 | $self->{entry}->set_text ($prefix); |
525 | $self->show; |
640 | $self->show; |
526 | } |
641 | } |
527 | |
642 | |
528 | sub size_allocate { |
643 | sub invoke_size_allocate { |
529 | my ($self, $w, $h) = @_; |
644 | my ($self, $w, $h) = @_; |
530 | |
645 | |
531 | $self->SUPER::size_allocate ($w, $h); |
|
|
532 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
646 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
|
|
647 | |
|
|
648 | $self->SUPER::invoke_size_allocate ($w, $h) |
533 | } |
649 | } |
534 | |
650 | |
535 | sub show { |
651 | sub show { |
536 | my ($self) = @_; |
652 | my ($self) = @_; |
537 | |
653 | |
538 | $self->SUPER::show; |
654 | $self->SUPER::show; |
539 | $self->{entry}->focus_in; |
655 | $self->{entry}->grab_focus; |
540 | } |
656 | } |
541 | |
657 | |
542 | sub hide { |
658 | sub hide { |
543 | my ($self) = @_; |
659 | my ($self) = @_; |
|
|
660 | |
|
|
661 | $self->{hist_ptr} = 0; |
544 | |
662 | |
545 | $self->SUPER::hide; |
663 | $self->SUPER::hide; |
546 | $self->{entry}->set_text (""); |
664 | $self->{entry}->set_text (""); |
547 | } |
665 | } |
548 | |
666 | |
549 | sub key_down { |
667 | sub inject_key_down { |
550 | my ($self, $ev) = @_; |
668 | my ($self, $ev) = @_; |
551 | |
669 | |
|
|
670 | $self->{entry}->grab_focus; |
552 | $self->{entry}->key_down ($ev) |
671 | $self->{entry}->emit (key_down => $ev); |
553 | } |
672 | } |
554 | |
673 | |
555 | sub update_labels { |
674 | sub update_labels { |
556 | my ($self) = @_; |
675 | my ($self) = @_; |
557 | |
676 | |
… | |
… | |
644 | $label->set_text (""); |
763 | $label->set_text (""); |
645 | $label->set_tooltip (""); |
764 | $label->set_tooltip (""); |
646 | } |
765 | } |
647 | |
766 | |
648 | $self->update; |
767 | $self->update; |
649 | ### |
|
|
650 | } |
768 | } |
651 | |
769 | |
652 | sub _draw { |
770 | sub _draw { |
653 | my ($self) = @_; |
771 | my ($self) = @_; |
654 | |
772 | |
655 | # hack |
773 | # hack |
656 | local $CFClient::UI::FOCUS = $self->{entry}; |
774 | local $CFPlus::UI::FOCUS = $self->{entry}; |
657 | |
775 | |
658 | $self->SUPER::_draw; |
776 | $self->SUPER::_draw; |
659 | } |
777 | } |
660 | |
778 | |
661 | 1 |
779 | 1 |