indexing description: "[ Multiplayer Waiting Room - Client ]" date: "$Date$" revision: "$Revision$" class BB_WAITING_ROOM_CLIENT inherit BB_MENU redefine handle_key_down_event end SHARED_BB_SETTINGS export {NONE} all end create make feature -- Initialization make (a_client: EM_NET_CLIENT [BB_MP_OBJECT_TYPES]; an_options_object: BB_MP_OPTIONS) is -- require client_not_void: a_client /= Void options_not_void: an_options_object /= Void local button: BB_MENU_BUTTON a_playerlist_request: BB_MP_PLAYERLIST_REQUEST a_label: EM_LABEL do init_menu options := an_options_object client := a_client client.subscribe_by_type_id (client.object_types.bb_mp_playerlist, agent on_playerlist (?)) client.subscribe_by_type_id (client.object_types.bb_mp_start_game, agent on_start_game) client.subscribe_by_type_id (client.object_types.bb_mp_chat_message, agent on_chat_message (?)) client.subscribe_by_type_id (client.object_types.bb_mp_leave_game, agent on_connection_lost (?)) client.timeout_event.subscribe (agent on_connection_lost (?)) create nickname.make_from_string (bb_settings.nickname) create button.make ("Back") button.set_position (50, 530) button.pressed_event.subscribe (agent back_button_pressed) add_button (button) create connected_players_label.make_from_text ("Connected Players") connected_players_label.set_font (Standard_ttf_fonts.bitstream_vera_sans_bold (18)) connected_players_label.set_foreground_color (create {EM_COLOR}.make_white) connected_players_label.set_position (20, 180) connected_players_label.resize_to_optimal_dimension add_widget (connected_players_label) create connected_players.make_empty connected_players.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) connected_players.set_foreground_color (create {EM_COLOR}.make_white) connected_players.set_position (20, 200) connected_players.resize_to_optimal_dimension add_widget (connected_players) create a_label.make_from_text ("Effect mode: " + options.remote_item_effect_mode) a_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) a_label.set_foreground_color (create {EM_COLOR}.make_white) a_label.set_position (450, 300) a_label.resize_to_optimal_dimension add_widget (a_label) create a_label.make_from_text ("Remote effect chance: " + options.remote_item_effect_chance.out + "%%") a_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) a_label.set_foreground_color (create {EM_COLOR}.make_white) a_label.set_position (450, 330) a_label.resize_to_optimal_dimension add_widget (a_label) create a_label.make_from_text ("Add block score: " + options.score_for_enemy_block.out) a_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) a_label.set_foreground_color (create {EM_COLOR}.make_white) a_label.set_position (450, 360) a_label.resize_to_optimal_dimension add_widget (a_label) create a_label.make_from_text ("Difficulty: " + options.difficulty) a_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) a_label.set_foreground_color (create {EM_COLOR}.make_white) a_label.set_position (450, 390) a_label.resize_to_optimal_dimension add_widget (a_label) create a_label.make_from_text ("Win games: " + options.number_of_games_to_win.out) a_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) a_label.set_foreground_color (create {EM_COLOR}.make_white) a_label.set_position (450, 420) a_label.resize_to_optimal_dimension add_widget (a_label) create a_label.make_from_text ("Start level: " + options.start_level) a_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) a_label.set_foreground_color (create {EM_COLOR}.make_white) a_label.set_position (450, 450) a_label.resize_to_optimal_dimension add_widget (a_label) create chat_window.make_empty chat_window.set_position (20, 350) chat_window.set_dimension (400, 95) chat_window.disable add_widget (chat_window) create chat_input.make_from_size (50) chat_input.set_position (20, 455) chat_input.set_width (400) add_widget (chat_input) -- request server for the playernames a_playerlist_request := client.object_types.create_bb_mp_playerlist_request a_playerlist_request.set_resend_time (Resend_time) a_playerlist_request.set_resends_left (Number_of_resends) client.event_2pc_id_manager.set_unique_id_for_object (a_playerlist_request) a_playerlist_request.set_group (client.standard_group) a_playerlist_request.set_player_name (bb_settings.nickname) a_playerlist_request.publish set_selected_menu_item (1) end feature -- Events back_button_pressed is -- back button pressed local a_leave_game: BB_MP_LEAVE_GAME do if not was_back_button_pressed then was_back_button_pressed := True a_leave_game := client.object_types.create_bb_mp_leave_game a_leave_game.set_resend_time (Resend_time) a_leave_game.set_resends_left (Number_of_resends) client.event_2pc_id_manager.set_unique_id_for_object (a_leave_game) a_leave_game.set_group (client.standard_group) a_leave_game.publish end end on_playerlist (a_playerlist: BB_MP_PLAYERLIST) is -- Handle received playerlist do connected_players.set_text ("") from a_playerlist.players.start until a_playerlist.players.after loop connected_players.text.append (a_playerlist.players.item_for_iteration + ", ") a_playerlist.players.forth end connected_players.text.keep_head (connected_players.text.count - 2) connected_players.resize_to_optimal_dimension end on_start_game is -- start the game do if options.level_set.is_equal ("Simple") then bb_settings.set_level_set ("simple_multiplayer") else bb_settings.set_level_set ("multiplayer") end bb_settings.write_user_settings client.unsubscribe_by_type_id (client.object_types.bb_mp_playerlist, agent on_playerlist (?)) client.unsubscribe_by_type_id (client.object_types.bb_mp_chat_message, agent on_chat_message (?)) client.timeout_event.unsubscribe (agent on_connection_lost (?)) set_next_scene (create {BB_MP_MULTIFIELD_CLIENT_LEVEL_SCENE}.make (client, Void, options)) start_next_scene end on_chat_message (a_chat_message: BB_MP_CHAT_MESSAGE) is -- handle chat message local chat_lines: DS_LIST [STRING] do chat_lines ?= chat_window.elements check -- elements are implemnted as DS_LIST chat_lines /= Void end chat_lines.put_first (a_chat_message.nickname + ": " + a_chat_message.message) chat_window.set_changed end on_connection_lost (a_connection: EM_NET_CONNECTION) is -- client lost connection to server do debug ("brick_breaker") io.put_string ("Lost connection to server") io.put_new_line end leave_room end handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events require else a_keyboard_event_not_void: a_keyboard_event /= Void local do if chat_input.has_focus and a_keyboard_event.key = a_keyboard_event.sdlk_return then send_chat_line else Precursor (a_keyboard_event) end end send_chat_line is -- send text of chat_input to chat local a_chat_message: BB_MP_CHAT_MESSAGE do if not chat_input.text.is_empty then a_chat_message := client.object_types.create_bb_mp_chat_message a_chat_message.set_resend_time (Resend_time) a_chat_message.set_resends_left (Number_of_resends) client.event_2pc_id_manager.set_unique_id_for_object (a_chat_message) a_chat_message.set_group (client.standard_group) a_chat_message.set_nickname (nickname) a_chat_message.set_message (create {STRING}.make_from_string (chat_input.text)) a_chat_message.publish chat_input.set_cursor_position (0) chat_input.text.make_empty end end feature {NONE} -- Implementation connected_players_label: EM_LABEL connected_players: EM_LABEL client: EM_NET_CLIENT [BB_MP_OBJECT_TYPES] -- Client nickname: STRING -- Nickname chat_window: EM_TEXTLIST [STRING] -- chat window chat_input: EM_TEXTBOX -- textbox to write chatmessages options: BB_MP_OPTIONS -- options for this game was_back_button_pressed: BOOLEAN -- was back button already pressed? leave_room is -- leave room do debug ("brick_breaker") io.put_string ("leaving room") io.put_new_line end client.disable_auto_transmit client.disable_time_sync client.close set_next_scene (create {BB_JOIN_GAME}.make) start_next_scene end end