indexing description: "[ Host Multiplayer Game ]" date: "$Date$" revision: "$Revision$" class BB_HOST_GAME inherit BB_MENU EM_SHARED_SUBSYSTEMS export {NONE} all end SHARED_BB_SETTINGS export {NONE} all end create make feature -- Initialization make is -- create widgets local button: BB_MENU_BUTTON label: EM_LABEL do init_menu bb_settings.create_multiplayer_widgets -- create menu items create button.make ("Create Game") button.set_position (500, 530) button.pressed_event.subscribe (agent creategame_button_pressed) add_button (button) create button.make ("Back") button.set_position (50, 530) button.pressed_event.subscribe (agent back_button_pressed) add_button (button) create nickname_label.make_from_text ("Nickname:") nickname_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) nickname_label.set_foreground_color (create {EM_COLOR}.make_white) nickname_label.set_position (100, 120) nickname_label.resize_to_optimal_dimension add_widget (nickname_label) create nickname_textbox.make_from_size (Maximum_nickname_length + 3) nickname_textbox.set_position (100, 145) nickname_textbox.text_changed_event.subscribe (agent on_nickname_textbox_changed) nickname_textbox.set_text (bb_settings.nickname) add_widget (nickname_textbox) create remote_item_effect_mode_lebel.make_from_text ("Effect mode:") remote_item_effect_mode_lebel.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) remote_item_effect_mode_lebel.set_foreground_color (create {EM_COLOR}.make_white) remote_item_effect_mode_lebel.set_position (100, 175) remote_item_effect_mode_lebel.resize_to_optimal_dimension add_widget (remote_item_effect_mode_lebel) bb_settings.widget_remote_item_effect_mode.set_position (100,200) bb_settings.widget_remote_item_effect_mode.set_dimension (200, 50) bb_settings.widget_remote_item_effect_mode.resize_to_optimal_dimension add_widget (bb_settings.widget_remote_item_effect_mode) create remote_item_effect_chance_label.make_from_text ("Remote effect chance:") remote_item_effect_chance_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) remote_item_effect_chance_label.set_foreground_color (create {EM_COLOR}.make_white) remote_item_effect_chance_label.set_position (100, 230) remote_item_effect_chance_label.resize_to_optimal_dimension add_widget (remote_item_effect_chance_label) create current_remote_item_effect_chance_label.make_from_text ("") current_remote_item_effect_chance_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) current_remote_item_effect_chance_label.set_foreground_color (create {EM_COLOR}.make_white) current_remote_item_effect_chance_label.set_position (320, 255) add_widget (current_remote_item_effect_chance_label) bb_settings.widget_remote_item_effect_chance.set_position (100,255) bb_settings.widget_remote_item_effect_chance.set_dimension (200, 20) bb_settings.widget_remote_item_effect_chance.position_changed_event.subscribe (agent on_remote_item_effect_chance_changed) on_remote_item_effect_chance_changed (bb_settings.remote_item_effect_chance) add_widget (bb_settings.widget_remote_item_effect_chance) create score_for_enemy_block_label.make_from_text ("Add block score:") score_for_enemy_block_label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) score_for_enemy_block_label.set_foreground_color (create {EM_COLOR}.make_white) score_for_enemy_block_label.set_position (100, 285) score_for_enemy_block_label.resize_to_optimal_dimension add_widget (score_for_enemy_block_label) create score_for_enemy_block_textbox.make_from_size (6) score_for_enemy_block_textbox.set_position (100, 310) score_for_enemy_block_textbox.text_changed_event.subscribe (agent on_score_for_enemy_block_textbox_changed) score_for_enemy_block_textbox.set_text (bb_settings.score_for_enemy_block.out) add_widget (score_for_enemy_block_textbox) create label.make_from_text ("Difficulty:") label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) label.set_foreground_color (create {EM_COLOR}.make_white) label.set_position (100, 340) label.resize_to_optimal_dimension add_widget (label) bb_settings.widget_mp_difficulty.set_position (100,365) bb_settings.widget_mp_difficulty.set_dimension (200, 50) bb_settings.widget_mp_difficulty.resize_to_optimal_dimension add_widget (bb_settings.widget_mp_difficulty) create label.make_from_text ("Games to win:") label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) label.set_foreground_color (create {EM_COLOR}.make_white) label.set_position (100, 395) label.resize_to_optimal_dimension add_widget (label) create games_to_win_textbox.make_from_size (2) games_to_win_textbox.set_position (100, 420) games_to_win_textbox.text_changed_event.subscribe (agent on_games_to_win_textbox_changed) games_to_win_textbox.set_text (bb_settings.number_of_games_to_win.out) add_widget (games_to_win_textbox) create label.make_from_text ("Start level:") label.set_font (Standard_ttf_fonts.bitstream_vera_sans (18)) label.set_foreground_color (create {EM_COLOR}.make_white) label.set_position (100, 450) label.resize_to_optimal_dimension add_widget (label) create start_level_textbox.make_from_size (20) start_level_textbox.set_position (100, 475) start_level_textbox.set_text (bb_settings.start_level) add_widget (start_level_textbox) set_selected_menu_item (1) end feature -- Events on_nickname_textbox_changed is -- ckeck if nickname is not too long do if nickname_textbox.text.count > Maximum_nickname_length then nickname_textbox.delete_character_left_of_cursor end end on_score_for_enemy_block_textbox_changed is -- ckeck if only integers are entered do if not score_for_enemy_block_textbox.text.is_integer and not score_for_enemy_block_textbox.text.is_empty then score_for_enemy_block_textbox.set_cursor_position (bb_settings.score_for_enemy_block.out.count) score_for_enemy_block_textbox.set_text (bb_settings.score_for_enemy_block.out) elseif score_for_enemy_block_textbox.text.is_integer and score_for_enemy_block_textbox.text.to_integer <= 0 then score_for_enemy_block_textbox.set_cursor_position (bb_settings.score_for_enemy_block.out.count) score_for_enemy_block_textbox.set_text (bb_settings.score_for_enemy_block.out) end end on_games_to_win_textbox_changed is -- ckeck if only integers are entered do if (not games_to_win_textbox.text.is_integer and not games_to_win_textbox.text.is_empty) then games_to_win_textbox.set_cursor_position (bb_settings.number_of_games_to_win.out.count) games_to_win_textbox.set_text (bb_settings.number_of_games_to_win.out) elseif games_to_win_textbox.text.count > 2 then games_to_win_textbox.delete_character_left_of_cursor end end on_remote_item_effect_chance_changed (a_value: INTEGER) is -- remote item effect chance changed do current_remote_item_effect_chance_label.set_text (a_value.out + "%%") current_remote_item_effect_chance_label.resize_to_optimal_dimension end creategame_button_pressed is -- create game button pressed do if is_nickname_valid then bb_settings.set_nickname (nickname_textbox.text) if score_for_enemy_block_textbox.text.is_empty then score_for_enemy_block_textbox.set_text ("0") end bb_settings.set_score_for_enemy_block (score_for_enemy_block_textbox.text.to_integer) bb_settings.set_number_of_games_to_win (games_to_win_textbox.text.to_integer) bb_settings.set_start_level (start_level_textbox.text) bb_settings.apply_multiplayer_settings bb_settings.write_user_settings bb_settings.free_multiplayer_widgets set_next_scene (create {BB_WAITING_ROOM_SERVER}.make) start_next_scene end end back_button_pressed is -- back button pressed do bb_settings.free_multiplayer_widgets set_next_scene (create {BB_MULTIPLAYER}.make) start_next_scene end feature {NONE} -- Implementation is_nickname_valid: BOOLEAN is -- is `nickname_textbox.text' a valid nickname? do Result := nickname_textbox.text.count > 0 and nickname_textbox.text.count < Maximum_nickname_length end feature {NONE} -- Implementation nickname_textbox: EM_TEXTBOX nickname_label: EM_LABEL score_for_enemy_block_textbox: EM_TEXTBOX remote_item_effect_chance_label: EM_LABEL current_remote_item_effect_chance_label: EM_LABEL remote_item_effect_mode_lebel: EM_LABEL score_for_enemy_block_label: EM_LABEL games_to_win_textbox: EM_TEXTBOX start_level_textbox: EM_TEXTBOX end