indexing
description: "[
THIS CLASS WAS AUTO-GENERATED WITH THE COMMAND
em_settings_generator.exe bb_settings.xml
DO NOT EDIT THIS CLASS
Settings that can be accessed, modified, loaded and saved
]"
date: "$Date$"
revision: "$Revision$"
class
BB_SETTINGS
inherit
XM_CALLBACKS_FILTER_FACTORY
export {NONE} all end
EM_SHARED_USER_DIRECTORY
export {NONE} all end
EM_SHARED_APPLICATION_ID
creation
make
feature -- Initialization
make is
require
application_id_set: application_id.item /= void
do
set_user_file (user_directory.item, application_id.item + "_bb_settings.xml")
-- Inits for Section: audio
music_volume := default_music_volume
sfx_volume := default_sfx_volume
-- Inits for Section: input
device := default_device
-- Inits for Section: general
level_set := default_level_set
fullscreen := default_fullscreen
difficulty := default_difficulty
-- Inits for Section: multiplayer
mp_difficulty := default_mp_difficulty
number_of_games_to_win := default_number_of_games_to_win
start_level := default_start_level
score_for_enemy_block := default_score_for_enemy_block
remote_item_effect_mode := default_remote_item_effect_mode
remote_item_effect_chance := default_remote_item_effect_chance
nickname := default_nickname
end
feature -- Attributes
-- Attributes for Section: audio
music_volume: INTEGER
sfx_volume: INTEGER
-- Attributes for Section: input
device: STRING
-- Attributes for Section: general
level_set: STRING
fullscreen: BOOLEAN
difficulty: STRING
-- Attributes for Section: multiplayer
mp_difficulty: STRING
number_of_games_to_win: INTEGER
start_level: STRING
score_for_enemy_block: INTEGER
remote_item_effect_mode: STRING
remote_item_effect_chance: INTEGER
nickname: STRING
feature -- Defaults
-- Defaults for Section: audio
default_music_volume: INTEGER is 100
default_sfx_volume: INTEGER is 90
-- Defaults for Section: input
default_device: STRING is "Keyboard"
-- Defaults for Section: general
default_level_set: STRING is "original"
default_fullscreen: BOOLEAN is False
default_difficulty: STRING is "Normal"
-- Defaults for Section: multiplayer
default_mp_difficulty: STRING is "Normal"
default_number_of_games_to_win: INTEGER is 3
default_start_level: STRING is "Random"
default_score_for_enemy_block: INTEGER is 500
default_remote_item_effect_mode: STRING is "Random"
default_remote_item_effect_chance: INTEGER is 50
default_nickname: STRING is "Player"
restore_all_defaults is
do
restore_audio_defaults
restore_input_defaults
restore_general_defaults
restore_multiplayer_defaults
end
restore_audio_defaults is
do
music_volume := default_music_volume
sfx_volume := default_sfx_volume
end
restore_input_defaults is
do
device := default_device
end
restore_general_defaults is
do
level_set := default_level_set
fullscreen := default_fullscreen
difficulty := default_difficulty
end
restore_multiplayer_defaults is
do
mp_difficulty := default_mp_difficulty
number_of_games_to_win := default_number_of_games_to_win
start_level := default_start_level
score_for_enemy_block := default_score_for_enemy_block
remote_item_effect_mode := default_remote_item_effect_mode
remote_item_effect_chance := default_remote_item_effect_chance
nickname := default_nickname
end
feature -- Element change
-- Setter for Section: audio
set_music_volume (val: INTEGER) is
do
music_volume := val
end
set_sfx_volume (val: INTEGER) is
do
sfx_volume := val
end
-- Setter for Section: input
set_device (val: STRING) is
do
device := val
end
-- Setter for Section: general
set_level_set (val: STRING) is
do
level_set := val
end
set_fullscreen (val: BOOLEAN) is
do
fullscreen := val
end
set_difficulty (val: STRING) is
do
difficulty := val
end
-- Setter for Section: multiplayer
set_mp_difficulty (val: STRING) is
do
mp_difficulty := val
end
set_number_of_games_to_win (val: INTEGER) is
do
number_of_games_to_win := val
end
set_start_level (val: STRING) is
do
start_level := val
end
set_score_for_enemy_block (val: INTEGER) is
do
score_for_enemy_block := val
end
set_remote_item_effect_mode (val: STRING) is
do
remote_item_effect_mode := val
end
set_remote_item_effect_chance (val: INTEGER) is
do
remote_item_effect_chance := val
end
set_nickname (val: STRING) is
do
nickname := val
end
feature -- User settings
set_user_file (a_directory: STRING; a_filename: STRING) is
require
a_filename /= void
a_directory.item (a_directory.count) = '/'
do
create user_dir.make (a_directory)
create user_file.make (a_directory + a_filename)
end
user_dir: KL_DIRECTORY
user_file: PLAIN_TEXT_FILE
write_user_settings is
do
if not user_file.exists then
if not user_dir.exists then
user_dir.recursive_create_directory
end
if user_file.is_creatable then
user_file.create_read_write
user_file.close
end
end
if user_file.exists and then user_file.is_writable then
user_file.open_write
user_file.put_string ("%N%N")
user_file.put_string ("%N")
-- Write audio settings
if not music_volume.is_equal(default_music_volume) then
user_file.put_string ("%T%N")
end
if not sfx_volume.is_equal(default_sfx_volume) then
user_file.put_string ("%T%N")
end
-- Write input settings
if not device.is_equal(default_device) then
user_file.put_string ("%T%N")
end
-- Write general settings
if not level_set.is_equal(default_level_set) then
user_file.put_string ("%T%N")
end
if not fullscreen.is_equal(default_fullscreen) then
user_file.put_string ("%T%N")
end
if not difficulty.is_equal(default_difficulty) then
user_file.put_string ("%T%N")
end
-- Write multiplayer settings
if not mp_difficulty.is_equal(default_mp_difficulty) then
user_file.put_string ("%T%N")
end
if not number_of_games_to_win.is_equal(default_number_of_games_to_win) then
user_file.put_string ("%T%N")
end
if not start_level.is_equal(default_start_level) then
user_file.put_string ("%T%N")
end
if not score_for_enemy_block.is_equal(default_score_for_enemy_block) then
user_file.put_string ("%T%N")
end
if not remote_item_effect_mode.is_equal(default_remote_item_effect_mode) then
user_file.put_string ("%T%N")
end
if not remote_item_effect_chance.is_equal(default_remote_item_effect_chance) then
user_file.put_string ("%T%N")
end
if not nickname.is_equal(default_nickname) then
user_file.put_string ("%T%N")
end
user_file.put_string("%N%N")
user_file.close
else
debug
io.put_string("Failed to write settings%N")
end
end
end
user_settings_parser: XM_EIFFEL_PARSER
user_settings_filter: EM_SETTINGS_READER_XM_FILTER
user_settings_table: DS_HASH_TABLE[STRING, STRING]
read_user_settings is
do
if user_file.exists and then user_file.is_readable then
user_file.open_read
create user_settings_filter.make_null
create user_settings_parser.make
user_settings_parser.set_callbacks (callbacks_pipe (<>))
user_file.read_stream (user_file.count)
user_settings_parser.parse_from_string (user_file.last_string)
user_settings_table := user_settings_filter.user_settings_table
user_file.close
-- Apply audio settings
if user_settings_table.has("music_volume") then
if user_settings_table.item("music_volume").is_integer then
music_volume := user_settings_table.item("music_volume").to_integer
end
end
if user_settings_table.has("sfx_volume") then
if user_settings_table.item("sfx_volume").is_integer then
sfx_volume := user_settings_table.item("sfx_volume").to_integer
end
end
-- Apply input settings
if user_settings_table.has("device") then
device := user_settings_table.item("device")
end
-- Apply general settings
if user_settings_table.has("level_set") then
level_set := user_settings_table.item("level_set")
end
if user_settings_table.has("fullscreen") then
if user_settings_table.item("fullscreen").is_boolean then
fullscreen := user_settings_table.item("fullscreen").to_boolean
end
end
if user_settings_table.has("difficulty") then
difficulty := user_settings_table.item("difficulty")
end
-- Apply multiplayer settings
if user_settings_table.has("mp_difficulty") then
mp_difficulty := user_settings_table.item("mp_difficulty")
end
if user_settings_table.has("number_of_games_to_win") then
if user_settings_table.item("number_of_games_to_win").is_integer then
number_of_games_to_win := user_settings_table.item("number_of_games_to_win").to_integer
end
end
if user_settings_table.has("start_level") then
start_level := user_settings_table.item("start_level")
end
if user_settings_table.has("score_for_enemy_block") then
if user_settings_table.item("score_for_enemy_block").is_integer then
score_for_enemy_block := user_settings_table.item("score_for_enemy_block").to_integer
end
end
if user_settings_table.has("remote_item_effect_mode") then
remote_item_effect_mode := user_settings_table.item("remote_item_effect_mode")
end
if user_settings_table.has("remote_item_effect_chance") then
if user_settings_table.item("remote_item_effect_chance").is_integer then
remote_item_effect_chance := user_settings_table.item("remote_item_effect_chance").to_integer
end
end
if user_settings_table.has("nickname") then
nickname := user_settings_table.item("nickname")
end
end
end
feature -- Widgets
-- Widgets for Section: audio
widget_music_volume: EM_SLIDER
widget_sfx_volume: EM_SLIDER
-- Widgets for Section: input
widget_device: EM_COMBOBOX[STRING]
-- Widgets for Section: general
widget_fullscreen: EM_CHECKBOX
widget_difficulty: EM_COMBOBOX[STRING]
-- Widgets for Section: multiplayer
widget_mp_difficulty: EM_COMBOBOX[STRING]
widget_remote_item_effect_mode: EM_COMBOBOX[STRING]
widget_remote_item_effect_chance: EM_SLIDER
create_all_widgets is
do
create_audio_widgets
create_input_widgets
create_general_widgets
create_multiplayer_widgets
all_widgets_created := true
end
create_audio_widgets is
do
create widget_music_volume.make_from_range_horizontal(0, 128)
widget_music_volume.set_current_value(music_volume)
create widget_sfx_volume.make_from_range_horizontal(0, 128)
widget_sfx_volume.set_current_value(sfx_volume)
audio_widgets_created := true
end
create_input_widgets is
do
create widget_device.make_empty
widget_device.put("Keyboard")
widget_device.put("Joystick")
if widget_device.has (device) then
widget_device.set_selected_element (device)
end
input_widgets_created := true
end
create_general_widgets is
do
create widget_fullscreen.make_empty
if fullscreen then
widget_fullscreen.set_checked
else
widget_fullscreen.set_unchecked
end
create widget_difficulty.make_empty
widget_difficulty.put("Foolproof")
widget_difficulty.put("Easy")
widget_difficulty.put("Normal")
widget_difficulty.put("Hard")
widget_difficulty.put("Insane")
if widget_difficulty.has (difficulty) then
widget_difficulty.set_selected_element (difficulty)
end
general_widgets_created := true
end
create_multiplayer_widgets is
do
create widget_mp_difficulty.make_empty
widget_mp_difficulty.put("Foolproof")
widget_mp_difficulty.put("Easy")
widget_mp_difficulty.put("Normal")
widget_mp_difficulty.put("Hard")
widget_mp_difficulty.put("Insane")
if widget_mp_difficulty.has (mp_difficulty) then
widget_mp_difficulty.set_selected_element (mp_difficulty)
end
create widget_remote_item_effect_mode.make_empty
widget_remote_item_effect_mode.put("Random")
widget_remote_item_effect_mode.put("All")
widget_remote_item_effect_mode.put("First")
widget_remote_item_effect_mode.put("Distributed")
if widget_remote_item_effect_mode.has (remote_item_effect_mode) then
widget_remote_item_effect_mode.set_selected_element (remote_item_effect_mode)
end
create widget_remote_item_effect_chance.make_from_range_horizontal(0, 100)
widget_remote_item_effect_chance.set_current_value(remote_item_effect_chance)
multiplayer_widgets_created := true
end
free_all_widgets is
do
free_audio_widgets
free_input_widgets
free_general_widgets
free_multiplayer_widgets
all_widgets_created := false
end
free_audio_widgets is
do
all_widgets_created := false
audio_widgets_created := false
widget_music_volume := void
widget_sfx_volume := void
end
free_input_widgets is
do
all_widgets_created := false
input_widgets_created := false
widget_device := void
end
free_general_widgets is
do
all_widgets_created := false
general_widgets_created := false
widget_fullscreen := void
widget_difficulty := void
end
free_multiplayer_widgets is
do
all_widgets_created := false
multiplayer_widgets_created := false
widget_mp_difficulty := void
widget_remote_item_effect_mode := void
widget_remote_item_effect_chance := void
end
apply_all_settings is
do
apply_audio_settings
apply_input_settings
apply_general_settings
apply_multiplayer_settings
end
apply_audio_settings is
require
widgets_created: audio_widgets_created
do
music_volume := widget_music_volume.current_value
sfx_volume := widget_sfx_volume.current_value
end
apply_input_settings is
require
widgets_created: input_widgets_created
do
device := widget_device.selected_element
end
apply_general_settings is
require
widgets_created: general_widgets_created
do
fullscreen := widget_fullscreen.is_checked
difficulty := widget_difficulty.selected_element
end
apply_multiplayer_settings is
require
widgets_created: multiplayer_widgets_created
do
mp_difficulty := widget_mp_difficulty.selected_element
remote_item_effect_mode := widget_remote_item_effect_mode.selected_element
remote_item_effect_chance := widget_remote_item_effect_chance.current_value
end
reset_all_widgets is
do
reset_audio_widgets
reset_input_widgets
reset_general_widgets
reset_multiplayer_widgets
end
reset_audio_widgets is
require
widgets_created: audio_widgets_created
do
widget_music_volume.set_current_value(music_volume)
widget_sfx_volume.set_current_value(sfx_volume)
end
reset_input_widgets is
require
widgets_created: input_widgets_created
do
if widget_device.has (device) then
widget_device.set_selected_element(device)
end
end
reset_general_widgets is
require
widgets_created: general_widgets_created
do
if fullscreen = true then
widget_fullscreen.set_checked
else
widget_fullscreen.set_unchecked
end
if widget_difficulty.has (difficulty) then
widget_difficulty.set_selected_element(difficulty)
end
end
reset_multiplayer_widgets is
require
widgets_created: multiplayer_widgets_created
do
if widget_mp_difficulty.has (mp_difficulty) then
widget_mp_difficulty.set_selected_element(mp_difficulty)
end
if widget_remote_item_effect_mode.has (remote_item_effect_mode) then
widget_remote_item_effect_mode.set_selected_element(remote_item_effect_mode)
end
widget_remote_item_effect_chance.set_current_value(remote_item_effect_chance)
end
all_widgets_created: BOOLEAN
audio_widgets_created: BOOLEAN
input_widgets_created: BOOLEAN
general_widgets_created: BOOLEAN
multiplayer_widgets_created: BOOLEAN
end