… | |
… | |
6 | use List::Util qw(min max); |
6 | use List::Util qw(min max); |
7 | |
7 | |
8 | use CFPlus; |
8 | use CFPlus; |
9 | use CFPlus::OpenGL; |
9 | use CFPlus::OpenGL; |
10 | use CFPlus::UI; |
10 | use CFPlus::UI; |
|
|
11 | use CFPlus::Macro; |
11 | |
12 | |
12 | our @ISA = CFPlus::UI::Base::; |
13 | our @ISA = CFPlus::UI::Base::; |
13 | |
14 | |
14 | my $magicmap_tex = |
15 | my $magicmap_tex = |
15 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
16 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
… | |
… | |
20 | |
21 | |
21 | my $self = $class->SUPER::new ( |
22 | my $self = $class->SUPER::new ( |
22 | z => -1, |
23 | z => -1, |
23 | can_focus => 1, |
24 | can_focus => 1, |
24 | list => glGenList, |
25 | list => glGenList, |
25 | |
26 | tilesize => 32, |
26 | smooth_matrix => [ |
|
|
27 | 0.05, 0.13, 0.05, |
|
|
28 | 0.13, 0.30, 0.13, |
|
|
29 | 0.05, 0.13, 0.05, |
|
|
30 | ], |
|
|
31 | |
|
|
32 | @_ |
27 | @_ |
33 | ); |
28 | ); |
34 | |
29 | |
35 | $self->{completer} = new CFPlus::MapWidget::Command:: |
30 | $self->{completer} = new CFPlus::MapWidget::Command:: |
36 | command => $self->{command}, |
31 | command => $self->{command}, |
37 | tooltip => "<b>The Command Completer</b>\n\n" |
32 | tooltip => "#completer_help", |
38 | . "This is your central interface to send text commands to the server. " |
|
|
39 | . "To enter a verbatim command to send to the server, just type the command, " |
|
|
40 | . "followed by a space, and press return. " |
|
|
41 | . "Typing the initial letters of words (or just any letters) displays guesses " |
|
|
42 | . "for commands you might want to use.\n" |
|
|
43 | . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" |
|
|
44 | . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.", |
|
|
45 | ; |
33 | ; |
46 | |
34 | |
47 | $self |
35 | $self |
|
|
36 | } |
|
|
37 | |
|
|
38 | sub set_tilesize { |
|
|
39 | my ($self, $tilesize) = @_; |
|
|
40 | |
|
|
41 | $self->{tilesize} = $tilesize; |
48 | } |
42 | } |
49 | |
43 | |
50 | sub add_command { |
44 | sub add_command { |
51 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
45 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
52 | |
46 | |
… | |
… | |
66 | |
60 | |
67 | $self->{completer}->hide |
61 | $self->{completer}->hide |
68 | if $self->{completer}; |
62 | if $self->{completer}; |
69 | } |
63 | } |
70 | |
64 | |
|
|
65 | sub server_login { |
|
|
66 | my ($server) = @_; |
|
|
67 | |
|
|
68 | ::stop_game (); |
|
|
69 | local $::PROFILE->{host} = $server; |
|
|
70 | ::start_game (); |
|
|
71 | } |
|
|
72 | |
|
|
73 | sub editor_invoke { |
|
|
74 | my $editsup = $::CONN && $::CONN->{editor_support} |
|
|
75 | or return; |
|
|
76 | |
|
|
77 | CFPlus::background { |
|
|
78 | print "preparing editor startup...\n"; |
|
|
79 | |
|
|
80 | my $server = $editsup->{gameserver} || "default"; |
|
|
81 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
|
|
82 | |
|
|
83 | local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; |
|
|
84 | local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; |
|
|
85 | |
|
|
86 | print "map directory is $mapdir\n"; |
|
|
87 | print "lib directory is $libdir\n"; |
|
|
88 | |
|
|
89 | my $ua = CFPlus::lwp_useragent; |
|
|
90 | |
|
|
91 | for my $file (qw(archetypes crossfire.0)) { |
|
|
92 | my $url = "$editsup->{lib_root}$file"; |
|
|
93 | print "mirroring $url...\n"; |
|
|
94 | CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file"); |
|
|
95 | printf "%s size %d octets\n", $file, -s "$libdir/$file"; |
|
|
96 | } |
|
|
97 | |
|
|
98 | if (1) { # upload a map |
|
|
99 | my $mapname = $::CONN->{map_info}[0]; |
|
|
100 | |
|
|
101 | my $mappath = "$mapdir/$mapname"; |
|
|
102 | |
|
|
103 | -e $mappath and die "$mappath already exists\n"; |
|
|
104 | |
|
|
105 | print "getting map revision for $mapname...\n"; |
|
|
106 | |
|
|
107 | # try to get the most recent head revision, what a hack, |
|
|
108 | # this should have been returned while downloading *sigh* |
|
|
109 | my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
|
|
110 | |
|
|
111 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
|
|
112 | my $rev = $1; |
|
|
113 | |
|
|
114 | print "downloading revision $rev...\n"; |
|
|
115 | |
|
|
116 | my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; |
|
|
117 | |
|
|
118 | my $meta = { |
|
|
119 | %$editsup, |
|
|
120 | path => $mapname, |
|
|
121 | revision => $rev, |
|
|
122 | cf_login => $::PROFILE->{user}, |
|
|
123 | }; |
|
|
124 | |
|
|
125 | require File::Basename; |
|
|
126 | require File::Path; |
|
|
127 | |
|
|
128 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
|
|
129 | open my $fh, ">:raw:perlio", "$mappath.meta" |
|
|
130 | or die "$mappath.meta: $!\n"; |
|
|
131 | print $fh CFPlus::to_json $meta; |
|
|
132 | close $fh; |
|
|
133 | open my $fh, ">:raw:perlio:utf8", $mappath |
|
|
134 | or die "$mappath: $!\n"; |
|
|
135 | print $fh $map; |
|
|
136 | close $fh; |
|
|
137 | |
|
|
138 | print "saved as $mappath\n"; |
|
|
139 | |
|
|
140 | print "invoking editor...\n"; |
|
|
141 | exec "/root/s2/gce $mappath";#d# |
|
|
142 | |
|
|
143 | # now upload it |
|
|
144 | # require HTTP::Request::Common; |
|
|
145 | # |
|
|
146 | # my $res = $ua->post ( |
|
|
147 | # $ENV{CFPLUS_UPLOAD}, |
|
|
148 | # Content_Type => 'multipart/form-data', |
|
|
149 | # Content => [ |
|
|
150 | # path => $mapname, |
|
|
151 | # mapdir => $ENV{CROSSFIRE_MAPDIR}, |
|
|
152 | # map => $map, |
|
|
153 | # revision => $rev, |
|
|
154 | # cf_login => $ENV{CFPLUS_LOGIN}, |
|
|
155 | # cf_password => $ENV{CFPLUS_PASSWORD}, |
|
|
156 | # comment => "", |
|
|
157 | # ] |
|
|
158 | # ); |
|
|
159 | # |
|
|
160 | # if ($res->is_error) { |
|
|
161 | # # fatal condition |
|
|
162 | # warn $res->status_line; |
|
|
163 | # } else { |
|
|
164 | # # script replies are marked as {{..}} |
|
|
165 | # my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g; |
|
|
166 | # warn map "$_\n", @msgs; |
|
|
167 | # } |
|
|
168 | } else { |
|
|
169 | die "viewvc parse error, unable to detect revision\n"; |
|
|
170 | } |
|
|
171 | } |
|
|
172 | } |
|
|
173 | } |
|
|
174 | |
71 | sub invoke_button_down { |
175 | sub invoke_button_down { |
72 | my ($self, $ev, $x, $y) = @_; |
176 | my ($self, $ev, $x, $y) = @_; |
73 | |
177 | |
74 | if ($ev->{button} == 1) { |
178 | if ($ev->{button} == 1) { |
75 | $self->grab_focus; |
179 | $self->grab_focus; |
76 | return unless $::CONN; |
180 | return unless $::CONN; |
77 | |
181 | |
78 | my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
182 | my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
79 | my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
183 | my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
80 | |
184 | |
81 | $x -= int 0.5 * $self->{sw}; |
185 | $x -= CFPlus::floor $::MAP->w * 0.5; |
82 | $y -= int 0.5 * $self->{sh}; |
186 | $y -= CFPlus::floor $::MAP->h * 0.5; |
83 | |
187 | |
|
|
188 | if ($::CONN) { |
|
|
189 | if ($::IN_BUILD_MODE) { |
|
|
190 | $::CONN->buildat ($::IN_BUILD_MODE, $x, $y); |
|
|
191 | } else { |
84 | $::CONN->lookat ($x, $y) |
192 | $::CONN->lookat ($x, $y) |
85 | if $::CONN; |
193 | } |
|
|
194 | } |
86 | |
195 | |
87 | } elsif ($ev->{button} == 2) { |
196 | } elsif ($ev->{button} == 2) { |
88 | $self->grab_focus; |
197 | $self->grab_focus; |
89 | return unless $::CONN; |
198 | return unless $::CONN; |
90 | |
199 | |
… | |
… | |
100 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
209 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
101 | |
210 | |
102 | $self->update; |
211 | $self->update; |
103 | }; |
212 | }; |
104 | } elsif ($ev->{button} == 3) { |
213 | } elsif ($ev->{button} == 3) { |
105 | (new CFPlus::UI::Menu |
214 | my @items = ( |
106 | items => [ |
|
|
107 | ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], |
215 | ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], |
108 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
216 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
109 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
217 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
110 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
218 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
111 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
219 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
… | |
… | |
115 | $::PICKUP_ENABLE->{state} |
223 | $::PICKUP_ENABLE->{state} |
116 | ? "Disable automatic pickup" |
224 | ? "Disable automatic pickup" |
117 | : "Enable automatic pickup", |
225 | : "Enable automatic pickup", |
118 | sub { $::PICKUP_ENABLE->toggle } |
226 | sub { $::PICKUP_ENABLE->toggle } |
119 | ], |
227 | ], |
|
|
228 | ); |
|
|
229 | |
|
|
230 | if ($::CONN && $::CONN->{editor_support}) { |
|
|
231 | push @items, [ |
|
|
232 | "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", |
|
|
233 | \&editor_invoke, |
|
|
234 | ]; |
|
|
235 | |
|
|
236 | for my $type (qw(test name)) { |
|
|
237 | $::CONN->{editor_support}{type} ne $type |
|
|
238 | or next; |
|
|
239 | my $server = $::CONN->{editor_support}{"${type}server"} |
|
|
240 | or next; |
|
|
241 | |
|
|
242 | push @items, [ |
|
|
243 | "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>", |
|
|
244 | sub { server_login $server }, |
|
|
245 | ]; |
|
|
246 | } |
|
|
247 | } |
|
|
248 | |
|
|
249 | push @items, |
120 | ["Quit", |
250 | ["Quit", |
121 | sub { |
251 | sub { |
122 | if ($::CONN) { |
252 | if ($::CONN) { |
123 | &::open_quit_dialog; |
253 | &::open_quit_dialog; |
124 | } else { |
254 | } else { |
125 | exit; |
255 | exit; |
126 | } |
|
|
127 | } |
256 | } |
128 | ], |
257 | } |
129 | ], |
258 | ], |
|
|
259 | ; |
|
|
260 | |
|
|
261 | (new CFPlus::UI::Menu |
|
|
262 | items => \@items, |
130 | )->popup ($ev); |
263 | )->popup ($ev); |
131 | } |
264 | } |
132 | |
265 | |
133 | 1 |
266 | 1 |
134 | } |
267 | } |
… | |
… | |
152 | |
285 | |
153 | 1 |
286 | 1 |
154 | } |
287 | } |
155 | |
288 | |
156 | sub size_request { |
289 | sub size_request { |
|
|
290 | my ($self) = @_; |
|
|
291 | |
157 | ( |
292 | ( |
158 | 32 * CFPlus::ceil $::WIDTH / 32, |
293 | $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize}, |
159 | 32 * CFPlus::ceil $::HEIGHT / 32, |
294 | $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize}, |
160 | ) |
295 | ) |
161 | } |
296 | } |
162 | |
297 | |
163 | sub update { |
298 | sub update { |
164 | my ($self) = @_; |
299 | my ($self) = @_; |
… | |
… | |
166 | $self->{need_update} = 1; |
301 | $self->{need_update} = 1; |
167 | $self->SUPER::update; |
302 | $self->SUPER::update; |
168 | } |
303 | } |
169 | |
304 | |
170 | my %DIR = ( |
305 | my %DIR = ( |
|
|
306 | ( "," . CFPlus::SDLK_KP5 ), [0, "stay fire"], |
171 | CFPlus::SDLK_KP8, [1, "north"], |
307 | ( "," . CFPlus::SDLK_KP8 ), [1, "north"], |
172 | CFPlus::SDLK_KP9, [2, "northeast"], |
308 | ( "," . CFPlus::SDLK_KP9 ), [2, "northeast"], |
173 | CFPlus::SDLK_KP6, [3, "east"], |
309 | ( "," . CFPlus::SDLK_KP6 ), [3, "east"], |
174 | CFPlus::SDLK_KP3, [4, "southeast"], |
310 | ( "," . CFPlus::SDLK_KP3 ), [4, "southeast"], |
175 | CFPlus::SDLK_KP2, [5, "south"], |
311 | ( "," . CFPlus::SDLK_KP2 ), [5, "south"], |
176 | CFPlus::SDLK_KP1, [6, "southwest"], |
312 | ( "," . CFPlus::SDLK_KP1 ), [6, "southwest"], |
177 | CFPlus::SDLK_KP4, [7, "west"], |
313 | ( "," . CFPlus::SDLK_KP4 ), [7, "west"], |
178 | CFPlus::SDLK_KP7, [8, "northwest"], |
314 | ( "," . CFPlus::SDLK_KP7 ), [8, "northwest"], |
179 | |
315 | |
180 | CFPlus::SDLK_UP, [1, "north"], |
316 | ( "," . CFPlus::SDLK_UP ), [1, "north"], |
|
|
317 | ("1," . CFPlus::SDLK_UP ), [2, "northeast"], |
181 | CFPlus::SDLK_RIGHT, [3, "east"], |
318 | ( "," . CFPlus::SDLK_RIGHT), [3, "east"], |
|
|
319 | ("1," . CFPlus::SDLK_RIGHT), [4, "southeast"], |
182 | CFPlus::SDLK_DOWN, [5, "south"], |
320 | ( "," . CFPlus::SDLK_DOWN ), [5, "south"], |
|
|
321 | ("1," . CFPlus::SDLK_DOWN ), [6, "southwest"], |
183 | CFPlus::SDLK_LEFT, [7, "west"], |
322 | ( "," . CFPlus::SDLK_LEFT ), [7, "west"], |
|
|
323 | ("1," . CFPlus::SDLK_LEFT ), [8, "northwest"], |
184 | ); |
324 | ); |
185 | |
325 | |
186 | sub invoke_key_down { |
326 | sub invoke_key_down { |
187 | my ($self, $ev) = @_; |
327 | my ($self, $ev) = @_; |
188 | |
328 | |
… | |
… | |
190 | my $sym = $ev->{sym}; |
330 | my $sym = $ev->{sym}; |
191 | my $uni = $ev->{unicode}; |
331 | my $uni = $ev->{unicode}; |
192 | |
332 | |
193 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
333 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
194 | |
334 | |
195 | if ($uni == ord "\t") { |
335 | if ($sym == 9) { |
196 | $::PL_WINDOW->toggle_visibility; |
336 | ($mod & CFPlus::KMOD_SHIFT ? $::MESSAGE_WINDOW : $::PL_WINDOW)->toggle_visibility; |
197 | } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { |
337 | } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { |
198 | $::HELP_WINDOW->toggle_visibility; |
338 | $::HELP_WINDOW->toggle_visibility; |
199 | } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { |
339 | } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { |
200 | ::toggle_player_page ($::STATS_PAGE); |
340 | ::toggle_player_page ($::STATS_PAGE); |
201 | } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { |
341 | } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { |
… | |
… | |
204 | ::toggle_player_page ($::SPELL_PAGE); |
344 | ::toggle_player_page ($::SPELL_PAGE); |
205 | } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { |
345 | } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { |
206 | ::toggle_player_page ($::INVENTORY_PAGE); |
346 | ::toggle_player_page ($::INVENTORY_PAGE); |
207 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
347 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
208 | $::SETUP_DIALOG->toggle_visibility; |
348 | $::SETUP_DIALOG->toggle_visibility; |
209 | } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) { |
|
|
210 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
211 | sub { |
|
|
212 | my ($mod, $sym, $cmds) = @_; |
|
|
213 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
|
|
214 | }); |
|
|
215 | $::BIND_EDITOR->start; |
|
|
216 | $::BIND_EDITOR->show; |
|
|
217 | } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { |
|
|
218 | $::BIND_EDITOR->stop; |
|
|
219 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
220 | $::BIND_EDITOR->hide; |
|
|
221 | } elsif (!$::CONN) { |
349 | } elsif (!$::CONN) { |
222 | return 0; # bindings further down need a valid connection |
350 | return 0; # bindings further down need a valid connection |
223 | |
351 | |
224 | } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { |
|
|
225 | $::CONN->user_send ("stay fire"); |
|
|
226 | } elsif ($uni == ord ",") { |
352 | } elsif ($uni == ord ",") { |
227 | $::CONN->user_send ("take"); |
353 | $::CONN->user_send ("take"); |
228 | } elsif ($uni == ord " ") { |
354 | } elsif ($uni == ord " ") { |
229 | $::CONN->user_send ("apply"); |
355 | $::CONN->user_send ("apply"); |
|
|
356 | } elsif ($uni == 13) { |
|
|
357 | $::CONN->user_send ("examine"); |
230 | } elsif ($uni == ord ".") { |
358 | } elsif ($uni == ord ".") { |
231 | $::CONN->user_send ($self->{completer}{last_command}) |
359 | $::CONN->user_send ($self->{completer}{last_command}) |
232 | if exists $self->{completer}{last_command}; |
360 | if exists $self->{completer}{last_command}; |
233 | } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { |
361 | } elsif (my @macros = CFPlus::Macro::match_event $ev) { |
234 | $::CONN->user_send ($_) for @$bind_cmd; |
362 | $::CONN->macro_send ($_) for @macros; |
235 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
363 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
236 | $::CONN->user_send ("rotateshoottype +"); |
364 | $::CONN->user_send ("rotateshoottype +"); |
237 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
365 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
238 | $::CONN->user_send ("rotateshoottype -"); |
366 | $::CONN->user_send ("rotateshoottype -"); |
|
|
367 | } elsif ($uni == ord '!') { |
|
|
368 | $self->{completer}->set_prefix ("shout "); |
|
|
369 | $self->{completer}->show; |
239 | } elsif ($uni == ord '"') { |
370 | } elsif ($uni == ord '"') { |
240 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
371 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
241 | $self->{completer}->show; |
372 | $self->{completer}->show; |
242 | } elsif ($uni == ord "'") { |
373 | } elsif ($uni == ord "'") { |
243 | $self->{completer}->set_prefix (""); |
374 | $self->{completer}->set_prefix (""); |
244 | $self->{completer}->show; |
375 | $self->{completer}->show; |
245 | } elsif (exists $DIR{$sym}) { |
376 | } elsif (my $dir = $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"}) { |
246 | if ($mod & CFPlus::KMOD_SHIFT) { |
377 | if ($mod & CFPlus::KMOD_SHIFT) { |
247 | $self->{shft}++; |
378 | $self->{shft}++; |
248 | if ($DIR{$sym}[0] != $self->{fire_dir}) { |
379 | if ($dir->[0] != $self->{fire_dir}) { |
249 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
380 | $::CONN->user_send ("fire $dir->[0]"); |
250 | } |
381 | } |
251 | $self->{fire_dir} = $DIR{$sym}[0]; |
382 | $self->{fire_dir} = $DIR{$sym}[0]; |
252 | } elsif ($mod & CFPlus::KMOD_CTRL) { |
383 | } elsif ($mod & CFPlus::KMOD_CTRL) { |
253 | $self->{ctrl}++; |
384 | $self->{ctrl}++; |
254 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
385 | $::CONN->user_send ("run $dir->[0]"); |
255 | } else { |
386 | } else { |
256 | $::CONN->user_send ("$DIR{$sym}[1]"); |
387 | $::CONN->user_send ("$dir->[1]"); |
257 | } |
388 | } |
258 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
389 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
259 | $self->{completer}->inject_key_down ($ev); |
390 | $self->{completer}->inject_key_down ($ev); |
260 | $self->{completer}->show; |
391 | $self->{completer}->show; |
261 | } else { |
392 | } else { |
… | |
… | |
296 | } |
427 | } |
297 | |
428 | |
298 | $res |
429 | $res |
299 | } |
430 | } |
300 | |
431 | |
|
|
432 | sub invoke_visibility_change { |
|
|
433 | my ($self) = @_; |
|
|
434 | |
|
|
435 | $self->refresh_hook; |
|
|
436 | |
|
|
437 | 0 |
|
|
438 | } |
|
|
439 | |
301 | sub set_magicmap { |
440 | sub set_magicmap { |
302 | my ($self, $w, $h, $x, $y, $data) = @_; |
441 | my ($self, $w, $h, $x, $y, $data) = @_; |
303 | |
442 | |
304 | $x -= $::MAP->ox + int 0.5 * $::MAP->w; |
443 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
305 | $y -= $::MAP->oy + int 0.5 * $::MAP->h; |
444 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
306 | |
445 | |
307 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
446 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
308 | |
447 | |
309 | $self->update; |
448 | $self->update; |
310 | } |
449 | } |
311 | |
450 | |
312 | sub draw { |
451 | sub refresh_hook { |
313 | my ($self) = @_; |
452 | my ($self) = @_; |
314 | |
453 | |
315 | return unless $::MAP; |
454 | return unless $::MAP; |
316 | |
455 | |
317 | my $focused = $CFPlus::UI::FOCUS == $self |
|
|
318 | || $CFPlus::UI::FOCUS == $self->{completer}{entry}; |
|
|
319 | |
|
|
320 | return |
|
|
321 | unless $focused || !$::FAST; |
|
|
322 | |
|
|
323 | if (delete $self->{need_update}) { |
456 | if (delete $self->{need_update}) { |
324 | my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; |
457 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
325 | |
458 | |
|
|
459 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
|
|
460 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
|
|
461 | |
326 | my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
462 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
327 | my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
463 | my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
328 | |
464 | |
329 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
465 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
330 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
466 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
331 | |
467 | |
332 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
468 | my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
333 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
469 | my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
334 | |
470 | |
335 | if ($::CFG->{fow_enable}) { |
471 | if ($::CFG->{fow_enable}) { |
336 | my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); |
472 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
337 | |
|
|
338 | if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
339 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
340 | glConvolutionFilter2D ( |
|
|
341 | GL_CONVOLUTION_2D, |
|
|
342 | GL_ALPHA, |
|
|
343 | 3, 3, |
|
|
344 | GL_ALPHA, GL_FLOAT, |
|
|
345 | (pack "f*", @{ $self->{smooth_matrix} }), |
|
|
346 | ); |
|
|
347 | glEnable GL_CONVOLUTION_2D; |
|
|
348 | } |
|
|
349 | |
473 | |
350 | $self->{fow_texture} = new CFPlus::Texture |
474 | $self->{fow_texture} = new CFPlus::Texture |
351 | w => $w, |
475 | w => $w, |
352 | h => $h, |
476 | h => $h, |
353 | data => $data, |
477 | data => $data, |
354 | internalformat => GL_ALPHA, |
478 | internalformat => GL_ALPHA, |
355 | format => GL_ALPHA; |
479 | format => GL_ALPHA; |
356 | |
|
|
357 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
358 | } else { |
480 | } else { |
359 | delete $self->{fow_texture}; |
481 | delete $self->{fow_texture}; |
360 | } |
482 | } |
361 | |
483 | |
362 | glNewList $self->{list}; |
484 | glNewList $self->{list}; |
363 | |
485 | |
364 | glPushMatrix; |
486 | glPushMatrix; |
365 | glTranslate $sx0, $sy0; |
487 | glTranslate $sx0, $sy0; |
366 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
488 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
367 | |
489 | |
368 | $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); |
490 | $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}); |
369 | |
491 | |
370 | glScale 32, 32; |
492 | glScale $self->{tilesize}, $self->{tilesize}; |
371 | |
493 | |
372 | if (my $tex = $self->{fow_texture}) { |
494 | if (my $tex = $self->{fow_texture}) { |
|
|
495 | glPushMatrix; |
|
|
496 | glScale 1/3, 1/3; |
373 | glEnable GL_TEXTURE_2D; |
497 | glEnable GL_TEXTURE_2D; |
374 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
498 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
375 | |
499 | |
376 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
500 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
377 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
501 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
378 | |
502 | |
379 | glDisable GL_TEXTURE_2D; |
503 | glDisable GL_TEXTURE_2D; |
|
|
504 | glPopMatrix; |
380 | } |
505 | } |
381 | |
506 | |
382 | if ($self->{magicmap}) { |
507 | if ($self->{magicmap}) { |
383 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
508 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
384 | |
509 | |
385 | $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); |
510 | $x += $::MAP->ox + $self->{dx}; |
386 | $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); |
511 | $y += $::MAP->oy + $self->{dy}; |
387 | |
512 | |
388 | glTranslate - $x - 1, - $y - 1; |
513 | glTranslate - $x - 1, - $y - 1; |
389 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
514 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
390 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
515 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
391 | } |
516 | } |
392 | |
517 | |
393 | glPopMatrix; |
518 | glPopMatrix; |
394 | glEndList; |
519 | glEndList; |
395 | } |
520 | } |
|
|
521 | |
|
|
522 | } |
|
|
523 | |
|
|
524 | sub draw { |
|
|
525 | my ($self) = @_; |
|
|
526 | |
|
|
527 | $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); |
|
|
528 | |
|
|
529 | return unless $self->{list}; |
|
|
530 | |
|
|
531 | my $focused = $CFPlus::UI::FOCUS == $self |
|
|
532 | || $CFPlus::UI::FOCUS == $self->{completer}{entry}; |
|
|
533 | |
|
|
534 | return |
|
|
535 | unless $focused || !$::FAST; |
396 | |
536 | |
397 | glCallList $self->{list}; |
537 | glCallList $self->{list}; |
398 | |
538 | |
399 | # TNT2 emulates logops in software (or worse :) |
539 | # TNT2 emulates logops in software (or worse :) |
400 | unless ($focused) { |
540 | unless ($focused) { |
… | |
… | |
419 | $self->SUPER::DESTROY; |
559 | $self->SUPER::DESTROY; |
420 | } |
560 | } |
421 | |
561 | |
422 | package CFPlus::MapWidget::MapMap; |
562 | package CFPlus::MapWidget::MapMap; |
423 | |
563 | |
|
|
564 | use strict; |
|
|
565 | use utf8; |
|
|
566 | |
424 | our @ISA = CFPlus::UI::Base::; |
567 | our @ISA = CFPlus::UI::Base::; |
425 | |
568 | |
426 | use Time::HiRes qw(time); |
569 | use Time::HiRes qw(time); |
427 | use CFPlus::OpenGL; |
570 | use CFPlus::OpenGL; |
428 | |
571 | |
429 | sub size_request { |
572 | sub size_request { |
430 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
573 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
431 | } |
574 | } |
432 | |
575 | |
433 | sub invoke_size_allocate { |
576 | sub refresh_hook { |
434 | my ($self, $w, $h) = @_; |
577 | my ($self) = @_; |
435 | |
578 | |
436 | $self->update; |
579 | if ($::MAP && $self->{texture_atime} < time) { |
437 | |
|
|
438 | 1 |
|
|
439 | } |
|
|
440 | |
|
|
441 | sub update { |
|
|
442 | my ($self) = @_; |
|
|
443 | |
|
|
444 | delete $self->{texture_atime}; |
|
|
445 | $self->SUPER::update; |
|
|
446 | } |
|
|
447 | |
|
|
448 | sub _draw { |
|
|
449 | my ($self) = @_; |
|
|
450 | |
|
|
451 | $::MAP or return; |
|
|
452 | |
|
|
453 | my ($w, $h) = @$self{qw(w h)}; |
580 | my ($w, $h) = @$self{qw(w h)}; |
454 | |
581 | |
455 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
582 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
456 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
583 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
457 | |
584 | |
458 | my $sx = int $::CFG->{map_shift_x} / 32; |
|
|
459 | my $sy = int $::CFG->{map_shift_y} / 32; |
|
|
460 | |
|
|
461 | my $ox = 0.5 * ($w - $sw); |
585 | my $ox = 0.5 * ($w - $sw); |
462 | my $oy = 0.5 * ($h - $sh); |
586 | my $oy = 0.5 * ($h - $sh); |
463 | |
587 | |
464 | glEnable GL_BLEND; |
588 | my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize}; |
465 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
589 | my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize}; |
466 | glEnable GL_TEXTURE_2D; |
|
|
467 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
468 | |
590 | |
469 | if ($self->{texture_atime} < time) { |
591 | #TODO: map scale is completely borked |
|
|
592 | |
|
|
593 | my $x0 = int $ox - $sx + 0.5; |
|
|
594 | my $y0 = int $oy - $sy + 0.5; |
|
|
595 | |
|
|
596 | $self->{sw} = $sw; |
|
|
597 | $self->{sh} = $sh; |
|
|
598 | |
|
|
599 | $self->{x0} = $x0; |
|
|
600 | $self->{y0} = $y0; |
|
|
601 | |
470 | $self->{texture_atime} = time + 1/3; |
602 | $self->{texture_atime} = time + 1/3; |
471 | |
603 | |
472 | $self->{texture} = |
604 | $self->{texture} = |
473 | new CFPlus::Texture |
605 | new CFPlus::Texture |
474 | w => $w, |
606 | w => $w, |
475 | h => $h, |
607 | h => $h, |
476 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
608 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
477 | type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
609 | type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
478 | } |
610 | } |
|
|
611 | } |
|
|
612 | |
|
|
613 | sub invoke_visibility_change { |
|
|
614 | my ($self) = @_; |
|
|
615 | |
|
|
616 | $self->refresh_hook; |
|
|
617 | |
|
|
618 | 0 |
|
|
619 | } |
|
|
620 | |
|
|
621 | sub invoke_size_allocate { |
|
|
622 | my ($self, $w, $h) = @_; |
|
|
623 | |
|
|
624 | $self->update; |
|
|
625 | |
|
|
626 | 1 |
|
|
627 | } |
|
|
628 | |
|
|
629 | sub update { |
|
|
630 | my ($self) = @_; |
|
|
631 | |
|
|
632 | delete $self->{texture_atime}; |
|
|
633 | $self->SUPER::update; |
|
|
634 | } |
|
|
635 | |
|
|
636 | sub _draw { |
|
|
637 | my ($self) = @_; |
|
|
638 | |
|
|
639 | $self->{root}->on_post_alloc (texture => sub { $self->refresh_hook }); |
|
|
640 | |
|
|
641 | $self->{texture} or return; |
|
|
642 | |
|
|
643 | glEnable GL_BLEND; |
|
|
644 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
645 | glEnable GL_TEXTURE_2D; |
|
|
646 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
479 | |
647 | |
480 | $self->{texture}->draw_quad (0, 0); |
648 | $self->{texture}->draw_quad (0, 0); |
481 | |
649 | |
482 | glDisable GL_TEXTURE_2D; |
650 | glDisable GL_TEXTURE_2D; |
483 | |
651 | |
484 | glTranslate 0.375, 0.375; |
652 | glTranslate 0.375, 0.375; |
485 | |
|
|
486 | #TODO: map scale is completely borked |
|
|
487 | |
|
|
488 | my $x0 = int $ox - $sx + 0.5; |
|
|
489 | my $y0 = int $oy - $sy + 0.5; |
|
|
490 | |
653 | |
491 | glColor 1, 1, 0, 1; |
654 | glColor 1, 1, 0, 1; |
492 | glBegin GL_LINE_LOOP; |
655 | glBegin GL_LINE_LOOP; |
493 | glVertex $x0 , $y0 ; |
656 | glVertex $self->{x0} , $self->{y0} ; |
494 | glVertex $x0 , $y0 + $sh; |
657 | glVertex $self->{x0} , $self->{y0} + $self->{sh}; |
495 | glVertex $x0 + $sw, $y0 + $sh; |
658 | glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh}; |
496 | glVertex $x0 + $sw, $y0 ; |
659 | glVertex $self->{x0} + $self->{sw}, $self->{y0} ; |
497 | glEnd; |
660 | glEnd; |
498 | |
661 | |
499 | glDisable GL_BLEND; |
662 | glDisable GL_BLEND; |
500 | } |
663 | } |
501 | |
664 | |
… | |
… | |
537 | |
700 | |
538 | if ($ev->{button} == 3) { |
701 | if ($ev->{button} == 3) { |
539 | (new CFPlus::UI::Menu |
702 | (new CFPlus::UI::Menu |
540 | items => [ |
703 | items => [ |
541 | ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" |
704 | ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" |
542 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
705 | => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }] |
543 | ], |
706 | ], |
544 | )->popup ($ev); |
707 | )->popup ($ev); |
545 | return 1; |
708 | return 1; |
546 | } |
709 | } |
547 | 0 |
710 | 0 |
… | |
… | |
748 | |
911 | |
749 | $self->SUPER::_draw; |
912 | $self->SUPER::_draw; |
750 | } |
913 | } |
751 | |
914 | |
752 | 1 |
915 | 1 |
|
|
916 | |