indexing description: "[ Scene with widgets to modify settings ]" date: "$Date$" revision: "$Revision$" class SETTINGS_SCENE inherit SHARED_SETTINGS EM_WIDGET_SCENE redefine initialize_scene, start_next_scene end create make_widget_scene feature -- Initialization initialize_scene is -- initialize the scene do set_background_color (theme_colors.window_background) -- Important remark: -- Changing a widget's value does NOT automatically change the corresponding variable's value! -- You have to call settings.apply_*_settings first! -- On the other hand, -- changing a variable's value does NOT automatically change the corresponding widget's value! -- You have to call settings.reset_*_widgets first! -- All widgets that were specified in settings.xml are available through the settings-objects -- They simply have to be positioned, resized (and optionally colored, ...) and added to the scene settings.create_all_widgets setup_widgets -- Settings widgets add_widget (settings.widget_music_enabled) add_widget (settings.widget_sfx_enabled) add_widget (settings.widget_music_genre) add_widget (settings.widget_music_song) settings.widget_sfx_volume.mouse_button_up_event.subscribe (agent sfx_volume_changed(?)) add_widget (settings.widget_sfx_volume) settings.widget_music_volume.position_changed_event.subscribe (agent music_volume_changed(?)) add_widget (settings.widget_music_volume) -- Buttons apply_button.clicked_event.subscribe (agent settings.apply_all_settings) add_widget (apply_button) reset_button.clicked_event.subscribe (agent settings.reset_all_widgets) add_widget (reset_button) set_defaults_button.clicked_event.subscribe (agent settings.restore_all_defaults) set_defaults_button.clicked_event.subscribe (agent settings.reset_all_widgets) add_widget (set_defaults_button) quit_button.clicked_event.subscribe (agent quit) add_widget (quit_button) -- Audio create music_player.make_with_file ("../../resources/music/sorry.ogg", false) music_player.set_repeat (true) music_player.play create sound_player.make_with_file ("../../resources/sound/channel_0.ogg", false) end start_next_scene is -- We'll free all widgets when we change the scene (which is not done in this example) -- Be aware that if you don't do that, all widgets (with all subscribtions) -- still are in the application -- This might for example cause trouble when you enter this scene once again -- and again subscribe actions do settings.free_all_widgets Precursor end music_volume_changed(a_volume: INTEGER) is -- This function get's called when the music-slider is moved -- we'll change the music volume on the fly here do music_player.set_volume (settings.widget_music_volume.current_value) end sfx_volume_changed(a_button: EM_MOUSEBUTTON_EVENT) is -- This function get's called when the SFX-slider has finished moving -- we'll make a sound to indicate how loud it is now -- (we have to have "a_button" here, because the subscription requests that) do -- todo sound_player.set_volume (settings.widget_sfx_volume.current_value) if sound_player.playlist.count > 0 then sound_player.play_i_th (sound_player.playlist.count, 0) end end setup_widgets is -- Set positions, dimensions and texts of all widgets local button_width, button_height: INTEGER button_offset_x, button_offset_y, button_spacing: INTEGER widget_offset_x, widget_offset_y, widget_spacing: INTEGER music_label, sfx_label, genre_labEL, music_vol_label, sfx_vol_label, song_label: EM_LABEL title: EM_LABEL used_label, unused_label: EM_LABEL do create title.make_from_text ("Changes will be saved when you press 'Apply'") title.set_position (20, 20) add_widget (title) -- Initialize some variables button_width := 200 button_height := 40 button_offset_x := 20 button_offset_y := 240 button_spacing := 60 widget_offset_x := 300 widget_offset_y := 125 widget_spacing := 55 -- Settings widgets settings.widget_music_volume.set_position (widget_offset_x, widget_offset_y + 0 * widget_spacing) settings.widget_music_volume.set_dimension (300, 20) settings.widget_sfx_volume.set_position (widget_offset_x, widget_offset_y + 1 * widget_spacing) settings.widget_sfx_volume.set_dimension (300, 20) settings.widget_music_enabled.set_position (widget_offset_x, widget_offset_y + 3 * widget_spacing) settings.widget_sfx_enabled.set_position (widget_offset_x + 100, widget_offset_y + 3 * widget_spacing) settings.widget_music_genre.set_position (widget_offset_x, widget_offset_y + 4 * widget_spacing) settings.widget_music_genre.set_dimension (300, 20) settings.widget_music_song.set_position (widget_offset_x, widget_offset_y + 5 * widget_spacing) settings.widget_music_song.set_dimension (300, 60) -- Buttons create apply_button.make_from_dimension (button_width, button_height) apply_button.set_position (button_offset_x, button_offset_y + 0 * button_spacing) apply_button.set_text ("Apply") create reset_button.make_from_dimension (button_width, button_height) reset_button.set_position (button_offset_x, button_offset_y + 1 * button_spacing) reset_button.set_text ("Reset") create set_defaults_button.make_from_dimension (button_width, button_height) set_defaults_button.set_position (button_offset_x, button_offset_y + 2 * button_spacing) set_defaults_button.set_text ("Restore Defaults") create quit_button.make_from_dimension (button_width, button_height) quit_button.set_position (button_offset_x, button_offset_y + 3 * button_spacing) quit_button.set_text ("Quit") -- Labels create used_label.make_from_text ("Used widgets:") used_label.set_position (settings.widget_music_volume.x, settings.widget_music_volume.y - 60) add_widget (used_label) create unused_label.make_from_text ("Unsed widgets (demonstration purpose only):") unused_label.set_position (settings.widget_music_enabled.x, settings.widget_music_enabled.y - 40) add_widget (unused_label) create music_label.make_from_text ("Music") music_label.set_position (settings.widget_music_enabled.x + 20, settings.widget_music_enabled.y) add_widget (music_label) create sfx_label.make_from_text ("SFX") sfx_label.set_position (settings.widget_sfx_enabled.x + 20, settings.widget_sfx_enabled.y) add_widget (sfx_label) create genre_label.make_from_text ("Genre") genre_label.set_position (settings.widget_music_genre.x, settings.widget_music_genre.y - 20) add_widget (genre_label) create music_vol_label.make_from_text ("Music Volume") music_vol_label.set_position (settings.widget_music_volume.x, settings.widget_music_volume.y - 20) add_widget (music_vol_label) create sfx_vol_label.make_from_text ("SFX Volume") sfx_vol_label.set_position (settings.widget_sfx_volume.x, settings.widget_sfx_volume.y - 20) add_widget (sfx_vol_label) create song_label.make_from_text ("Song") song_label.set_position (settings.widget_music_song.x, settings.widget_music_song.y - 20) add_widget (song_label) end apply_button: EM_BUTTON quit_button: EM_BUTTON reset_button: EM_BUTTON set_defaults_button: EM_BUTTON music_player: EM_MUSIC_PLAYER sound_player: EM_SOUND_PLAYER end