… | |
… | |
81 | our $LOGVIEW; |
81 | our $LOGVIEW; |
82 | our $CONSOLE; |
82 | our $CONSOLE; |
83 | our $METASERVER; |
83 | our $METASERVER; |
84 | our $LOGIN_BUTTON; |
84 | our $LOGIN_BUTTON; |
85 | our $QUIT_DIALOG; |
85 | our $QUIT_DIALOG; |
|
|
86 | our $SERVER_SETUP; |
86 | |
87 | |
87 | our $FLOORBOX; |
88 | our $FLOORBOX; |
88 | our $GAUGES; |
89 | our $GAUGES; |
89 | our $STATWIDS; |
90 | our $STATWIDS; |
90 | |
91 | |
… | |
… | |
97 | |
98 | |
98 | our $ALT_ENTER_MESSAGE; |
99 | our $ALT_ENTER_MESSAGE; |
99 | our $STATUSBOX; |
100 | our $STATUSBOX; |
100 | our $DEBUG_STATUS; |
101 | our $DEBUG_STATUS; |
101 | |
102 | |
|
|
103 | our $INV_WINDOW; |
102 | our $INV; |
104 | our $INV; |
103 | our $INVR; |
105 | our $INVR; |
104 | our $INVR_LBL; |
106 | our $INVR_LBL; |
105 | |
107 | |
106 | sub status { |
108 | sub status { |
… | |
… | |
113 | $DEBUG_STATUS->move ($WIDTH - $w, 0); |
115 | $DEBUG_STATUS->move ($WIDTH - $w, 0); |
114 | } |
116 | } |
115 | |
117 | |
116 | sub start_game { |
118 | sub start_game { |
117 | status "logging in..."; |
119 | status "logging in..."; |
|
|
120 | |
|
|
121 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
122 | $SERVER_SETUP->hide; |
118 | |
123 | |
119 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
124 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
120 | |
125 | |
121 | my ($host, $port) = split /:/, $CFG->{host}; |
126 | my ($host, $port) = split /:/, $CFG->{host}; |
122 | |
127 | |
… | |
… | |
151 | }; |
156 | }; |
152 | |
157 | |
153 | if ($CONN) { |
158 | if ($CONN) { |
154 | CFClient::lowdelay fileno $CONN->{fh}; |
159 | CFClient::lowdelay fileno $CONN->{fh}; |
155 | |
160 | |
156 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
157 | status "login successful"; |
161 | status "login successful"; |
158 | |
|
|
159 | $BUTTONBAR->{children}[1]->emit ("activate") |
|
|
160 | if $BUTTONBAR->{children}[1]->{state}; |
|
|
161 | |
|
|
162 | } else { |
162 | } else { |
163 | status "unable to connect"; |
163 | status "unable to connect"; |
164 | stop_game(); |
164 | stop_game(); |
165 | } |
165 | } |
166 | } |
166 | } |
167 | |
167 | |
168 | sub stop_game { |
168 | sub stop_game { |
|
|
169 | $LOGIN_BUTTON->set_text ("Login"); |
|
|
170 | $SERVER_SETUP->show; |
|
|
171 | $INV_WINDOW->hide; |
|
|
172 | $LOGVIEW->hide; |
|
|
173 | |
169 | return unless $CONN; |
174 | return unless $CONN; |
170 | |
175 | |
171 | status "connection closed"; |
176 | status "connection closed"; |
172 | $LOGIN_BUTTON->set_text ("Login"); |
177 | |
173 | $CONN->destroy; |
178 | $CONN->destroy; |
174 | $CONN = 0; # false, does not autovivify |
179 | $CONN = 0; # false, does not autovivify |
175 | |
|
|
176 | $BUTTONBAR->{children}[1]->emit ("activate") |
|
|
177 | unless $BUTTONBAR->{children}[1]->{state}; |
|
|
178 | } |
180 | } |
179 | |
181 | |
180 | sub client_setup { |
182 | sub client_setup { |
181 | my $dialog = new CFClient::UI::FancyFrame |
183 | my $dialog = new CFClient::UI::FancyFrame |
182 | req_x => 1, |
184 | req_x => 1, |
… | |
… | |
385 | |
387 | |
386 | sub make_gauge_window { |
388 | sub make_gauge_window { |
387 | my $gh = int $HEIGHT * $CFG->{gauge_size}; |
389 | my $gh = int $HEIGHT * $CFG->{gauge_size}; |
388 | |
390 | |
389 | my $win = new CFClient::UI::Frame ( |
391 | my $win = new CFClient::UI::Frame ( |
|
|
392 | req_x => 0, |
390 | req_y => -1, |
393 | req_y => -1, |
391 | user_w => $WIDTH, |
394 | def_w => $WIDTH, |
392 | user_h => $gh, |
395 | def_h => $gh, |
393 | ); |
396 | ); |
394 | |
397 | |
395 | $win->add (my $hbox = new CFClient::UI::HBox |
398 | $win->add (my $hbox = new CFClient::UI::HBox |
396 | children => [ |
399 | children => [ |
397 | (new CFClient::UI::HBox expand => 1), |
400 | (new CFClient::UI::HBox expand => 1), |
… | |
… | |
710 | } |
713 | } |
711 | }); |
714 | }); |
712 | } |
715 | } |
713 | |
716 | |
714 | sub server_setup { |
717 | sub server_setup { |
715 | my $dialog = new CFClient::UI::FancyFrame |
718 | my $dialog = $SERVER_SETUP = new CFClient::UI::FancyFrame |
716 | x => $WIDTH * (1/3), |
719 | x => $WIDTH * (1/3), |
717 | y => $HEIGHT * (1/8), |
720 | y => $HEIGHT * (1/8), |
718 | name => "server_setup", |
721 | name => "server_setup", |
719 | title => "Server Setup", |
722 | title => "Server Setup", |
720 | child => (my $vbox = new CFClient::UI::VBox), |
723 | child => (my $vbox = new CFClient::UI::VBox), |
721 | on_visibility_change => sub { |
724 | on_visibility_change => sub { |
722 | $_[0]->show_centered if $_[1] |
725 | my ($self, $visible) = @_; |
|
|
726 | $self->center if $visible; |
723 | }; |
727 | }, |
|
|
728 | ; |
724 | |
729 | |
725 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
730 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
726 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
731 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
727 | |
732 | |
728 | { |
733 | { |
… | |
… | |
833 | name => "message_window", |
838 | name => "message_window", |
834 | title => "Messages", |
839 | title => "Messages", |
835 | border_bg => [1, 1, 1, 1], |
840 | border_bg => [1, 1, 1, 1], |
836 | bg => [0, 0, 0, 0.75], |
841 | bg => [0, 0, 0, 0.75], |
837 | req_x => -1, |
842 | req_x => -1, |
|
|
843 | req_y => 0, |
838 | user_w => int $::WIDTH / 3, |
844 | def_w => int $::WIDTH / 3, |
839 | user_h => int $::HEIGHT / 5, |
845 | def_h => int $::HEIGHT / 5, |
840 | child => (my $vbox = new CFClient::UI::VBox); |
846 | child => (my $vbox = new CFClient::UI::VBox); |
841 | |
847 | |
842 | $vbox->add ($LOGVIEW); |
848 | $vbox->add ($LOGVIEW); |
843 | |
849 | |
844 | $vbox->add (my $input = new CFClient::UI::Entry |
850 | $vbox->add (my $input = new CFClient::UI::Entry |
… | |
… | |
884 | $window |
890 | $window |
885 | } |
891 | } |
886 | |
892 | |
887 | sub open_quit_dialog { |
893 | sub open_quit_dialog { |
888 | unless ($QUIT_DIALOG) { |
894 | unless ($QUIT_DIALOG) { |
889 | |
|
|
890 | $QUIT_DIALOG = new CFClient::UI::FancyFrame title => "Really Quit?"; |
895 | $QUIT_DIALOG = new CFClient::UI::FancyFrame title => "Really Quit?"; |
891 | |
896 | |
892 | $QUIT_DIALOG->add (my $vb = new CFClient::UI::VBox expand => 1); |
897 | $QUIT_DIALOG->add (my $vb = new CFClient::UI::VBox expand => 1); |
893 | |
898 | |
894 | $vb->add (new CFClient::UI::Label |
899 | $vb->add (new CFClient::UI::Label |
… | |
… | |
905 | $hb->add (new CFClient::UI::Button |
910 | $hb->add (new CFClient::UI::Button |
906 | text => "Quit anyway", |
911 | text => "Quit anyway", |
907 | expand => 1, |
912 | expand => 1, |
908 | on_activate => sub { exit }, |
913 | on_activate => sub { exit }, |
909 | ); |
914 | ); |
|
|
915 | } |
910 | |
916 | |
|
|
917 | $QUIT_DIALOG->show; |
911 | $QUIT_DIALOG->show_centered; |
918 | $QUIT_DIALOG->center; |
912 | } else { |
|
|
913 | $QUIT_DIALOG->show_centered; |
|
|
914 | } |
|
|
915 | } |
919 | } |
916 | |
920 | |
917 | sub make_inventory_window { |
921 | sub make_inventory_window { |
918 | my $invwin = new CFClient::UI::FancyFrame |
922 | my $invwin = $INV_WINDOW = new CFClient::UI::FancyFrame |
919 | user_w => $WIDTH * (7/8), |
923 | def_w => $WIDTH * 7/8, |
920 | user_h => $HEIGHT * (7/8), |
924 | def_h => $HEIGHT * 7/8, |
921 | title => "Inventory", |
925 | title => "Inventory", |
922 | name => "inventory_window", |
926 | name => "inventory_window", |
923 | on_visibility_change => sub { |
927 | on_visibility_change => sub { |
924 | $_[0]->show_centered if $_[1] |
928 | my ($self, $visible) = @_; |
|
|
929 | $self->center if $visible; |
925 | }; |
930 | }, |
|
|
931 | ; |
926 | |
932 | |
927 | $invwin->add (my $hb = new CFClient::UI::HBox expand => 1); |
933 | $invwin->add (my $hb = new CFClient::UI::HBox homogeneous => 1); |
928 | |
934 | |
929 | $hb->add (my $vb1 = new CFClient::UI::VBox expand => 1); |
935 | $hb->add (my $vb1 = new CFClient::UI::VBox); |
930 | $vb1->add (my $lbl = new CFClient::UI::Label align => 0); |
936 | $vb1->add (new CFClient::UI::Label align => 0, text => "Player"); |
931 | $lbl->set_text ("Player"); |
|
|
932 | $vb1->add ($INV = new CFClient::UI::Inventory expand => 1); |
937 | $vb1->add ($INV = new CFClient::UI::Inventory expand => 1); |
933 | |
938 | |
934 | $hb->add (my $vb2 = new CFClient::UI::VBox expand => 1); |
939 | $hb->add (my $vb2 = new CFClient::UI::VBox); |
935 | |
940 | |
936 | $vb2->add (my $hb2 = new CFClient::UI::HBox); |
941 | $vb2->add (my $hb2 = new CFClient::UI::HBox); |
937 | $hb2->add ($INVR_LBL = new CFClient::UI::Label align => 0, expand => 1); |
942 | $hb2->add ($INVR_LBL = new CFClient::UI::Label align => 0, expand => 1, text => "Floor"); |
938 | $hb2->add (new CFClient::UI::Button |
943 | $hb2->add (new CFClient::UI::Button |
939 | text => "Close", |
944 | text => "Close", |
940 | tooltip => "Close the currently open container (if one is open)", |
945 | tooltip => "Close the currently open container (if one is open)", |
941 | on_activate => sub { |
946 | on_activate => sub { |
942 | $CONN->send ("apply $CONN->{open_container}") |
947 | $CONN->send ("apply $CONN->{open_container}") |
943 | if $CONN->{open_container} != 0; |
948 | if $CONN->{open_container} != 0; |
944 | }, |
949 | }, |
945 | ); |
950 | ); |
946 | |
951 | |
947 | $INVR_LBL->set_text ("Floor"); |
|
|
948 | $vb2->add ($INVR = new CFClient::UI::Inventory expand => 1); |
952 | $vb2->add ($INVR = new CFClient::UI::Inventory expand => 1); |
949 | |
953 | |
950 | $invwin |
954 | $invwin |
951 | } |
955 | } |
952 | |
956 | |
953 | sub make_help_window { |
957 | sub make_help_window { |
954 | my $win = new CFClient::UI::FancyFrame |
958 | my $win = new CFClient::UI::FancyFrame |
955 | user_w => $WIDTH * (7/8), user_h => $HEIGHT * (7/8), title => "Documentation"; |
959 | def_w => int $WIDTH * 7/8, |
|
|
960 | def_h => int $HEIGHT * 7/8, |
|
|
961 | title => "Documentation"; |
956 | |
962 | |
957 | $win->add (my $vbox = new CFClient::UI::VBox); |
963 | $win->add (my $vbox = new CFClient::UI::VBox); |
958 | |
964 | |
959 | $vbox->add (my $buttons = new CFClient::UI::HBox); |
965 | $vbox->add (my $buttons = new CFClient::UI::HBox); |
960 | $vbox->add (my $viewer = new CFClient::UI::TextView expand => 1, fontsize => 0.8); |
966 | $vbox->add (my $viewer = new CFClient::UI::TextView expand => 1, fontsize => 0.8); |
… | |
… | |
1111 | |
1117 | |
1112 | $BUTTONBAR->show; |
1118 | $BUTTONBAR->show; |
1113 | |
1119 | |
1114 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
1120 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
1115 | |
1121 | |
1116 | # delay till geometry is constant |
1122 | $SERVER_SETUP->show; |
1117 | $CFClient::UI::ROOT->on_post_alloc (startup => sub { |
|
|
1118 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
1119 | my $widget = $GAUGES->{win}; |
|
|
1120 | $widget->move (0, $HEIGHT - $widget->{h});#d# to in toplevel |
|
|
1121 | }); |
|
|
1122 | force_refresh (); |
|
|
1123 | } |
1123 | } |
1124 | } |
1124 | } |
1125 | |
1125 | |
1126 | sub video_shutdown { |
1126 | sub video_shutdown { |
1127 | undef $SDL_ACTIVE; |
1127 | undef $SDL_ACTIVE; |