1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Glib; |
6 | use Time::HiRes 'time'; |
7 | use Gtk2 -init; |
|
|
8 | |
|
|
9 | use SDL; |
|
|
10 | use SDL::App; |
|
|
11 | use SDL::Event; |
7 | use Event; |
12 | use SDL::Surface; |
|
|
13 | use SDL::OpenGL; |
|
|
14 | use SDL::OpenGL::Constants; |
|
|
15 | |
8 | |
16 | use Crossfire; |
9 | use Crossfire; |
17 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
18 | |
11 | |
|
|
12 | use Compress::LZF; |
|
|
13 | |
19 | use CFClient; |
14 | use CFClient; |
20 | use CFClient::UI; |
15 | use CFClient::UI; |
|
|
16 | use CFClient::MapWidget; |
21 | |
17 | |
22 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
23 | |
19 | |
24 | my $MAX_FPS = 60; |
20 | my $MAX_FPS = 60; |
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
21 | my $MIN_FPS = 5; # unused as of yet |
26 | |
22 | |
|
|
23 | our $META_SERVER = "crossfire.real-time.com:13326"; |
|
|
24 | |
|
|
25 | our $FACEMAP; |
|
|
26 | our $TILECACHE; |
27 | our $FACECACHE; |
27 | our $MAPCACHE; |
|
|
28 | |
|
|
29 | our $LAST_REFRESH; |
|
|
30 | our $NOW; |
28 | |
31 | |
29 | our $CFG; |
32 | our $CFG; |
30 | our $CONN; |
33 | our $CONN; |
|
|
34 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
31 | |
35 | |
32 | our @SDL_MODES; |
36 | our @SDL_MODES; |
33 | our $WIDTH; |
37 | our $WIDTH; |
34 | our $HEIGHT; |
38 | our $HEIGHT; |
35 | our $FULLSCREEN; |
39 | our $FULLSCREEN; |
|
|
40 | our $FONTSIZE; |
36 | |
41 | |
37 | our $NOW; |
42 | our $MAP; |
38 | |
|
|
39 | our $MAPWIDGET; |
43 | our $MAPWIDGET; |
40 | our $FONTSIZE; |
44 | our $BUTTONBAR; |
|
|
45 | our $LOGVIEW; |
|
|
46 | our $CONSOLE; |
|
|
47 | our $METASERVER; |
41 | |
48 | |
|
|
49 | our $GAUGES; |
|
|
50 | our $STATWIDS; |
|
|
51 | |
42 | our $SDL_TIMER; |
52 | our $SDL_ACTIVE; |
43 | our $SDL_APP; |
|
|
44 | our $SDL_EV; |
|
|
45 | our %SDL_CB; |
53 | our %SDL_CB; |
|
|
54 | |
|
|
55 | our $SDL_MIXER; |
|
|
56 | our @SOUNDS; # event => file mapping |
|
|
57 | our %AUDIO_CHUNKS; # audio files |
46 | |
58 | |
47 | our $ALT_ENTER_MESSAGE; |
59 | our $ALT_ENTER_MESSAGE; |
48 | our $STATUS_LINE; |
60 | our $STATUS_LINE; |
49 | our $DEBUG_STATUS; |
61 | our $DEBUG_STATUS; |
50 | |
62 | |
51 | my $last_refresh; |
63 | sub status { |
52 | my %ANIMATE; |
64 | $STATUS_LINE->set_text ($_[0]); |
53 | my $refresh_handler; |
65 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
|
|
66 | } |
54 | |
67 | |
55 | our ($tw, $te); # Test widget #d# |
68 | sub debug { |
|
|
69 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
70 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
|
|
71 | } |
56 | |
72 | |
57 | sub init_screen { |
73 | sub start_game { |
58 | $SDL_APP = new SDL::App |
74 | status "logging in..."; |
59 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
|
|
60 | -title => "Crossfire+ Client", |
|
|
61 | -width => $WIDTH, |
|
|
62 | -height => $HEIGHT, |
|
|
63 | -opengl => 1, |
|
|
64 | -red_size => 5, |
|
|
65 | -green_size => 5, |
|
|
66 | -blue_size => 5, |
|
|
67 | -alpha_size => 0, |
|
|
68 | -double_buffer => 1, |
|
|
69 | -fullscreen => $FULLSCREEN, |
|
|
70 | -resizeable => 0; |
|
|
71 | |
75 | |
72 | $SDL_EV = new SDL::Event; |
76 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
73 | $SDL_EV->set_unicode (1); |
|
|
74 | |
77 | |
75 | $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { |
78 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
76 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
77 | while $SDL_EV->poll; |
|
|
78 | |
79 | |
79 | 1 |
80 | $MAP = new CFClient::Map $mapsize, $mapsize; |
80 | }; |
|
|
81 | |
81 | |
82 | $last_refresh = SDL::GetTicks; |
82 | my ($host, $port) = split /:/, $CFG->{host}; |
83 | |
|
|
84 | CFClient::gl_init; |
|
|
85 | |
|
|
86 | $FONTSIZE = int $HEIGHT / 40; |
|
|
87 | |
|
|
88 | ############################################################################# |
|
|
89 | |
|
|
90 | glClearColor 0.45, 0.45, 0.45, 1; |
|
|
91 | |
|
|
92 | glEnable GL_TEXTURE_2D; |
|
|
93 | glEnable GL_COLOR_MATERIAL; |
|
|
94 | glShadeModel GL_FLAT; |
|
|
95 | glDisable GL_DEPTH_TEST; |
|
|
96 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
97 | |
|
|
98 | ############################################################################# |
|
|
99 | |
|
|
100 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
|
|
101 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
102 | |
83 | |
103 | $STATUS_LINE = new CFClient::UI::Label |
|
|
104 | padding => 0, |
|
|
105 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
|
|
106 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
|
|
107 | |
|
|
108 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
109 | padding => 0, |
|
|
110 | y => $HEIGHT * 49 / 50, |
|
|
111 | height => $HEIGHT / 50, |
|
|
112 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
113 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
114 | |
|
|
115 | $MAPWIDGET = new CFClient::UI::MapWidget; |
|
|
116 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
|
|
117 | $MAPWIDGET->focus_in; |
|
|
118 | } |
|
|
119 | |
|
|
120 | sub destroy_screen { |
|
|
121 | remove Glib::Source $SDL_TIMER; |
|
|
122 | undef $SDL_APP; |
|
|
123 | undef $SDL_EV; |
|
|
124 | SDL::Quit; |
|
|
125 | } |
|
|
126 | |
|
|
127 | sub config_dialog { |
|
|
128 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
|
|
129 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
130 | $vbox->add (new CFClient::UI::Label align => 0, text => "Setup"); |
|
|
131 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
132 | |
|
|
133 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
|
|
134 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
|
|
135 | |
|
|
136 | $hbox->add (my $mode_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
137 | $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); |
|
|
138 | |
|
|
139 | $mode_slider->connect (changed => sub { |
|
|
140 | my (undef, $value) = @_; |
|
|
141 | |
|
|
142 | $CFG->{sdl_mode} = $value = int $value + 0.5; |
|
|
143 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
144 | }); |
|
|
145 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
|
|
146 | |
|
|
147 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Host"); |
|
|
148 | $table->add (1, 1, my $host = new CFClient::UI::Entry text => $CFG->{host}); |
|
|
149 | |
|
|
150 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Port"); |
|
|
151 | $table->add (1, 2, my $port = new CFClient::UI::Entry text => $CFG->{port}); |
|
|
152 | |
|
|
153 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Username"); |
|
|
154 | $table->add (1, 3, my $user = new CFClient::UI::Entry text => $CFG->{user}); |
|
|
155 | |
|
|
156 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Password"); |
|
|
157 | $table->add (1, 4, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); |
|
|
158 | |
|
|
159 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Map Size"); |
|
|
160 | $table->add (1, 5, my $mapsize_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{mapsize}, 10, 100 + 1, 1]); |
|
|
161 | |
|
|
162 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
163 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
|
|
164 | warn "save\n"; |
|
|
165 | }); |
|
|
166 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
|
|
167 | warn "login\n"; |
|
|
168 | }); |
|
|
169 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
170 | warn "apply\n"; |
|
|
171 | }); |
|
|
172 | |
|
|
173 | $CFClient::UI::TOPLEVEL->add ($dialog); |
|
|
174 | } |
|
|
175 | |
|
|
176 | sub start_game { |
|
|
177 | $WIDTH = $CFG->{width}; |
|
|
178 | $HEIGHT = $CFG->{height}; |
|
|
179 | $FULLSCREEN = 0; |
|
|
180 | |
|
|
181 | init_screen; |
|
|
182 | |
|
|
183 | config_dialog; |
|
|
184 | |
|
|
185 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
186 | |
|
|
187 | $CONN = new conn |
84 | $CONN = new conn |
188 | host => $CFG->{host}, |
85 | host => $host, |
189 | port => $CFG->{port}, |
86 | port => $port || 13327, |
190 | user => $CFG->{user}, |
87 | user => $CFG->{user}, |
191 | pass => $CFG->{password}, |
88 | pass => $CFG->{password}, |
192 | mapw => $mapsize, |
89 | mapw => $mapsize, |
193 | maph => $mapsize, |
90 | maph => $mapsize, |
194 | ; |
91 | ; |
195 | |
92 | |
|
|
93 | status "login successful"; |
|
|
94 | |
196 | CFClient::lowdelay fileno $CONN->{fh}; |
95 | CFClient::lowdelay fileno $CONN->{fh}; |
197 | } |
96 | } |
198 | |
97 | |
199 | sub stop_game { |
98 | sub stop_game { |
200 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
201 | undef $refresh_handler; |
|
|
202 | |
|
|
203 | undef $CONN; |
99 | undef $CONN; |
204 | destroy_screen; |
|
|
205 | } |
100 | } |
206 | |
101 | |
207 | sub force_refresh { |
102 | sub client_setup { |
208 | glViewport 0, 0, $WIDTH, $HEIGHT; |
103 | my $dialog = new CFClient::UI::FancyFrame |
|
|
104 | title => "Client Setup", |
|
|
105 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
106 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
209 | |
107 | |
210 | glMatrixMode GL_PROJECTION; |
108 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
211 | glLoadIdentity; |
109 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
212 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
|
|
213 | glMatrixMode GL_MODELVIEW; |
|
|
214 | glLoadIdentity; |
|
|
215 | |
110 | |
216 | glClear GL_COLOR_BUFFER_BIT; |
111 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
112 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
217 | |
113 | |
218 | $CFClient::UI::TOPLEVEL->draw; |
114 | $mode_slider->connect (changed => sub { |
|
|
115 | my ($self, $value) = @_; |
219 | |
116 | |
220 | SDL::GLSwapBuffers; |
117 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
221 | } |
118 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
119 | }); |
|
|
120 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
222 | |
121 | |
223 | sub debug { |
122 | my $row = 1; |
224 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
225 | my ($w, $h) = $DEBUG_STATUS->size_request; |
|
|
226 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
227 | } |
|
|
228 | |
123 | |
229 | my $FPS; |
124 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
|
|
125 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
|
|
126 | my ($self, $value) = @_; |
|
|
127 | $CFG->{fullscreen} = $value; |
|
|
128 | }); |
230 | |
129 | |
231 | sub refresh { |
130 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
232 | $refresh_handler ||= add Glib::Idle sub { |
131 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
233 | if ($SDL_APP) { |
132 | my ($self, $value) = @_; |
234 | $NOW = SDL::GetTicks; |
133 | $CFG->{fast} = $value; |
|
|
134 | }); |
235 | |
135 | |
236 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
136 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
237 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
137 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
238 | $NOW = SDL::GetTicks; |
138 | my ($self, $value) = @_; |
|
|
139 | $CFG->{fow_enable} = $value; |
|
|
140 | }); |
|
|
141 | |
|
|
142 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
|
|
143 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
|
|
144 | my ($self, $value) = @_; |
|
|
145 | $CFG->{fow_intensity} = $value; |
|
|
146 | }); |
|
|
147 | |
|
|
148 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
|
|
149 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
|
|
150 | my ($self, $value) = @_; |
|
|
151 | $CFG->{fow_smooth} = $value; |
|
|
152 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
|
|
153 | }); |
|
|
154 | |
|
|
155 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
|
|
156 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
157 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
158 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
159 | }); |
|
|
160 | |
|
|
161 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
|
|
162 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
163 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
|
|
164 | }); |
|
|
165 | |
|
|
166 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize"); |
|
|
167 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{stat_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
168 | $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10; |
|
|
169 | &set_stats_window_fontsize; |
|
|
170 | }); |
|
|
171 | |
|
|
172 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge height"); |
|
|
173 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], connect_changed => sub { |
|
|
174 | $CFG->{gauge_size} = $_[1]; |
|
|
175 | my $h = int ($HEIGHT * $CFG->{gauge_size}); |
|
|
176 | $GAUGES->{win}->set_size ($WIDTH, $h); |
|
|
177 | $GAUGES->{win}->{y} = $HEIGHT - $h; |
|
|
178 | $GAUGES->{win}->{x} = 0; |
|
|
179 | $GAUGES->{win}->update; |
|
|
180 | }); |
|
|
181 | |
|
|
182 | |
|
|
183 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
|
|
184 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gauge_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
185 | $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10; |
|
|
186 | &set_gauge_window_fontsize; |
|
|
187 | $GAUGES->{win}->check_size; |
|
|
188 | $GAUGES->{win}->update; |
|
|
189 | }); |
|
|
190 | |
|
|
191 | |
|
|
192 | |
|
|
193 | $table->add (1, $row++, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
194 | video_shutdown (); |
|
|
195 | video_init (); |
|
|
196 | }); |
|
|
197 | |
|
|
198 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
|
|
199 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
|
|
200 | $CFG->{audio_enable} = $_[1]; |
|
|
201 | }); |
|
|
202 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
203 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
204 | # $CFG->{effects_volume} = $_[1]; |
|
|
205 | # }); |
|
|
206 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
207 | $table->add (1, $row++, my $hbox = new CFClient::UI::HBox); |
|
|
208 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
|
|
209 | $CFG->{bgm_enable} = $_[1]; |
|
|
210 | }); |
|
|
211 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
|
|
212 | $CFG->{bgm_volume} = $_[1]; |
|
|
213 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
214 | }); |
|
|
215 | |
|
|
216 | $table->add (1, $row++, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
217 | audio_shutdown (); |
|
|
218 | audio_init (); |
|
|
219 | }); |
|
|
220 | |
|
|
221 | $dialog |
|
|
222 | } |
|
|
223 | |
|
|
224 | sub set_stats_window_fontsize { |
|
|
225 | for (values %{$STATWIDS}) { |
|
|
226 | $_->set_fontsize ($::CFG->{stat_fontsize}); |
|
|
227 | } |
|
|
228 | } |
|
|
229 | |
|
|
230 | sub set_gauge_window_fontsize { |
|
|
231 | for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) { |
|
|
232 | $_->set_fontsize ($::CFG->{gauge_fontsize}); |
|
|
233 | } |
|
|
234 | } |
|
|
235 | |
|
|
236 | sub make_gauge_window { |
|
|
237 | my $gh = int ($HEIGHT * $CFG->{gauge_size}); |
|
|
238 | # my $gw = int ($WIDTH * $CFG->{gauge_w_size}); |
|
|
239 | |
|
|
240 | my $win = new CFClient::UI::Frame ( |
|
|
241 | y => $HEIGHT - $gh, x => 0, req_w => $WIDTH, req_h => $gh |
|
|
242 | ); |
|
|
243 | $win->add (my $vb = new CFClient::UI::VBox); |
|
|
244 | |
|
|
245 | $vb->add (my $hbg = new CFClient::UI::HBox expand => 1); |
|
|
246 | |
|
|
247 | |
|
|
248 | $hbg->add (new CFClient::UI::Empty expand => 1); |
|
|
249 | $hbg->add (my $hb = new CFClient::UI::HBox); |
|
|
250 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp'); |
|
|
251 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana'); |
|
|
252 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace'); |
|
|
253 | $hb->add (my $fg = new CFClient::UI::Gauge type => 'food'); |
|
|
254 | |
|
|
255 | $vb->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, text => "XP:"); |
|
|
256 | # $vb->add (my $lvl = new CFClient::UI::Label valign => 0, align => 1, text => "Lvl:"); |
|
|
257 | $vb->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, text => "Rng:"); |
|
|
258 | |
|
|
259 | |
|
|
260 | $GAUGES = { |
|
|
261 | exp => $exp,# lvl => $lvl, |
|
|
262 | win => $win, range => $rng, |
|
|
263 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
|
|
264 | }; |
|
|
265 | $win |
|
|
266 | } |
|
|
267 | |
|
|
268 | sub make_stats_window { |
|
|
269 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
|
|
270 | |
|
|
271 | $tgw->add (my $vb = new CFClient::UI::VBox); |
|
|
272 | $vb->add (my $uhb = new CFClient::UI::HBox); |
|
|
273 | $uhb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); |
|
|
274 | $uhb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); |
|
|
275 | |
|
|
276 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
|
|
277 | |
|
|
278 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
|
|
279 | |
|
|
280 | $tbl->add (0, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Str"); |
|
|
281 | $tbl->add (0, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Dex"); |
|
|
282 | $tbl->add (0, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Con"); |
|
|
283 | $tbl->add (0, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Int"); |
|
|
284 | $tbl->add (0, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Wis"); |
|
|
285 | $tbl->add (0, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Pow"); |
|
|
286 | $tbl->add (0, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Cha"); |
|
|
287 | |
|
|
288 | $tbl->add (1, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
289 | $tbl->add (1, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
290 | $tbl->add (1, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
291 | $tbl->add (1, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
292 | $tbl->add (1, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
293 | $tbl->add (1, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
294 | $tbl->add (1, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
295 | |
|
|
296 | $tbl->add (2, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Wc"); |
|
|
297 | $tbl->add (2, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Ac"); |
|
|
298 | $tbl->add (2, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Dam"); |
|
|
299 | $tbl->add (2, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Arm"); |
|
|
300 | $tbl->add (2, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Sp"); |
|
|
301 | $tbl->add (2, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "WSp"); |
|
|
302 | |
|
|
303 | $tbl->add (3, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
304 | $tbl->add (3, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
305 | $tbl->add (3, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
306 | $tbl->add (3, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
307 | $tbl->add (3, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
308 | $tbl->add (3, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
309 | |
|
|
310 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
|
|
311 | |
|
|
312 | my $row = 0; |
|
|
313 | my $col = 0; |
|
|
314 | |
|
|
315 | for (qw/slow holyw conf fire depl magic |
|
|
316 | drain acid pois para deat phys |
|
|
317 | blind fear tund elec cold ghit/) |
|
|
318 | { |
|
|
319 | $tbl2->add ($col , $row, |
|
|
320 | $STATWIDS->{"res_$_"} = |
|
|
321 | new CFClient::UI::Label text => "0", align => +1, valign => 0 |
|
|
322 | ); |
|
|
323 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image image => "ui/resist/resist_$_.png"); |
|
|
324 | |
|
|
325 | $row++; |
|
|
326 | if ($row % 6 == 0) { |
|
|
327 | $col += 2; |
|
|
328 | $row = 0; |
|
|
329 | } |
|
|
330 | } |
|
|
331 | |
|
|
332 | &set_stats_window_fontsize; |
|
|
333 | update_stats_window ({}); |
|
|
334 | |
|
|
335 | $tgw |
|
|
336 | } |
|
|
337 | |
|
|
338 | sub update_stats_window { |
|
|
339 | my ($stats) = @_; |
|
|
340 | |
|
|
341 | # i love text protocols!!! |
|
|
342 | my $hp = $stats->{1} * 1; |
|
|
343 | my $hp_m = $stats->{2} * 1; |
|
|
344 | my $sp = $stats->{3} * 1; |
|
|
345 | my $sp_m = $stats->{4} * 1; |
|
|
346 | my $fo = $stats->{18} * 1; |
|
|
347 | my $fo_m = 999; |
|
|
348 | my $gr = $stats->{23} * 1; |
|
|
349 | my $gr_m = $stats->{24} * 1; |
|
|
350 | |
|
|
351 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
352 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
353 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
354 | $GAUGES->{grace} ->set_value ($gr, $gr_m); |
|
|
355 | $GAUGES->{exp} ->set_text ("XP: " . ($stats->{11} || $stats->{28}) * 1 |
|
|
356 | ." LVL: " . $stats->{12} * 1); |
|
|
357 | my $rng = $stats->{20}; |
|
|
358 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
359 | $GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
360 | # $GAUGES->{lvl} ->set_text ("LVL: " . $stats->{12}); |
|
|
361 | $STATWIDS->{title} ->set_text ("Title: " . $stats->{21}); |
|
|
362 | |
|
|
363 | if (0) { # this code can vanish, just wanted to preserver it for a checkin |
|
|
364 | $STATWIDS->{st_str} ->set_text (sprintf "S%d", $stats->{5}); |
|
|
365 | $STATWIDS->{st_dex} ->set_text (sprintf "D%d", $stats->{8}); |
|
|
366 | $STATWIDS->{st_con} ->set_text (sprintf "Co%d", $stats->{9}); |
|
|
367 | $STATWIDS->{st_int} ->set_text (sprintf "I%d", $stats->{6}); |
|
|
368 | $STATWIDS->{st_wis} ->set_text (sprintf "W%d", $stats->{7}); |
|
|
369 | $STATWIDS->{st_pow} ->set_text (sprintf "P%d", $stats->{22}); |
|
|
370 | $STATWIDS->{st_cha} ->set_text (sprintf "Ch%d", $stats->{10}); |
|
|
371 | $STATWIDS->{st_wc} ->set_text (sprintf "Wc%d", $stats->{13}); |
|
|
372 | $STATWIDS->{st_ac} ->set_text (sprintf "Ac%d", $stats->{14}); |
|
|
373 | $STATWIDS->{st_dam} ->set_text (sprintf "Dam%d", $stats->{15}); |
|
|
374 | $STATWIDS->{st_arm} ->set_text (sprintf "Arm%d", $stats->{16}); |
|
|
375 | $STATWIDS->{st_spd} ->set_text (sprintf "Sp%.1f", $stats->{17}); |
|
|
376 | $STATWIDS->{st_wspd}->set_text (sprintf "WSp%.1f", $stats->{19}); |
|
|
377 | } else { |
|
|
378 | $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5}); |
|
|
379 | $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8}); |
|
|
380 | $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9}); |
|
|
381 | $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6}); |
|
|
382 | $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7}); |
|
|
383 | $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22}); |
|
|
384 | $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10}); |
|
|
385 | $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13}); |
|
|
386 | $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14}); |
|
|
387 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
|
|
388 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
|
|
389 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17}); |
|
|
390 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19}); |
|
|
391 | } |
|
|
392 | |
|
|
393 | my %tbl = ( |
|
|
394 | phys => 100, |
|
|
395 | magic => 101, |
|
|
396 | fire => 102, |
|
|
397 | elec => 103, |
|
|
398 | cold => 104, |
|
|
399 | conf => 105, |
|
|
400 | acid => 106, |
|
|
401 | drain => 107, |
|
|
402 | ghit => 108, |
|
|
403 | pois => 109, |
|
|
404 | slow => 110, |
|
|
405 | para => 111, |
|
|
406 | tund => 112, |
|
|
407 | fear => 113, |
|
|
408 | deat => 115, |
|
|
409 | holyw => 116, |
|
|
410 | blind => 117 |
|
|
411 | ); |
|
|
412 | |
|
|
413 | for (keys %tbl) { |
|
|
414 | $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}}); |
|
|
415 | } |
|
|
416 | |
|
|
417 | } |
|
|
418 | |
|
|
419 | sub metaserver_dialog { |
|
|
420 | my $dialog = new CFClient::UI::FancyFrame |
|
|
421 | title => "Metaserver", |
|
|
422 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
423 | |
|
|
424 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
|
|
425 | |
|
|
426 | $dialog |
|
|
427 | } |
|
|
428 | |
|
|
429 | sub update_metaserver { |
|
|
430 | my ($HOST) = @_; |
|
|
431 | |
|
|
432 | status "fetching metaserver list..."; |
|
|
433 | |
|
|
434 | my $buf; |
|
|
435 | |
|
|
436 | my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; |
|
|
437 | |
|
|
438 | Event->io (fd => $fh, poll => 'r', cb => sub { |
|
|
439 | my $res = sysread $fh, $buf, 8192, length $buf; |
|
|
440 | |
|
|
441 | if (!defined $res) { |
|
|
442 | $_[0]->w->cancel; |
|
|
443 | status "metaserver: $!"; |
|
|
444 | } elsif ($res == 0) { |
|
|
445 | $_[0]->w->cancel; |
|
|
446 | status "server list retrieved"; |
|
|
447 | |
|
|
448 | my $table = $METASERVER->{table}; |
|
|
449 | |
|
|
450 | $table->clear; |
|
|
451 | |
|
|
452 | my @col = qw(Use #Users Host Uptime Version Description); |
|
|
453 | $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) |
|
|
454 | for 0 .. $#col; |
|
|
455 | |
|
|
456 | my @align = qw(1 0 1 1 -1); |
|
|
457 | |
|
|
458 | my $y = 0; |
|
|
459 | for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { |
|
|
460 | my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; |
|
|
461 | |
|
|
462 | for ($desc) { |
|
|
463 | s/<br>/\n/gi; |
|
|
464 | s/<li>/\n· /gi; |
|
|
465 | s/<.*?>//sgi; |
|
|
466 | s/&/&/g; |
|
|
467 | s/</</g; |
|
|
468 | s/>/>/g; |
|
|
469 | } |
|
|
470 | |
|
|
471 | $uptime = sprintf "%dd %02d:%02d:%02d", |
|
|
472 | (int $m->[8] / 86400), |
|
|
473 | (int $m->[8] / 3600) % 24, |
|
|
474 | (int $m->[8] / 60) % 60, |
|
|
475 | $m->[8] % 60; |
|
|
476 | |
|
|
477 | $m = [$users, $host, $uptime, $version, $desc]; |
|
|
478 | |
|
|
479 | $y++; |
|
|
480 | |
|
|
481 | $table->add (0, $y, new CFClient::UI::VBox children => [ |
|
|
482 | (new CFClient::UI::Button text => " ", connect_activate => sub { |
|
|
483 | $HOST->set_text ($CFG->{host} = $host); |
|
|
484 | }), |
|
|
485 | (new CFClient::UI::Empty expand => 1), |
|
|
486 | ]); |
|
|
487 | |
|
|
488 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
|
|
489 | for 0 .. $#$m; |
239 | } |
490 | } |
240 | |
491 | } |
241 | my $interval = ($NOW - $last_refresh) * 0.001; |
492 | }); |
242 | $last_refresh = $NOW; |
493 | } |
243 | |
494 | |
244 | if ($interval) { |
495 | sub server_setup { |
245 | $FPS ||= 1 / $interval; |
496 | my $dialog = new CFClient::UI::FancyFrame |
246 | $FPS = $FPS * 0.9 + (1 / $interval) * 0.1; |
497 | title => "Server Setup", |
247 | debug sprintf "%5.02f", $FPS; |
498 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
499 | |
|
|
500 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
501 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
|
|
502 | |
|
|
503 | { |
|
|
504 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
|
|
505 | |
|
|
506 | $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub { |
|
|
507 | my ($self, $value) = @_; |
|
|
508 | $CFG->{host} = $value; |
|
|
509 | }); |
|
|
510 | |
|
|
511 | $METASERVER = metaserver_dialog; |
|
|
512 | |
|
|
513 | $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub { |
|
|
514 | update_metaserver $HOST; |
|
|
515 | }); |
|
|
516 | } |
|
|
517 | |
|
|
518 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
|
|
519 | $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
|
|
520 | my ($self, $value) = @_; |
|
|
521 | $CFG->{user} = $value; |
|
|
522 | }); |
|
|
523 | |
|
|
524 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
|
|
525 | $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
|
|
526 | my ($self, $value) = @_; |
|
|
527 | $CFG->{password} = $value; |
|
|
528 | }); |
|
|
529 | |
|
|
530 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
|
|
531 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
|
|
532 | my ($self, $value) = @_; |
|
|
533 | $CFG->{say_command} = $value; |
|
|
534 | }); |
|
|
535 | |
|
|
536 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
|
|
537 | $table->add (1, 7, new CFClient::UI::Slider |
|
|
538 | req_w => 100, |
|
|
539 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
540 | connect_changed => sub { |
|
|
541 | my ($self, $value) = @_; |
|
|
542 | |
|
|
543 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
|
|
544 | }, |
|
|
545 | ); |
|
|
546 | |
|
|
547 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
|
|
548 | start_game; |
|
|
549 | }); |
|
|
550 | |
|
|
551 | $dialog |
|
|
552 | } |
|
|
553 | |
|
|
554 | sub message_window { |
|
|
555 | my $window = new CFClient::UI::FancyFrame |
|
|
556 | title => "Messages", |
|
|
557 | border_bg => [1, 1, 1, 0.5], |
|
|
558 | bg => [0.3, 0.3, 0.3, 0.8], |
|
|
559 | user_w => int $::WIDTH / 3, |
|
|
560 | user_h => int $::HEIGHT / 5, |
|
|
561 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
562 | |
|
|
563 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
|
|
564 | expand => 1, |
|
|
565 | fontsize => $::CFG->{log_fontsize}, |
|
|
566 | ); |
|
|
567 | |
|
|
568 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
569 | connect_focus_in => sub { |
|
|
570 | my ($input, $prev_focus) = @_; |
|
|
571 | |
|
|
572 | delete $input->{refocus_map}; |
|
|
573 | |
|
|
574 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
575 | $input->{refocus_map} = 1; |
248 | } |
576 | } |
|
|
577 | delete $input->{auto_activated}; |
|
|
578 | }, |
|
|
579 | connect_activate => sub { |
|
|
580 | my ($input, $text) = @_; |
|
|
581 | $input->set_text (''); |
249 | |
582 | |
250 | force_refresh; |
583 | if ($text =~ /^\/(.*)/) { |
251 | $_->animate ($interval) for grep $_, values %ANIMATE; |
584 | $::CONN->user_send ($1); |
252 | |
|
|
253 | if (%ANIMATE) { |
|
|
254 | 1 |
|
|
255 | } else { |
585 | } else { |
256 | undef $refresh_handler; |
586 | my $say_cmd = $::CFG->{say_command} || 'say'; |
|
|
587 | $::CONN->user_send ("$say_cmd $text"); |
|
|
588 | } |
|
|
589 | if ($input->{refocus_map}) { |
|
|
590 | delete $input->{refocus_map}; |
|
|
591 | $MAPWIDGET->focus_in |
|
|
592 | } |
|
|
593 | }, |
|
|
594 | connect_escape => sub { |
|
|
595 | $MAPWIDGET->focus_in |
|
|
596 | }, |
|
|
597 | ); |
|
|
598 | |
|
|
599 | $CONSOLE = { |
|
|
600 | window => $window, |
|
|
601 | input => $input |
|
|
602 | }; |
|
|
603 | |
|
|
604 | $window |
|
|
605 | } |
|
|
606 | |
|
|
607 | sub sdl_init { |
|
|
608 | CFClient::SDL_Init |
|
|
609 | and die "SDL::Init failed!\n"; |
|
|
610 | } |
|
|
611 | |
|
|
612 | sub video_init { |
|
|
613 | sdl_init; |
|
|
614 | |
|
|
615 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
616 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
617 | $FAST = $CFG->{fast}; |
|
|
618 | |
|
|
619 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
|
|
620 | or die "SDL_SetVideoMode failed!\n"; |
|
|
621 | |
|
|
622 | $SDL_ACTIVE = 1; |
|
|
623 | |
|
|
624 | $LAST_REFRESH = time - 0.01; |
|
|
625 | |
|
|
626 | CFClient::gl_init; |
|
|
627 | |
|
|
628 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
629 | |
|
|
630 | ############################################################################# |
|
|
631 | |
|
|
632 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
|
|
633 | $DEBUG_STATUS->show; |
|
|
634 | |
|
|
635 | $STATUS_LINE = new CFClient::UI::Label |
|
|
636 | padding => 0, |
|
|
637 | y => $HEIGHT - $FONTSIZE * 1.8; |
|
|
638 | $STATUS_LINE->show; |
|
|
639 | |
|
|
640 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
641 | padding => 0, |
|
|
642 | fontsize => 0.8, |
|
|
643 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
644 | $ALT_ENTER_MESSAGE->show; |
|
|
645 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
|
|
646 | |
|
|
647 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
|
|
648 | $MAPWIDGET->focus_in; |
|
|
649 | $MAPWIDGET->connect (activate_console => sub { |
|
|
650 | my ($mapwidget, $preset) = @_; |
|
|
651 | |
|
|
652 | if ($CONSOLE) { |
|
|
653 | $CONSOLE->{input}->{auto_activated} = 1; |
|
|
654 | $CONSOLE->{input}->focus_in; |
|
|
655 | |
|
|
656 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
|
|
657 | $CONSOLE->{input}->set_text ($preset); |
|
|
658 | } |
|
|
659 | } |
|
|
660 | }); |
|
|
661 | |
|
|
662 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
|
|
663 | |
|
|
664 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
|
|
665 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
|
|
666 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
|
|
667 | |
|
|
668 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
|
|
669 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
670 | status "Configuration Saved"; |
|
|
671 | }); |
|
|
672 | |
|
|
673 | $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D |
|
|
674 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
|
|
675 | |
|
|
676 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
677 | |
|
|
678 | |
|
|
679 | } |
|
|
680 | |
|
|
681 | sub video_shutdown { |
|
|
682 | $CFClient::UI::ROOT->{children} = []; |
|
|
683 | undef $SDL_ACTIVE; |
|
|
684 | } |
|
|
685 | |
|
|
686 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
|
|
687 | my $bgmusic;#TODO#hack#d# |
|
|
688 | |
|
|
689 | sub audio_music_finished { |
|
|
690 | return unless $CFG->{bgm_enable}; |
|
|
691 | |
|
|
692 | # TODO: hack, do play loop and mood music |
|
|
693 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
694 | $bgmusic->play (0); |
|
|
695 | |
|
|
696 | push @bgmusic, shift @bgmusic; |
|
|
697 | } |
|
|
698 | |
|
|
699 | sub audio_init { |
|
|
700 | if ($CFG->{audio_enable}) { |
|
|
701 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
702 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
|
|
703 | CFClient::Mix_AllocateChannels 8; |
|
|
704 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
|
|
705 | |
|
|
706 | audio_music_finished; |
|
|
707 | |
|
|
708 | while (<$fh>) { |
|
|
709 | next if /^\s*#/; |
|
|
710 | next if /^\s*$/; |
|
|
711 | |
|
|
712 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
713 | |
|
|
714 | push @SOUNDS, "$volume,$file"; |
|
|
715 | |
|
|
716 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
717 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
|
|
718 | $chunk->volume ($volume * 128 / 100); |
|
|
719 | $chunk |
257 | 0 |
720 | }; |
258 | } |
721 | } |
259 | } else { |
722 | } else { |
260 | undef $refresh_handler; |
723 | status "unable to open sound config: $!"; |
261 | 0 |
|
|
262 | } |
724 | } |
263 | }; |
725 | } |
|
|
726 | } |
|
|
727 | |
|
|
728 | sub audio_shutdown { |
|
|
729 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
|
|
730 | undef $SDL_MIXER; |
|
|
731 | @SOUNDS = (); |
|
|
732 | %AUDIO_CHUNKS = (); |
|
|
733 | } |
|
|
734 | |
|
|
735 | my %animate_object; |
|
|
736 | my $animate_timer; |
|
|
737 | |
|
|
738 | my $want_refresh; |
|
|
739 | my $can_refresh; |
|
|
740 | |
|
|
741 | my $fps = 9; |
|
|
742 | |
|
|
743 | sub force_refresh { |
|
|
744 | $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; |
|
|
745 | debug sprintf "%3.2f", $fps; |
|
|
746 | |
|
|
747 | $want_refresh = 0; |
|
|
748 | $can_refresh = 0; |
|
|
749 | |
|
|
750 | $CFClient::UI::ROOT->draw; |
|
|
751 | |
|
|
752 | CFClient::SDL_GL_SwapBuffers; |
|
|
753 | |
|
|
754 | $LAST_REFRESH = $NOW; |
|
|
755 | } |
|
|
756 | |
|
|
757 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
|
|
758 | $NOW = time; |
|
|
759 | |
|
|
760 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
|
|
761 | for CFClient::SDL_PollEvent; |
|
|
762 | |
|
|
763 | if (%animate_object) { |
|
|
764 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
|
|
765 | $want_refresh++; |
|
|
766 | } |
|
|
767 | |
|
|
768 | if ($want_refresh) { |
|
|
769 | force_refresh; |
|
|
770 | } else { |
|
|
771 | $can_refresh = 1; |
|
|
772 | } |
|
|
773 | }); |
|
|
774 | |
|
|
775 | sub refresh { |
|
|
776 | $want_refresh++; |
264 | } |
777 | } |
265 | |
778 | |
266 | sub animation_start { |
779 | sub animation_start { |
267 | my ($widget) = @_; |
780 | my ($widget) = @_; |
268 | $ANIMATE{$widget} = $widget; |
781 | $animate_object{$widget} = $widget; |
269 | Scalar::Util::weaken $ANIMATE{$widget}; |
|
|
270 | |
|
|
271 | refresh; |
|
|
272 | } |
782 | } |
273 | |
783 | |
274 | sub animation_stop { |
784 | sub animation_stop { |
275 | my ($widget) = @_; |
785 | my ($widget) = @_; |
276 | delete $ANIMATE{$widget}; |
786 | delete $animate_object{$widget}; |
|
|
787 | } |
|
|
788 | |
|
|
789 | @conn::ISA = Crossfire::Protocol::; |
|
|
790 | |
|
|
791 | sub conn::stats_update { |
|
|
792 | my ($self, $stats) = @_; |
|
|
793 | |
|
|
794 | update_stats_window ($stats); |
|
|
795 | } |
|
|
796 | |
|
|
797 | sub conn::user_send { |
|
|
798 | my ($self, $command) = @_; |
|
|
799 | |
|
|
800 | $self->send_command ($command); |
|
|
801 | status $command; |
|
|
802 | } |
|
|
803 | |
|
|
804 | sub conn::map_scroll { |
|
|
805 | my ($self, $dx, $dy) = @_; |
|
|
806 | |
|
|
807 | $MAP->scroll ($dx, $dy); |
|
|
808 | } |
|
|
809 | |
|
|
810 | sub conn::feed_map1a { |
|
|
811 | my ($self, $data) = @_; |
|
|
812 | |
|
|
813 | # $self->Crossfire::Protocol::feed_map1a ($data); |
|
|
814 | |
|
|
815 | $MAP->map1a_update ($data); |
|
|
816 | $MAPWIDGET->update; |
|
|
817 | } |
|
|
818 | |
|
|
819 | sub conn::flush_map { |
|
|
820 | my ($self) = @_; |
|
|
821 | |
|
|
822 | my $map_info = delete $self->{map_info} |
|
|
823 | or return; |
|
|
824 | |
|
|
825 | my ($hash, $x, $y, $w, $h) = @$map_info; |
|
|
826 | |
|
|
827 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
|
|
828 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
|
|
829 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
830 | } |
|
|
831 | |
|
|
832 | sub conn::map_clear { |
|
|
833 | my ($self) = @_; |
|
|
834 | |
|
|
835 | $self->flush_map; |
|
|
836 | delete $self->{neigh_map}; |
|
|
837 | |
|
|
838 | $MAP->clear; |
|
|
839 | } |
|
|
840 | |
|
|
841 | |
|
|
842 | sub conn::load_map($$$) { |
|
|
843 | my ($self, $hash, $x, $y) = @_; |
|
|
844 | |
|
|
845 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
|
|
846 | $data = Compress::LZF::decompress $data; |
|
|
847 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
848 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
|
|
849 | my $data = $TILECACHE->get ($id) |
|
|
850 | or next; |
|
|
851 | |
|
|
852 | $self->set_texture ($id => $data); |
|
|
853 | } |
|
|
854 | } |
|
|
855 | } |
|
|
856 | |
|
|
857 | # this method does a "flood fill" into every tile direction |
|
|
858 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
859 | # i.e. a map is the same as the left of the right map etc. |
|
|
860 | # failure to comply are harmless and result in display errors |
|
|
861 | # at worst. |
|
|
862 | sub conn::flood_fill { |
|
|
863 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
|
|
864 | |
|
|
865 | # the server does not allow map paths > 6 |
|
|
866 | return if 6 <= length $path; |
|
|
867 | |
|
|
868 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
|
|
869 | |
|
|
870 | for ( |
|
|
871 | [1, 0, -1], |
|
|
872 | [2, 1, 0], |
|
|
873 | [3, 0, 1], |
|
|
874 | [4, -1, 0], |
|
|
875 | ) { |
|
|
876 | my ($tile, $dx, $dy) = @$_; |
|
|
877 | |
|
|
878 | my $gx = $gx + $dx; |
|
|
879 | my $gy = $gy + $dy; |
|
|
880 | |
|
|
881 | next unless $flags & (1 << ($tile - 1)); |
|
|
882 | next if $self->{neigh_grid}{$gx, $gy}++; |
|
|
883 | |
|
|
884 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
|
|
885 | if (my $info = $neigh->[$tile]) { |
|
|
886 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
|
|
887 | |
|
|
888 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
889 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
890 | |
|
|
891 | } else { |
|
|
892 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
893 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
894 | |
|
|
895 | return if $mode ne "spatial"; |
|
|
896 | |
|
|
897 | $x += $MAP->ox; |
|
|
898 | $y += $MAP->oy; |
|
|
899 | |
|
|
900 | $self->load_map ($hash, $x, $y) |
|
|
901 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
902 | |
|
|
903 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
904 | |
|
|
905 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
906 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
907 | }); |
|
|
908 | } |
|
|
909 | } |
|
|
910 | } |
|
|
911 | |
|
|
912 | sub conn::map_change { |
|
|
913 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
914 | |
|
|
915 | $self->flush_map; |
|
|
916 | |
|
|
917 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
918 | |
|
|
919 | my $mapmapw = 250; |
|
|
920 | my $mapmaph = 250; |
|
|
921 | |
|
|
922 | $self->{neigh_rect} = [ |
|
|
923 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
924 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
925 | ]; |
|
|
926 | |
|
|
927 | delete $self->{neigh_grid}; |
|
|
928 | $self->flood_fill (0, 0, "", $hash, $flags); |
|
|
929 | |
|
|
930 | $x += $ox; |
|
|
931 | $y += $oy; |
|
|
932 | |
|
|
933 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
934 | |
|
|
935 | my $map = $self->{map_info}[0]; |
|
|
936 | $map =~ s/^.*?\/([^\/]+)$/\1/; |
|
|
937 | $STATWIDS->{map}->set_text ("Map: " . $map); |
|
|
938 | |
|
|
939 | $self->load_map ($hash, $x, $y); |
|
|
940 | } |
|
|
941 | |
|
|
942 | sub conn::face_find { |
|
|
943 | my ($self, $facenum, $face) = @_; |
|
|
944 | |
|
|
945 | my $hash = "$face->{chksum},$face->{name}"; |
|
|
946 | |
|
|
947 | my $id = $FACEMAP->get ($hash); |
|
|
948 | |
|
|
949 | unless ($id) { |
|
|
950 | # create new id for face |
|
|
951 | # i love transactions |
|
|
952 | for (1..100) { |
|
|
953 | my $txn = $CFClient::DB_ENV->txn_begin; |
|
|
954 | my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW); |
|
|
955 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
|
|
956 | $id++; |
|
|
957 | if ($FACEMAP->put (id => $id) == 0 |
|
|
958 | && $FACEMAP->put ($hash => $id) == 0) { |
|
|
959 | $txn->txn_commit; |
|
|
960 | |
|
|
961 | goto gotid; |
|
|
962 | } |
|
|
963 | } |
|
|
964 | $txn->abort; |
|
|
965 | } |
|
|
966 | |
|
|
967 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
|
|
968 | } |
|
|
969 | |
|
|
970 | gotid: |
|
|
971 | $face->{id} = $id; |
|
|
972 | $MAP->set_face ($facenum => $id); |
|
|
973 | $TILECACHE->get ($id) |
|
|
974 | } |
|
|
975 | |
|
|
976 | sub conn::face_update { |
|
|
977 | my ($self, $facenum, $face) = @_; |
|
|
978 | |
|
|
979 | $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
|
|
980 | |
|
|
981 | $self->set_texture ($face->{id} => delete $face->{image}); |
|
|
982 | } |
|
|
983 | |
|
|
984 | sub conn::set_texture { |
|
|
985 | my ($self, $id, $data) = @_; |
|
|
986 | |
|
|
987 | $self->{texture}[$id] ||= do { |
|
|
988 | my $tex = |
|
|
989 | new_from_image CFClient::Texture |
|
|
990 | $data, minify => 1; |
|
|
991 | |
|
|
992 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
993 | $MAPWIDGET->update; |
|
|
994 | |
|
|
995 | $tex |
|
|
996 | }; |
|
|
997 | } |
|
|
998 | |
|
|
999 | sub conn::sound_play { |
|
|
1000 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
1001 | |
|
|
1002 | $SDL_MIXER |
|
|
1003 | or return; |
|
|
1004 | |
|
|
1005 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
1006 | or return; |
|
|
1007 | |
|
|
1008 | $chunk->play; |
|
|
1009 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
|
|
1010 | } |
|
|
1011 | |
|
|
1012 | sub conn::query { |
|
|
1013 | my ($self, $flags, $prompt) = @_; |
|
|
1014 | |
|
|
1015 | #TODO, display dialog with relevant information |
|
|
1016 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
|
|
1017 | } |
|
|
1018 | |
|
|
1019 | sub conn::drawinfo { |
|
|
1020 | my ($self, $color, $text) = @_; |
|
|
1021 | |
|
|
1022 | my @color = ( |
|
|
1023 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
|
|
1024 | [1.00, 1.00, 1.00], |
|
|
1025 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
|
|
1026 | [1.00, 0.00, 0.00], |
|
|
1027 | [1.00, 0.54, 0.00], |
|
|
1028 | [0.11, 0.56, 1.00], |
|
|
1029 | [0.93, 0.46, 0.00], |
|
|
1030 | [0.18, 0.54, 0.34], |
|
|
1031 | [0.56, 0.73, 0.56], |
|
|
1032 | [0.80, 0.80, 0.80], |
|
|
1033 | [0.55, 0.41, 0.13], |
|
|
1034 | [0.99, 0.77, 0.26], |
|
|
1035 | [0.74, 0.65, 0.41], |
|
|
1036 | ); |
|
|
1037 | |
|
|
1038 | $LOGVIEW->add_paragraph ($color[$color], $text); |
|
|
1039 | } |
|
|
1040 | |
|
|
1041 | sub conn::spell_add { |
|
|
1042 | my ($self, $spell) = @_; |
|
|
1043 | |
|
|
1044 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub { |
|
|
1045 | }); |
|
|
1046 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub { |
|
|
1047 | }); |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | sub conn::spell_delete { |
|
|
1051 | my ($self, $spell) = @_; |
|
|
1052 | } |
|
|
1053 | |
|
|
1054 | sub conn::addme_success { |
|
|
1055 | my ($self) = @_; |
|
|
1056 | |
|
|
1057 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1058 | $MAPWIDGET->add_command ("ready_skill $skill", "", sub { |
|
|
1059 | }); |
|
|
1060 | $MAPWIDGET->add_command ("use_skill $skill", "", sub { |
|
|
1061 | }); |
|
|
1062 | } |
277 | } |
1063 | } |
278 | |
1064 | |
279 | %SDL_CB = ( |
1065 | %SDL_CB = ( |
280 | SDL_QUIT() => sub { |
1066 | CFClient::SDL_QUIT => sub { |
281 | main_quit Gtk2; |
1067 | Event::unloop -1; |
282 | }, |
1068 | }, |
283 | SDL_VIDEORESIZE() => sub { |
1069 | CFClient::SDL_VIDEORESIZE => sub { |
284 | }, |
1070 | }, |
285 | SDL_VIDEOEXPOSE() => sub { |
1071 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
286 | refresh; |
1072 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
1073 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
287 | }, |
1074 | }, |
288 | SDL_KEYDOWN() => sub { |
1075 | CFClient::SDL_KEYDOWN => sub { |
289 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
1076 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
290 | # alt-enter |
1077 | # alt-enter |
291 | $FULLSCREEN = !$FULLSCREEN; |
1078 | video_shutdown; |
292 | init_screen; |
1079 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
|
|
1080 | video_init; |
293 | } else { |
1081 | } else { |
294 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
1082 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
295 | } |
1083 | } |
296 | }, |
1084 | }, |
297 | SDL_KEYUP() => sub { |
1085 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
298 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
1086 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
299 | }, |
1087 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
300 | SDL_MOUSEMOTION() => sub { |
1088 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
301 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
1089 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
302 | }, |
|
|
303 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
304 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
305 | }, |
|
|
306 | SDL_MOUSEBUTTONUP() => sub { |
|
|
307 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
308 | }, |
|
|
309 | SDL_ACTIVEEVENT() => sub { |
|
|
310 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
311 | }, |
|
|
312 | ); |
1090 | ); |
313 | |
1091 | |
314 | @conn::ISA = Crossfire::Protocol::; |
|
|
315 | |
|
|
316 | sub conn::map_update { |
|
|
317 | my ($self, $dirty) = @_; |
|
|
318 | |
|
|
319 | $MAPWIDGET->update; |
|
|
320 | } |
|
|
321 | |
|
|
322 | sub conn::map_scroll { |
|
|
323 | my ($self, $dx, $dy) = @_; |
|
|
324 | |
|
|
325 | # refresh; |
|
|
326 | } |
|
|
327 | |
|
|
328 | sub conn::map_clear { |
|
|
329 | my ($self) = @_; |
|
|
330 | |
|
|
331 | # refresh; |
|
|
332 | } |
|
|
333 | |
|
|
334 | sub conn::face_find { |
|
|
335 | my ($self, $face) = @_; |
|
|
336 | |
|
|
337 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
|
|
338 | } |
|
|
339 | |
|
|
340 | sub conn::face_update { |
|
|
341 | my ($self, $face) = @_; |
|
|
342 | |
|
|
343 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
|
|
344 | |
|
|
345 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
|
|
346 | } |
|
|
347 | |
|
|
348 | sub conn::query { |
|
|
349 | my ($self, $flags, $prompt) = @_; |
|
|
350 | |
|
|
351 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
|
|
352 | } |
|
|
353 | |
|
|
354 | sub gtk_add_cfg_field { |
|
|
355 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
|
|
356 | my $i = $cfg->{_i}++; |
|
|
357 | $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); |
|
|
358 | $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1); |
|
|
359 | if ($key eq 'password') { |
|
|
360 | $ent->set_invisible_char ("*"); |
|
|
361 | $ent->set (visibility => 0) |
|
|
362 | } |
|
|
363 | $ent->set_text ($value); |
|
|
364 | $ent->signal_connect (changed => sub { |
|
|
365 | my ($ent) = @_; |
|
|
366 | $cfg->{$key} = $ent->get_text; |
|
|
367 | # TODO: Mapsize should be a slider in the game gui |
|
|
368 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
|
|
369 | $cfg->{$key} = 100; |
|
|
370 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
371 | $cfg->{$key} = 50; |
|
|
372 | } |
|
|
373 | }); |
|
|
374 | } |
|
|
375 | |
|
|
376 | sub run_config_dialog { |
|
|
377 | my (%events) = @_; |
|
|
378 | |
|
|
379 | my $w = Gtk2::Window->new; |
|
|
380 | |
|
|
381 | my @cfg = ( |
|
|
382 | [qw/Host host/], |
|
|
383 | [qw/Port port/], |
|
|
384 | [qw/Mapsize% mapsize/], |
|
|
385 | [qw/Username user/], |
|
|
386 | [qw/Password password/], |
|
|
387 | ); |
|
|
388 | |
|
|
389 | my $cfg = {}; |
|
|
390 | |
|
|
391 | $w->add (my $vb = Gtk2::VBox->new); |
|
|
392 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
|
|
393 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
|
|
394 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
|
|
395 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
|
|
396 | my $i = 0; |
|
|
397 | my $act = 0; |
|
|
398 | for (map { "$_->[0]x$_->[1]" } @SDL_MODES) { |
|
|
399 | if ($_ eq $selmode) { $act = $i } |
|
|
400 | $cb->append_text ($_); |
|
|
401 | $i++; |
|
|
402 | } |
|
|
403 | $cb->set_active ($act); |
|
|
404 | $cb->signal_connect (changed => sub { |
|
|
405 | my ($cb) = @_; |
|
|
406 | my $txt = $cb->get_active_text; |
|
|
407 | if ($txt =~ m/(\d+)x(\d+)/) { |
|
|
408 | $::CFG->{width} = $1; |
|
|
409 | $::CFG->{height} = $2; |
|
|
410 | } |
|
|
411 | }); |
|
|
412 | |
|
|
413 | $cfg->{_i} = 1; |
|
|
414 | for (@cfg) { |
|
|
415 | gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]}); |
|
|
416 | } |
|
|
417 | |
|
|
418 | $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
|
|
419 | $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5); |
|
|
420 | $cb->signal_connect (clicked => sub { |
|
|
421 | for (keys %$cfg) { |
|
|
422 | $::CFG->{$_} = $cfg->{$_} |
|
|
423 | if $_ ne '_i'; |
|
|
424 | } |
|
|
425 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
|
|
426 | }); |
|
|
427 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
|
|
428 | $cb->signal_connect (clicked => sub { |
|
|
429 | for (keys %$cfg) { |
|
|
430 | $::CFG->{$_} = $cfg->{$_} |
|
|
431 | if $_ ne '_i'; |
|
|
432 | } |
|
|
433 | my $cb = $events{login} || sub {}; |
|
|
434 | $cb->($::CFG->{user}, $::CFG->{password}); |
|
|
435 | }); |
|
|
436 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
|
|
437 | $cb->signal_connect (clicked => sub { |
|
|
438 | my $cb = $events{logout} || sub {}; |
|
|
439 | $cb->(); |
|
|
440 | }); |
|
|
441 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
|
|
442 | $cb->signal_connect (clicked => sub { $w->destroy }); |
|
|
443 | |
|
|
444 | $w->show_all; |
|
|
445 | |
|
|
446 | $w->signal_connect (destroy => sub { Gtk2->main_quit }); |
|
|
447 | } |
|
|
448 | |
|
|
449 | |
|
|
450 | ############################################################################# |
1092 | ############################################################################# |
451 | |
1093 | |
452 | SDL::Init SDL_INIT_EVERYTHING; |
1094 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
453 | |
1095 | |
454 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
1096 | $TILECACHE = CFClient::db_table "tilecache"; |
455 | @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; |
1097 | $FACEMAP = CFClient::db_table "facemap"; |
456 | |
1098 | |
457 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
1099 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
458 | |
1100 | |
459 | $CFG ||= { |
1101 | my %DEF_CFG = ( |
|
|
1102 | sdl_mode => 0, |
460 | width => 640, |
1103 | width => 640, |
461 | height => 480, |
1104 | height => 480, |
|
|
1105 | fullscreen => 0, |
|
|
1106 | fast => 0, |
|
|
1107 | fow_enable => 1, |
|
|
1108 | fow_intensity => 0.45, |
|
|
1109 | fow_smooth => 0, |
|
|
1110 | gui_fontsize => 1, |
|
|
1111 | log_fontsize => 1, |
|
|
1112 | gauge_fontsize => 1, |
|
|
1113 | gauge_size => 0.35, |
|
|
1114 | stat_fontsize => 1, |
462 | mapsize => 100, |
1115 | mapsize => 100, |
463 | fullscreen => 0, |
|
|
464 | host => "crossfire.schmorp.de", |
1116 | host => "crossfire.schmorp.de", |
465 | port => 13327, |
1117 | say_command => 'say', |
466 | }; |
1118 | audio_enable => 1, |
|
|
1119 | bgm_enable => 1, |
|
|
1120 | bgm_volume => 0.25, |
|
|
1121 | ); |
|
|
1122 | |
|
|
1123 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
1124 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
1125 | } |
|
|
1126 | |
|
|
1127 | sdl_init; |
|
|
1128 | |
|
|
1129 | @SDL_MODES = reverse |
|
|
1130 | grep $_->[0] >= 640 && $_->[1] >= 480, |
|
|
1131 | CFClient::SDL_ListModes; |
|
|
1132 | |
|
|
1133 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
|
|
1134 | |
|
|
1135 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
467 | |
1136 | |
468 | { |
1137 | { |
469 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
1138 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
470 | |
1139 | |
471 | CFClient::add_font $_ for @fonts; |
1140 | CFClient::add_font $_ for @fonts; |
472 | CFClient::set_font $fonts[0]; |
1141 | CFClient::set_font $fonts[0]; |
473 | } |
1142 | } |
474 | |
1143 | |
475 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
1144 | video_init; |
|
|
1145 | audio_init; |
476 | |
1146 | |
477 | run_config_dialog |
1147 | Event::loop; |
478 | login => sub { start_game }, |
|
|
479 | logout => sub { stop_game }; |
|
|
480 | |
1148 | |
481 | main Gtk2; |
1149 | END { CFClient::SDL_Quit } |
482 | |
1150 | |
483 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
1151 | |