gui2/tpreferences: implemented new gui2 Preferences dialog

This commit is contained in:
Charles Dang 2016-02-02 01:00:08 +11:00
parent 6626bbce22
commit b7d56e0c11
15 changed files with 1679 additions and 246 deletions

View file

@ -3,70 +3,47 @@
### Main game preferences dialog.
###
#define _GUI_PREFS_PLACEHOLDER PAGE_NUM
[row]
#define _GUI_INFO_TAB_PADDING
[column]
border = all
border_size = 5
[column]
grow_factor = 1
horizontal_grow = "true"
[spacer]
width = 10
[/spacer]
border = "all"
border_size = 5
[label]
id = "page{PAGE_NUM}_label1"
definition = "default"
label = "This is page #{PAGE_NUM}."
[/label]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "button{PAGE_NUM}"
definition = "default"
label = "Button {PAGE_NUM}"
tooltip = "This is the page #{PAGE_NUM} button — you know you want to push it"
[/button]
[/column]
[/row]
[/column]
#enddef
#define _GUI_PREFS_PAGE1_CONTENTS
{_GUI_PREFS_PLACEHOLDER (1)}
#enddef
#define _GUI_TAB_BAR
[toggle_panel]
linked_group = "tabs"
#define _GUI_PREFS_PAGE2_CONTENTS
{_GUI_PREFS_PLACEHOLDER (2)}
#enddef
[grid]
#define _GUI_PREFS_PAGE3_CONTENTS
{_GUI_PREFS_PLACEHOLDER (3)}
#enddef
[row]
#define _GUI_PREFS_PAGE4_CONTENTS
{_GUI_PREFS_PLACEHOLDER (4)}
#enddef
{_GUI_INFO_TAB_PADDING}
#define _GUI_PREFS_PAGE5_CONTENTS
{_GUI_PREFS_PLACEHOLDER (5)}
#enddef
[column]
grow_factor = 1
border = all
border_size = 5
#define _GUI_PREFS_PAGE PAGE_NUM
[layer]
id = "page{PAGE_NUM}"
{_GUI_PREFS_PAGE{PAGE_NUM}_CONTENTS}
[/layer]
[label]
id = "tab_label"
wrap = true
[/label]
[/column]
{_GUI_INFO_TAB_PADDING}
[/row]
[/grid]
[/toggle_panel]
#enddef
[window]
@ -80,8 +57,8 @@
vertical_placement = "center"
horizontal_placement = "center"
maximum_width = 800
maximum_height = 600
maximum_width = 900
maximum_height = 500
[linked_group]
id = "page_icon"
@ -93,6 +70,16 @@
fixed_width = "true"
[/linked_group]
[linked_group]
id = "tabs"
fixed_width = "true"
[/linked_group]
[linked_group]
id = "friends"
fixed_width = "true"
[/linked_group]
[tooltip]
id = "tooltip_large"
[/tooltip]
@ -115,7 +102,7 @@
[label]
id = "title"
definition = "title"
label = _ "Preferences Mk. II"
label = _ "Preferences"
[/label]
[/column]
@ -172,7 +159,7 @@
# consistency with an invisible spacer.
#
[spacer]
width = 0
width = 20
height = 72
[/spacer]
[/column]
@ -248,3 +235,4 @@
#undef _GUI_PREFS_PAGE4
#undef _GUI_PREFS_PAGE5
#undef _GUI_PREFS_PAGE
#undef _GUI_INFO_TAB_PADDING

View file

@ -7,15 +7,33 @@
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[grid]
[row]
[column]
border = "top,left,right"
border_size = 5
horizontal_alignment = "left"
[label]
id = {_LABEL_ID}
definition = "default_small"
label = {_LABEL_TEXT}
[/label]
[label]
id = "help_text"
definition = "default_small"
label = {_LABEL_TEXT}
[/label]
[/column]
[column]
border = "top,right"
border_size = 5
horizontal_alignment = "left"
[scroll_label]
id = {_LABEL_ID}
definition = "default_small"
[/scroll_label]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
@ -34,7 +52,7 @@
[/grid]
#enddef
#define _GUI_PREFERENCES_MAIN_GRID_1
#define _GUI_PREFERENCES_GENERAL_GRID_1
[row]
[column]
horizontal_grow = true
@ -44,6 +62,7 @@
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
label = _ "Scroll speed:"
@ -51,9 +70,9 @@
[/column]
[column]
horizontal_grow = true
border = "all"
border_size = 5
horizontal_grow = true
[slider]
id = "scroll_speed"
@ -71,14 +90,14 @@
[row]
[column]
horizontal_grow = true
horizontal_alignment = "left"
[grid]
[row]
[column]
border = "top,left,right"
border_size = 5
horizontal_alignment = "left"
horizontal_grow = true
[toggle_button]
id = "turbo_toggle"
@ -90,7 +109,7 @@
[column]
border = "top,left,right"
border_size = 5
horizontal_alignment = "left"
horizontal_grow = true
[toggle_button]
id = "skip_ai_moves"
@ -108,9 +127,9 @@
horizontal_grow = true
{_GUI_PREFERENCES_CHECKBOX_ALIGN_BORDER}
{_GUI_PREFERENCES_MAIN_COMPOSITE_SLIDER
turbo_value ( _ "Speed: $value")
turbo_value ( _ "Speed:")
turbo_slider (
minimum_value,maximum_value=0,11
minimum_value,maximum_value=1,12
step_size=1
tooltip= _ "Units move and fight speed"
)
@ -225,7 +244,7 @@
horizontal_grow = true
{_GUI_PREFERENCES_CHECKBOX_ALIGN_BORDER}
{_GUI_PREFERENCES_MAIN_COMPOSITE_SLIDER
max_saves_value ( _ "Maximum auto-saves: $value")
max_saves_value ( _ "Maximum auto-saves:")
max_saves_slider (
minimum_value,maximum_value=0,61
step_size=1
@ -236,7 +255,7 @@
[/row]
#enddef
#define _GUI_PREFERENCES_MAIN_GRID_2
#define _GUI_PREFERENCES_GENERAL_GRID_2
[row]
[column]
border = "all"
@ -246,6 +265,7 @@
[button]
id = hotkeys
label = _ "Hotkeys"
tooltip = "View and configure keyboard shortcuts"
[/button]
[/column]
@ -257,6 +277,7 @@
[button]
id = cachemg
label = _ "Cache"
tooltip = "Manage the game WML cache"
[/button]
[/column]
[/row]
@ -271,11 +292,10 @@
[grid]
[row]
[column]
horizontal_alignment = "left"
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
{_GUI_PREFERENCES_MAIN_GRID_1}
{_GUI_PREFERENCES_GENERAL_GRID_1}
[/grid]
[/column]
[/row]
@ -286,7 +306,7 @@
vertical_alignment = "bottom"
[grid]
{_GUI_PREFERENCES_MAIN_GRID_2}
{_GUI_PREFERENCES_GENERAL_GRID_2}
[/grid]
[/column]
[/row]
@ -295,5 +315,5 @@
[/row]
[/layer]
#undef _GUI_PREFERENCES_MAIN_GRID_1
#undef _GUI_PREFERENCES_MAIN_GRID_2
#undef _GUI_PREFERENCES_GENERAL_GRID_1
#undef _GUI_PREFERENCES_GENERAL_GRID_2

View file

@ -7,6 +7,7 @@
[row]
[column]
horizontal_alignment = "left"
vertical_alignment = "top"
[grid]
[row]
@ -25,23 +26,13 @@
border_size = 5
horizontal_alignment = "left"
[scroll_label]
id = "resolution"
definition = "description"
label = "1920x1080"
[/scroll_label]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
[combobox]
id = "resolution_set"
label = _ "display_resolution^Change"
[/button]
definition = "default"
tooltip = "Change the game resolution"
[/combobox]
[/column]
[/row]
[row]
@ -55,10 +46,10 @@
[toggle_button]
id = "fullscreen"
label = _ "Full screen"
tooltip = "Toggle between fullscreen and window mode"
[/toggle_button]
[/column]
{GUI_FILLER}
[/row]
[/grid]
[/column]
@ -75,6 +66,7 @@
[toggle_button]
id = "show_floating_labels"
label = _ "Show floating labels"
tooltip = "Show damage and healing amounts above a unit"
[/toggle_button]
[/column]
[/row]
@ -88,6 +80,7 @@
[toggle_button]
id = "show_halos"
label = _ "Show haloing effects"
tooltip = "Show special unit graphical effects"
[/toggle_button]
[/column]
[/row]
@ -101,6 +94,7 @@
[toggle_button]
id = "show_ellipses"
label = _ "Show team colors"
tooltip = "Show a colored circle around the base of each unit to show which side it is on"
[/toggle_button]
[/column]
[/row]
@ -116,6 +110,7 @@
[toggle_button]
id = "show_grid"
label = _ "Show grid"
tooltip = "Overlay a grid over the map"
[/toggle_button]
[/column]
[/row]
@ -131,6 +126,7 @@
[toggle_button]
id = "animate_terrains"
label = _ "Animate map"
tooltip = "Display animated terrain graphics"
[/toggle_button]
[/column]
[/row]
@ -144,6 +140,7 @@
[toggle_button]
id = "animate_units_standing"
label = _ "Show unit standing animations"
tooltip = "Continuously animate standing units in the battlefield"
[/toggle_button]
[/column]
[/row]
@ -162,6 +159,7 @@
[toggle_button]
id = "animate_units_idle"
label = _ "Show unit idle animations"
tooltip = "Play short random animations for idle units"
[/toggle_button]
[/column]
[/row]
@ -177,9 +175,10 @@
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
horizontal_grow = true
[label]
definition = "default_small"
@ -188,8 +187,10 @@
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = true
[slider]
id = "idle_anim_frequency"
@ -219,28 +220,7 @@
[button]
id = choose_theme
label = _ "Theme"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
id = orbs_setup
label = _ "Colors"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
id = disp_advanced
label = _ "Advanced"
tooltip = "Change the in-game theme"
[/button]
[/column]
[/row]
@ -255,7 +235,7 @@
[grid]
[row]
[column]
horizontal_alignment = "left"
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
@ -281,3 +261,4 @@
#undef _GUI_PREFERENCES_DISPLAY_GRID_1
#undef _GUI_PREFERENCES_DISPLAY_GRID_2
#undef _GUI_PREFERENCES_DISPLAY_GRID_2

View file

@ -28,9 +28,10 @@
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
horizontal_grow = true
[label]
definition = "default_small"
@ -39,6 +40,7 @@
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = true
@ -59,7 +61,7 @@
[/grid]
#enddef
#define _GUI_PREFERENCES_SOUND_GRID_1
#define _GUI_PREFERENCES_SOUND_GRID
[row]
[column]
horizontal_grow = true
@ -103,21 +105,6 @@
[/row]
#enddef
#define _GUI_PREFERENCES_SOUND_GRID_2
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
id = sound_advanced
label = _ "Advanced"
[/button]
[/column]
[/row]
#enddef
[layer]
[row]
[column]
@ -127,22 +114,11 @@
[grid]
[row]
[column]
horizontal_alignment = "left"
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
{_GUI_PREFERENCES_SOUND_GRID_1}
[/grid]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "left"
vertical_alignment = "bottom"
[grid]
{_GUI_PREFERENCES_SOUND_GRID_2}
{_GUI_PREFERENCES_SOUND_GRID}
[/grid]
[/column]
[/row]
@ -151,6 +127,5 @@
[/row]
[/layer]
#undef _GUI_PREFERENCES_SOUND_GRID_1
#undef _GUI_PREFERENCES_SOUND_GRID_2
#undef _GUI_PREFERENCES_SOUND_GRID
#undef _GUI_SOUND_SLIDER_CONTROL

View file

@ -3,7 +3,7 @@
### Preferences dialog, Multiplayer page
###
#define _GUI_PREFERENCES_MP_GRID_1
#define _GUI_PREFERENCES_MP_PAGE_1_GRID_1
[row]
[column]
horizontal_grow = true
@ -11,9 +11,10 @@
[grid]
[row]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
horizontal_grow = true
[label]
label = _ "Chat lines:"
@ -21,6 +22,7 @@
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = true
@ -31,6 +33,7 @@
minimum_value = 1
maximum_value = 20
step_size = 1
tooltip = "Set the number of chat lines shown"
[/slider]
[/column]
[/row]
@ -47,6 +50,7 @@
[toggle_button]
id = "chat_timestamps"
label = _ "Chat timestamping"
tooltip = "Add a timestamp to chat messages"
[/toggle_button]
[/column]
[/row]
@ -62,6 +66,7 @@
[toggle_button]
id = "remember_password"
label = _ "Save password to preferences (plain text)"
tooltip = "Uncheck to delete the saved password (on exit)"
[/toggle_button]
[/column]
[/row]
@ -144,76 +149,451 @@
[/row]
#enddef
#define _GUI_PREFERENCES_MP_GRID_2
#define _GUI_PREFERENCES_MP_PAGE_1_GRID_2
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
id = mp_friends
label = _ "Friends List"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
id = mp_alerts
label = _ "Alerts"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
vertical_alignment = "bottom"
[button]
id = mp_wesnothd
label = _ "Set Path to wesnothd"
label = _ "Server Executable"
tooltip = "Find and set path to MP server to host LAN games"
[/button]
[/column]
[/row]
#enddef
[layer]
#define _GUI_LOBBY_SOUNDS_ENTRY ID LABEL TOOLTIP
[row]
[column]
horizontal_grow = true
vertical_grow = true
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "gold_small"
id = {ID} + "_label"
label = {LABEL}
tooltip = {TOOLTIP}
[/label]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[toggle_button]
id = {ID} + "_sound"
definition = "default"
label = ""
[/toggle_button]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[toggle_button]
id = {ID} + "_notif"
definition = "default"
label = ""
tooltip = ""
[/toggle_button]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[toggle_button]
id = {ID} + "_lobby"
definition = "default"
label = ""
tooltip = ""
[/toggle_button]
[/column]
[/row]
#enddef
#define _GUI_PREFERENCES_MP_PAGE_2
[row]
grow_factor = 1
[column]
horizontal_grow = "true"
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
{_GUI_PREFERENCES_MP_GRID_1}
[/grid]
[text_box]
id = "friend_name_box"
definition = "default"
[/text_box]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "left"
vertical_alignment = "bottom"
horizontal_alignment = "right"
[grid]
{_GUI_PREFERENCES_MP_GRID_2}
[row]
grow_factor = 1
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "add_friend"
label = _ "Add as friend"
tooltip = _ "Add this username to your friends list (add optional notes, e.g., 'player_name notes on friend')"
[/button]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "add_ignored"
label = _ "Add as ignored"
tooltip = _ "Add this username to your ignore list (add optional reason, e.g., 'player_name reason ignored')"
[/button]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "remove"
label = _ "Remove"
tooltip = _ "Remove this username from your list"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
horizontal_grow = "true"
[listbox]
id = "friends_list"
definition = "default"
[list_definition]
[row]
[column]
vertical_grow = "true"
horizontal_grow = "true"
[toggle_panel]
definition = "default"
[grid]
[row]
[column]
grow_factor = 0
horizontal_alignment = "left"
border = "all"
border_size = 5
[image]
id = "friend_icon"
definition = "default"
[/image]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "friend_name"
definition = "default"
linked_group = "friends"
[/label]
[/column]
[column]
grow_factor = 1
horizontal_alignment = "right"
border = "all"
border_size = 5
[label]
id = "friend_status"
definition = "default"
[/label]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
[/grid]
[/column]
[/row]
#enddef
#define _GUI_PREFERENCES_MP_PAGE_3
[row]
grow_factor = 1
[column]
horizontal_grow = "true"
vertical_grow = "true"
[grid]
[row]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Event:"
[/label]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Play Sound:"
tooltip = _ "Play a sound for the event, specified in data/game_config.cfg"
[/label]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "notification_label"
definition = "default"
label = _ "Desktop
Notification:"
tooltip = _ "Shows desktop/system tray notifications for turn change events or conversations when the game window is inactive"
[/label]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Also in
lobby:"
tooltip = _ "Also take these actions in response to events in the main multiplayer lobby"
[/label]
[/column]
[/row]
{_GUI_LOBBY_SOUNDS_ENTRY "player_joins" ( _ "Player joins:") ( _ "When a player joins the lobby or game")}
{_GUI_LOBBY_SOUNDS_ENTRY "player_leaves" ( _ "Player leaves:") ( _ "When a player leaves the lobby or game")}
{_GUI_LOBBY_SOUNDS_ENTRY "private_message" ( _ "Private message:") ( _ "When a private message is received")}
{_GUI_LOBBY_SOUNDS_ENTRY "friend_message" ( _ "Friend message:") ( _ "When a message from a friend is received")}
{_GUI_LOBBY_SOUNDS_ENTRY "public_message" ( _ "Public message:") ( _ "When a public message is received")}
{_GUI_LOBBY_SOUNDS_ENTRY "server_message" ( _ "Server message:") ( _ "When a server message is received")}
{_GUI_LOBBY_SOUNDS_ENTRY "ready_for_start" ( _ "Ready to start game:") ( _ "When the game you are hosting is ready to start")}
{_GUI_LOBBY_SOUNDS_ENTRY "game_has_begun" ( _ "Game has begun:") ( _ "When the host (not you) has started the game")}
{_GUI_LOBBY_SOUNDS_ENTRY "turn_changed" ( _ "Turn changed:") ( _ "When a new turn has begun")}
[/grid]
[/column]
[/row]
[row]
grow_factor = 1
[column]
horizontal_grow="true"
[grid]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
id = "revert_to_defaults"
definition = "default"
label = _ "Defaults"
tooltip = _"Reset all options to their default values"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
#enddef
#define _GUI_PREFERENCES_MP_SWITCH_ROW
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[horizontal_listbox]
id = "mp_tab"
[list_definition]
[row]
[column]
{_GUI_TAB_BAR}
[/column]
[/row]
[/list_definition]
[/horizontal_listbox]
[/column]
[/row]
#enddef
[layer]
[row]
grow_factor = 1
[column]
horizontal_grow = true
vertical_grow = true
[stacked_widget]
id = "mp_tab_pager"
definition = "default"
[stack]
[layer]
[row]
[column]
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
{_GUI_PREFERENCES_MP_PAGE_1_GRID_1}
[/grid]
[/column]
[/row]
[row]
[column]
horizontal_grow = "true"
vertical_alignment = "bottom"
[grid]
{_GUI_PREFERENCES_MP_PAGE_1_GRID_2}
[/grid]
[/column]
[/row]
[/layer]
[layer]
[row]
[column]
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
{_GUI_PREFERENCES_MP_PAGE_2}
[/grid]
[/column]
[/row]
[/layer]
[layer]
[row]
[column]
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
{_GUI_PREFERENCES_MP_PAGE_3}
[/grid]
[/column]
[/row]
[/layer]
[/stack]
[/stacked_widget]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "left"
vertical_alignment = "bottom"
[grid]
{_GUI_PREFERENCES_MP_SWITCH_ROW}
[/grid]
[/column]
[/row]
[/layer]
#undef _GUI_PREFERENCES_MP_GRID_1
#undef _GUI_PREFERENCES_MP_GRID_2
#undef _GUI_PREFERENCES_MP_PAGE_1_GRID_1
#undef _GUI_PREFERENCES_MP_PAGE_1_GRID_2
#undef _GUI_PREFERENCES_MP_PAGE_2
#undef _GUI_PREFERENCES_MP_PAGE_3
#undef _GUI_PREFERENCES_MP_SWITCH_ROW

View file

@ -3,13 +3,140 @@
### Preferences dialog, Advanced page
###
[layer]
#define _GUI_ADVANCED_GRID
[row]
[column]
grow_factor = 0
horizontal_grow = "true"
vertical_grow = "true"
border = "all"
border_size = 5
[spacer][/spacer]
[tree_view]
id = "advanced_prefs"
definition = "default"
horizontal_scrollbar_mode = "never"
#vertical_scrollbar_mode = "initial_auto"
indention_step_size = 40
[node]
id = "pref_main"
[node_definition]
[row]
[column]
horizontal_grow = "true"
[toggle_panel]
id = "tree_view_node_icon"
[grid]
id = "pref_main_grid"
[row]
[column]
grow_factor = 0
border = "left,top,bottom"
border_size = 5
horizontal_alignment = "left"
[toggle_button]
id = "value_toggle"
definition = "default"
[/toggle_button]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "tree_view_node_label"
definition = "gold_small"
[/label]
[/column]
[column]
grow_factor = 0
horizontal_alignment = "right"
border = "all"
border_size = 5
# TODO: fix scroll labels in tree views
#[scroll_label]
# id = "value"
# definition = "default"
# horizontal_scrollbar_mode = "never"
# vertical_scrollbar_mode = "never"
#[/scroll_label]
[label]
id = "value"
definition = "default"
[/label]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "pref_details"
[node_definition]
[row]
[column]
horizontal_alignment = "left"
[grid]
id = "pref_setter_grid"
[row]
grow_factor = 1
[column]
grow_factor = 1
border = "top,right,bottom"
border_size = 10
horizontal_grow = "true"
[toggle_button]
id = "setter"
definition = "default"
[/toggle_button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/node_definition]
[/node]
[/tree_view]
[/column]
[/row]
#enddef
[layer]
[row]
[column]
horizontal_grow = true
vertical_grow = true
[grid]
[row]
[column]
horizontal_grow = "true"
vertical_alignment = "top"
[grid]
{_GUI_ADVANCED_GRID}
[/grid]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/layer]
#undef _GUI_ADVANCED_GRID

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 B

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 B

After

Width:  |  Height:  |  Size: 216 B

View file

@ -1687,8 +1687,8 @@ void preferences_dialog::set_selection(int index)
void show_preferences_dialog(CVideo& video, const config& game_cfg)
{
if(true/*gui2::new_widgets*/) {
gui2::tpreferences dlg;
dlg.show(disp.video());
gui2::tpreferences dlg(video, game_cfg);
dlg.show(video);
return;
}
@ -1790,7 +1790,7 @@ std::string show_wesnothd_server_search(CVideo& video)
symbols["filename"] = filename;
const std::string title = utils::interpolate_variables_into_string(
_("Find $filename server binary to host networked games")
_("Find $filename server binary")
, &symbols);
int res = dialogs::show_file_chooser_dialog(video, path, title, false, filename);

View file

@ -16,34 +16,755 @@
#include "gui/dialogs/preferences_dialog.hpp"
#include "game_preferences.hpp"
#include "preferences.hpp"
#include "preferences_display.hpp"
#include "lobby_preferences.hpp"
#include "gettext.hpp"
#include "formatter.hpp"
#include "gui/dialogs/helper.hpp"
#include "video.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/dialogs/advanced_graphics_options.hpp"
#include "gui/dialogs/game_cache_options.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/dialogs/mp_alerts_options.hpp"
#include "gui/dialogs/simple_item_selector.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/combobox.hpp"
#include "gui/widgets/grid.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/label.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
#include "gui/widgets/list.hpp"
#else
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/slider.hpp"
#include "gui/widgets/stacked_widget.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/tree_view.hpp"
#include "gui/widgets/tree_view_node.hpp"
#include "gui/widgets/window.hpp"
#include "util.hpp"
#include "utils/foreach.tpp"
#include "gettext.hpp"
#include <sstream>
#include <boost/bind.hpp>
#include <boost/math/common_factor_rt.hpp>
namespace {
//const unsigned int num_pages = 5;
struct advanced_preferences_sorter
{
bool operator()(const config& lhs, const config& rhs) const
{
return lhs["name"].t_str().str() < rhs["name"].t_str().str();
}
};
const std::string bool_to_display_string(bool value)
{
return value ? _("yes") : _("no");
}
} // end anon namespace
namespace gui2 {
// TODO: probably should use a namespace alias instead
using namespace preferences;
REGISTER_DIALOG(preferences)
tpreferences::tpreferences()
tpreferences::tpreferences(CVideo& video, const config& game_cfg)
: resolutions_(video.get_available_resolutions(true))
, adv_preferences_cfg_()
, friend_names_()
, last_selected_node_(NULL)
, accl_speeds_()
{
BOOST_FOREACH(const config& adv, game_cfg.child_range("advanced_preference")) {
adv_preferences_cfg_.push_back(adv);
}
std::sort(adv_preferences_cfg_.begin(), adv_preferences_cfg_.end(),
advanced_preferences_sorter());
// IMPORTANT: NEVER have trailing zeroes here, or else the cast from doubles
// to string will not match, since lexical_cast strips trailing zeroes.
static const char* const speeds[] = {
"0.25", "0.5", "0.75", "1", "1.25", "1.5", "1.75", "2", "3", "4", "8", "16" };
const size_t num_items = sizeof(speeds)/sizeof(const char*);
accl_speeds_.insert(accl_speeds_.end(), speeds, &speeds[num_items]);
}
// Determine the template type in order to use the correct value getter
static std::string disambiguate_widget_value(const ttoggle_button& parent_widget)
{
return bool_to_display_string(parent_widget.get_value_bool());
}
static std::string disambiguate_widget_value(const tcombobox& parent_widget)
{
return parent_widget.get_value_string();
}
static std::string disambiguate_widget_value(const tslider& parent_widget)
{
return parent_widget.get_value_label();
}
// Helper function to refresh resolution list
static void set_resolution_list(tcombobox& res_list, CVideo& video)
{
const std::vector<std::pair<int,int> > resolutions = video.get_available_resolutions(true);
std::vector<std::string> options;
FOREACH(const AUTO& res, resolutions)
{
std::ostringstream option;
option << res.first << utils::unicode_multiplication_sign << res.second;
const int div = boost::math::gcd(res.first, res.second);
const int ratio[2] = {res.first/div, res.second/div};
if (ratio[0] <= 10 || ratio[1] <= 10) {
option << " <span color='#777777'>("
<< ratio[0] << ':' << ratio[1] << ")</span>";
}
options.push_back(option.str());
}
const unsigned current_res = std::find(resolutions.begin(), resolutions.end(),
video.current_resolution()) - resolutions.begin();
res_list.set_values(options, current_res);
}
void tpreferences::setup_single_toggle(
const std::string& widget_id,
const bool start_value,
boost::function<void(bool)> callback,
twidget& find_in)
{
ttoggle_button& widget =
find_widget<ttoggle_button>(&find_in, widget_id, false);
widget.set_value(start_value);
connect_signal_mouse_left_click(widget, boost::bind(
&tpreferences::single_toggle_callback,
this, boost::ref(widget), callback));
}
void tpreferences::setup_toggle_slider_pair(
const std::string& toggle_widget,
const std::string& slider_widget,
const bool toggle_start_value,
const int slider_state_value,
boost::function<void(bool)> toggle_callback,
boost::function<void(int)> slider_callback,
twidget& find_in)
{
ttoggle_button& button =
find_widget<ttoggle_button>(&find_in, toggle_widget, false);
tslider& slider =
find_widget<tslider>(&find_in, slider_widget, false);
button.set_value(toggle_start_value);
slider.set_value(slider_state_value);
slider.set_active(toggle_start_value);
connect_signal_mouse_left_click(button, boost::bind(
&tpreferences::toggle_slider_pair_callback,
this, boost::ref(button), boost::ref(slider),
toggle_callback));
connect_signal_notify_modified(slider, boost::bind(
&tpreferences::single_slider_callback,
this, boost::ref(slider),
slider_callback));
}
void tpreferences::setup_single_slider(
const std::string& widget_id,
const int start_value,
boost::function<void(int)> slider_callback,
twidget& find_in)
{
tslider& widget = find_widget<tslider>(&find_in, widget_id, false);
widget.set_value(start_value);
connect_signal_notify_modified(widget, boost::bind(
&tpreferences::single_slider_callback,
this, boost::ref(widget),
slider_callback));
}
void tpreferences::setup_combobox(
const std::string& widget_id,
const combo_data& options,
const unsigned start_value,
boost::function<void(std::string)> callback,
twidget& find_in)
{
tcombobox& widget =
find_widget<tcombobox>(&find_in, widget_id, false);
widget.set_use_markup(true);
widget.set_values(options.first, start_value);
connect_signal_mouse_left_click(widget, boost::bind(
&tpreferences::simple_combobox_callback,
this, boost::ref(widget),
callback, options.second));
}
void tpreferences::setup_radio_toggle(
const std::string& toggle_id,
LOBBY_JOINS enum_value,
int start_value,
std::vector<std::pair<ttoggle_button*, int> >& vec,
twindow& window)
{
ttoggle_button& button = find_widget<ttoggle_button>(&window, toggle_id, false);
button.set_value(enum_value == start_value);
connect_signal_mouse_left_click(button, boost::bind(
&tpreferences::toggle_radio_callback,
this, boost::ref(vec), boost::ref(start_value), &button));
vec.push_back(std::make_pair(&button, enum_value));
}
template <typename T>
void tpreferences::bind_status_label(T& parent, const std::string& label_id,
twidget& find_in)
{
tcontrol& label = find_widget<tcontrol>(&find_in, label_id, false);
label.set_label(disambiguate_widget_value(parent));
parent.set_callback_state_change(boost::bind(
&tpreferences::status_label_callback<T>,
this, boost::ref(parent), boost::ref(label)));
}
void tpreferences::bind_status_label(tslider& parent, const std::string& label_id,
twidget& find_in)
{
tcontrol& label = find_widget<tcontrol>(&find_in, label_id, false);
label.set_label(lexical_cast<std::string>(parent.get_value_label()));
connect_signal_notify_modified(parent, boost::bind(
&tpreferences::status_label_callback<tslider>,
this, boost::ref(parent), boost::ref(label)));
}
void tpreferences::setup_friends_list(twindow& window)
{
tlistbox& friends_list = find_widget<tlistbox>(&window, "friends_list", false);
const std::map<std::string, preferences::acquaintance>& acquaintances = get_acquaintances();
std::map<std::string, string_map> data;
find_widget<tbutton>(&window, "remove", false).set_active(!acquaintances.empty());
if (acquaintances.empty()) {
data["friend_icon"]["label"] = "misc/status-neutral.png";
data["friend_name"]["label"] = _("Empty list");
friends_list.add_row(data);
return;
}
friends_list.clear();
friend_names_.clear();
FOREACH(const AUTO& acquaintence, acquaintances)
{
std::string image = "friend.png";
std::string descriptor = _("friend");
std::string notes;
if(acquaintence.second.get_status() == "ignore") {
image = "ignore.png";
descriptor = _("ignored");
}
if(!acquaintence.second.get_notes().empty()) {
notes = " <small>(" + acquaintence.second.get_notes() + ")</small>";
}
data["friend_icon"]["label"] = "misc/status-" + image;
data["friend_name"]["label"] = acquaintence.second.get_nick() + notes;
data["friend_name"]["use_markup"] = "true";
data["friend_status"]["label"] = "<small>" + descriptor + "</small>";
data["friend_status"]["use_markup"] = "true";
friends_list.add_row(data);
friend_names_.push_back(acquaintence.first);
}
}
void tpreferences::add_friend_list_entry(const bool is_friend,
ttext_box& textbox, twindow& window)
{
std::string reason;
std::string username = textbox.text();
size_t pos = username.find_first_of(' ');
if (pos != std::string::npos) {
reason = username.substr(pos + 1);
username = username.substr(0, pos);
}
const bool added_sucessfully = is_friend ?
add_friend(username, reason) :
add_ignore(username, reason) ;
if (!added_sucessfully) {
gui2::show_transient_error_message(window.video(), _("Invalid username"));
return;
}
textbox.clear();
setup_friends_list(window);
}
void tpreferences::remove_friend_list_entry(tlistbox& friends_list,
ttext_box& textbox, twindow& window)
{
std::string to_remove = textbox.text();
if (to_remove.empty()) {
const int selected_row = std::max(0, friends_list.get_selected_row());
to_remove = friend_names_[selected_row];
}
remove_acquaintance(to_remove);
textbox.clear();
setup_friends_list(window);
}
/**
* Sets up states and callbacks for each of the widgets
*/
void tpreferences::initialize_members(twindow& window)
{
//
// GENERAL PANEL
//
/** SCROLL SPEED **/
setup_single_slider("scroll_speed",
scroll_speed(), set_scroll_speed, window);
/** ACCELERATED SPEED **/
ttoggle_button& accl_toggle =
find_widget<ttoggle_button>(&window, "turbo_toggle", false);
tslider& accl_slider =
find_widget<tslider>(&window, "turbo_slider", false);
const int selected_speed = std::find(
(accl_speeds_.begin()), accl_speeds_.end(), lexical_cast<std::string>(turbo_speed()))
- (accl_speeds_.begin());
accl_slider.set_value_labels(accl_speeds_);
const bool is_turbo = turbo();
accl_toggle.set_value(is_turbo);
accl_slider.set_value(selected_speed + 1);
accl_slider.set_active(is_turbo);
connect_signal_mouse_left_click(accl_toggle, boost::bind(
&tpreferences::toggle_slider_pair_callback,
this, boost::ref(accl_toggle), boost::ref(accl_slider),
set_turbo));
connect_signal_notify_modified(accl_slider, boost::bind(
&tpreferences::accl_speed_slider_callback,
this,
boost::ref(accl_slider)));
bind_status_label(accl_slider, "turbo_value", window);
/** SKIP AI MOVES **/
setup_single_toggle("skip_ai_moves",
show_ai_moves(), set_show_ai_moves, window);
/** DISABLE AUTO MOVES **/
setup_single_toggle("disable_auto_moves",
disable_auto_moves(), set_disable_auto_moves, window);
/** TURN DIALOG **/
setup_single_toggle("show_turn_dialog",
turn_dialog(), set_turn_dialog, window);
/** ENABLE PLANNING MODE **/
setup_single_toggle("whiteboard_on_start",
enable_whiteboard_mode_on_start(), set_enable_whiteboard_mode_on_start, window);
/** HIDE ALLY PLANS **/
setup_single_toggle("whiteboard_hide_allies",
hide_whiteboard(), set_hide_whiteboard, window);
/** INTERRUPT ON SIGHTING **/
setup_single_toggle("interrupt_move_when_ally_sighted",
interrupt_when_ally_sighted(), set_interrupt_when_ally_sighted, window);
/** SAVE REPLAYS **/
setup_single_toggle("save_replays",
save_replays(), set_save_replays, window);
/** DELETE AUTOSAVES **/
setup_single_toggle("delete_saves",
delete_saves(), set_delete_saves, window);
/** MAX AUTO SAVES **/
setup_single_slider("max_saves_slider",
autosavemax(), set_autosavemax, window);
bind_status_label(find_widget<tslider>(&window, "max_saves_slider", false),
"max_saves_value", window);
/** SET HOTKEYS **/
connect_signal_mouse_left_click(find_widget<tbutton>(&window, "hotkeys", false),
boost::bind(&preferences::show_hotkeys_preferences_dialog,
boost::ref(window.video())));
/** CACHE MANAGE **/
connect_signal_mouse_left_click(find_widget<tbutton>(&window, "cachemg", false),
boost::bind(&gui2::tgame_cache_options::display,
boost::ref(window.video())));
//
// DISPLAY PANEL
//
/** FULLSCREEN TOGGLE **/
ttoggle_button& toggle_fullscreen =
find_widget<ttoggle_button>(&window, "fullscreen", false);
toggle_fullscreen.set_value(fullscreen());
// We bind a special callback function, so setup_single_toggle() is not used
connect_signal_mouse_left_click(toggle_fullscreen, boost::bind(
&tpreferences::fullscreen_toggle_callback,
this, boost::ref(window)));
/** SET RESOLUTION **/
tcombobox& res_list = find_widget<tcombobox>(&window, "resolution_set", false);
res_list.set_use_markup(true);
res_list.set_active(!fullscreen());
set_resolution_list(res_list, window.video());
res_list.connect_click_handler(
boost::bind(&tpreferences::handle_res_select,
this, boost::ref(window)));
/** SHOW FLOATING LABELS **/
setup_single_toggle("show_floating_labels",
show_floating_labels(), set_show_floating_labels, window);
/** SHOW HALOES **/
setup_single_toggle("show_halos",
show_haloes(), set_show_haloes, window);
/** SHOW TEAM COLORS **/
setup_single_toggle("show_ellipses",
show_side_colors(), set_show_side_colors, window);
/** SHOW GRID **/
setup_single_toggle("show_grid",
grid(), set_grid, window);
/** ANIMATE MAP **/
setup_single_toggle("animate_terrains",
show_haloes(), set_show_haloes, window);
/** SHOW UNIT STANDING ANIMS **/
setup_single_toggle("animate_units_standing",
show_standing_animations(), set_show_standing_animations, window);
/** SHOW UNIT IDLE ANIMS **/
setup_toggle_slider_pair("animate_units_idle", "idle_anim_frequency",
idle_anim(), idle_anim_rate(),
set_idle_anim, set_idle_anim_rate, window);
/** SELECT THEME **/
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "choose_theme", false),
boost::bind(&preferences::show_theme_dialog,
boost::ref(window.video())));
//
// SOUND PANEL
//
/** SOUND FX **/
setup_toggle_slider_pair("sound_toggle_sfx", "sound_volume_sfx",
sound_on(), sound_volume(),
set_sound, set_sound_volume, window);
/** MUSIC **/
setup_toggle_slider_pair("sound_toggle_music", "sound_volume_music",
music_on(), music_volume(),
set_music, set_music_volume, window);
/** TURN BELL **/
setup_toggle_slider_pair("sound_toggle_bell", "sound_volume_bell",
turn_bell(), bell_volume(),
set_turn_bell, set_bell_volume, window);
/** UI FX **/
setup_toggle_slider_pair("sound_toggle_uisfx", "sound_volume_uisfx",
UI_sound_on(), UI_volume(),
set_UI_sound, set_UI_volume, window);
//
// MULTIPLAYER PANEL
//
/** CHAT LINES **/
setup_single_slider("chat_lines",
chat_lines(), set_chat_lines, window);
/** CHAT TIMESTAMPPING **/
setup_single_toggle("chat_timestamps",
chat_timestamping(), set_chat_timestamping, window);
/** SAVE PASSWORD **/
setup_single_toggle("remember_password",
remember_password(), set_remember_password, window);
/** SORT LOBBY LIST **/
setup_single_toggle("lobby_sort_players",
sort_list(), _set_sort_list, window);
/** ICONIZE LOBBY LIST **/
setup_single_toggle("lobby_player_icons",
iconize_list(), _set_iconize_list, window);
/** LOBBY JOIN NOTIFICATIONS **/
setup_radio_toggle("lobby_joins_none", SHOW_NONE,
lobby_joins(), lobby_joins_, window);
setup_radio_toggle("lobby_joins_friends", SHOW_FRIENDS,
lobby_joins(), lobby_joins_, window);
setup_radio_toggle("lobby_joins_all", SHOW_ALL,
lobby_joins(), lobby_joins_, window);
/** FRIENDS LIST **/
setup_friends_list(window);
ttext_box& textbox = find_widget<ttext_box>(&window, "friend_name_box", false);
tlistbox& friend_list = find_widget<tlistbox>(&window, "friends_list", false);
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "add_friend", false), boost::bind(
&tpreferences::add_friend_list_entry,
this, true,
boost::ref(textbox),
boost::ref(window)));
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "add_ignored", false), boost::bind(
&tpreferences::add_friend_list_entry,
this, false,
boost::ref(textbox),
boost::ref(window)));
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "remove", false), boost::bind(
&tpreferences::remove_friend_list_entry,
this,
boost::ref(friend_list),
boost::ref(textbox),
boost::ref(window)));
friend_list.select_row(0);
/** ALERTS **/
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "mp_alerts", false),
boost::bind(&gui2::tmp_alerts_options::display,
boost::ref(window.video())));
/** SET WESNOTHD PATH **/
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "mp_wesnothd", false), boost::bind(
&preferences::show_wesnothd_server_search,
boost::ref(window.video())));
//
// ADVANCED PANEL
//
ttree_view& advanced = find_widget<ttree_view>(&window, "advanced_prefs", false);
typedef std::map<std::string, string_map> node_content;
node_content tree_group_item;
BOOST_FOREACH(const config& option, adv_preferences_cfg_)
{
// Details about the current option
const ADVANCED_PREF_TYPE& pref_type = ADVANCED_PREF_TYPE::string_to_enum(
option["type"].str());
const std::string& pref_name = option["field"].str();
tree_group_item["tree_view_node_label"]["label"] = option["name"];
ttree_view_node& pref_node = advanced.add_node("pref_main", tree_group_item);
ttree_view_node& detail_node = pref_node.add_child("pref_details", node_content());
// Get the main grids from each node
tgrid* main_grid = dynamic_cast<tgrid*>(pref_node.find("pref_main_grid", true));
VALIDATE(main_grid, missing_widget("pref_main_grid"));
tgrid* details_grid = dynamic_cast<tgrid*>(detail_node.find("pref_setter_grid", true));
VALIDATE(details_grid, missing_widget("pref_setter_grid"));
// The toggle widget for toggle-type options (hidden for other types)
ttoggle_button& toggle_box = find_widget<ttoggle_button>(main_grid, "value_toggle", false);
toggle_box.set_visible(tcontrol::tvisible::hidden);
switch (pref_type.v) {
case ADVANCED_PREF_TYPE::TOGGLE: {
pref_node.clear();
toggle_box.set_visible(tcontrol::tvisible::visible);
// Needed to disambiguate overloaded function
typedef void (*setter) (const std::string &, bool);
setter set_ptr = &preferences::set;
setup_single_toggle("value_toggle",
get(pref_name, option["default"].to_bool()),
boost::bind(set_ptr, pref_name, _1),
*main_grid);
bind_status_label(toggle_box, "value", *main_grid);
break;
}
case ADVANCED_PREF_TYPE::SLIDER: {
tslider* setter_widget = new tslider;
setter_widget->set_definition("minimal");
setter_widget->set_id("control_slider");
// Maximum must be set first or this will assert
setter_widget->set_maximum_value(option["max"].to_int());
setter_widget->set_minimum_value(option["min"].to_int());
setter_widget->set_step_size(
option["step"].empty() ? 1 : option["step"].to_int());
delete details_grid->swap_child("setter", setter_widget, true);
// Needed to disambiguate overloaded function
typedef void (*setter) (const std::string &, int);
setter set_ptr = &preferences::set;
setup_single_slider("control_slider",
lexical_cast_default<int>(get(pref_name), option["default"].to_int()),
boost::bind(set_ptr, pref_name, _1),
*details_grid);
bind_status_label(*setter_widget, "value", *main_grid);
break;
}
case ADVANCED_PREF_TYPE::COMBO: {
combo_data combo_options;
BOOST_FOREACH(const config& choice, option.child_range("option"))
{
combo_options.first.push_back(choice["name"]);
combo_options.second.push_back(choice["id"]);
}
const unsigned selected = std::find(
combo_options.second.begin(), combo_options.second.end(),
get(pref_name, option["default"].str())) - combo_options.second.begin();
tcombobox* setter_widget = new tcombobox;
setter_widget->set_definition("default");
setter_widget->set_id("control_combobox");
delete details_grid->swap_child("setter", setter_widget, true);
// Needed to disambiguate overloaded function
typedef void (*setter) (const std::string &, const std::string &);
setter set_ptr = &preferences::set;
setup_combobox("control_combobox",
combo_options, selected,
boost::bind(set_ptr, pref_name, _1),
*details_grid);
bind_status_label(*setter_widget, "value", *main_grid);
break;
}
case ADVANCED_PREF_TYPE::SPECIAL: {
pref_node.clear();
timage* value_widget = new timage;
value_widget->set_definition("default");
value_widget->set_label("icons/arrows/short_arrow_right_25.png");
delete main_grid->swap_child("value", value_widget, true);
if (pref_name == "advanced_graphic_options") {
pref_node.set_callback_state_change(2,
boost::bind(show_advanced_graphics_dialog,
boost::ref(window.video())));
}
if (pref_name == "orb_color") {
// TODO
}
// Add more options here as needed
break;
}
}
}
connect_signal_mouse_left_click(advanced, boost::bind(
&tpreferences::on_node_select, this, boost::ref(advanced)));
last_selected_node_ = advanced.selected_item();
}
void tpreferences::on_node_select(ttree_view& tree)
{
ttree_view_node* last_item = tree.selected_item();
if(last_selected_node_ != last_item) {
last_selected_node_->fold();
last_selected_node_ = last_item;
}
}
void tpreferences::add_pager_row(tlistbox& selector, const std::string& icon, const std::string& label)
@ -54,6 +775,25 @@ void tpreferences::add_pager_row(tlistbox& selector, const std::string& icon, co
selector.add_row(data);
}
void tpreferences::add_tab(tlistbox& tab_bar, const std::string& label)
{
std::map<std::string, string_map> data;
data["tab_label"]["label"] = label;
tab_bar.add_row(data);
}
void tpreferences::initialize_tabs(twindow& window)
{
/** MULTIPLAYER TABS **/
tlistbox& tabs_multiplayer = find_widget<tlistbox>(&window, "mp_tab", false);
add_tab(tabs_multiplayer, _("Prefs tab^General"));
add_tab(tabs_multiplayer, _("Prefs tab^Friends"));
add_tab(tabs_multiplayer, _("Prefs tab^Alerts"));
tabs_multiplayer.set_callback_value_change(make_dialog_callback(
boost::bind(&tpreferences::on_tab_select, this, _1, "mp_tab")));
}
void tpreferences::pre_show(CVideo& /*video*/, twindow& window)
{
tlistbox& selector = find_widget<tlistbox>(&window, "selector", false);
@ -61,13 +801,12 @@ void tpreferences::pre_show(CVideo& /*video*/, twindow& window)
#ifdef GUI2_EXPERIMENTAL_LISTBOX
connect_signal_notify_modified(selector, boost::bind(
&tpreferences::on_page_select
, this
, boost::ref(window)));
&tpreferences::on_page_select,
this,
boost::ref(window)));
#else
selector.set_callback_value_change(dialog_callback
<tpreferences
, &tpreferences::on_page_select>);
<tpreferences, &tpreferences::on_page_select>);
#endif
window.keyboard_capture(&selector);
@ -75,46 +814,132 @@ void tpreferences::pre_show(CVideo& /*video*/, twindow& window)
add_pager_row(selector, "display.png", _("Prefs section^Display"));
add_pager_row(selector, "music.png", _("Prefs section^Sound"));
add_pager_row(selector, "multiplayer.png", _("Prefs section^Multiplayer"));
add_pager_row(selector, "advanced.png", _("Advanced section^Advanced"));
add_pager_row(selector, "advanced.png", _("Prefs section^Advanced"));
//
// We need to establish callbacks before selecting the initial page,
// otherwise widgets from other pages cannot be found afterwards.
//
#if 0
tbutton& test_button = find_widget<tbutton>(&window, "button1", false);
// Initializes tabs for the various pages. This should be done before
// setting up the member callbacks.
initialize_tabs(window);
// Initializes initial values and sets up callbacks. This needs to be
// done before selecting the initial page, otherwise widgets from other
// pages cannot be found afterwards.
initialize_members(window);
connect_signal_mouse_left_click(
test_button,
boost::bind(&tpreferences::button_test_callback,
this));
#endif
assert(selector.get_item_count() == pager.get_layer_count());
// Selects initial tab for each page and the initially displayed main
// page. This should be done last after all intilization
set_visible_page(window, 0, "mp_tab_pager");
selector.select_row(0);
pager.select_layer(0);
}
void tpreferences::set_visible_page(twindow& window, unsigned int page)
void tpreferences::set_visible_page(twindow& window, unsigned int page, const std::string& pager_id)
{
tstacked_widget& pager = find_widget<tstacked_widget>(&window, "pager", false);
pager.select_layer(page);
find_widget<tstacked_widget>(&window, pager_id, false).select_layer(page);
}
void tpreferences::button_test_callback()
void tpreferences::single_toggle_callback(const ttoggle_button& widget,
boost::function<void(bool)> setter)
{
std::cerr << "hi from button1\n";
setter(widget.get_value_bool());
}
void tpreferences::toggle_slider_pair_callback(const ttoggle_button& toggle_widget,
tslider& slider_widget, boost::function<void(bool)> setter)
{
const bool ison = toggle_widget.get_value_bool();
setter(ison);
slider_widget.set_active(ison);
}
void tpreferences::single_slider_callback(const tslider& widget,
boost::function<void(int)> setter)
{
setter(widget.get_value());
}
void tpreferences::simple_combobox_callback(const tcombobox& widget,
boost::function<void(std::string)> setter, std::vector<std::string>& vec)
{
const unsigned index = widget.get_value();
setter(vec[index]);
}
template <typename T>
void tpreferences::status_label_callback(T& parent_widget,
tcontrol& label_widget)
{
label_widget.set_label(disambiguate_widget_value(parent_widget));
}
// Special fullsceen callback
void tpreferences::fullscreen_toggle_callback(twindow& window)
{
const bool ison =
find_widget<ttoggle_button>(&window, "fullscreen", false).get_value_bool();
window.video().set_fullscreen(ison);
tcombobox& res_list = find_widget<tcombobox>(&window, "resolution_set", false);
set_resolution_list(res_list, window.video());
res_list.set_active(!ison);
}
void tpreferences::handle_res_select(twindow& window)
{
tcombobox& res_list = find_widget<tcombobox>(&window, "resolution_set", false);
const int choice = res_list.get_value();
if (resolutions_[static_cast<size_t>(choice)] == window.video().current_resolution()) {
return;
}
window.video().set_resolution(resolutions_[static_cast<size_t>(choice)]);
set_resolution_list(res_list, window.video());
}
// Special Accelerated Speed slider callback
void tpreferences::accl_speed_slider_callback(tslider& slider)
{
const int index = slider.get_value();
set_turbo_speed(lexical_cast<double>(accl_speeds_[index - 1]));
}
void tpreferences::toggle_radio_callback(
const std::vector<std::pair<ttoggle_button*, int> >& vec,
int& value,
ttoggle_button* active)
{
FOREACH(const AUTO & e, vec)
{
ttoggle_button* const b = e.first;
if(b == NULL) {
continue;
} else if(b == active && !b->get_value()) {
b->set_value(true);
} else if(b == active) {
value = e.second;
_set_lobby_joins(value);
} else if(b != active && b->get_value()) {
b->set_value(false);
}
}
}
void tpreferences::on_page_select(twindow& window)
{
const int selected_row =
std::max(0, find_widget<tlistbox>(&window, "selector", false).get_selected_row());
set_visible_page(window, static_cast<unsigned int>(selected_row));
set_visible_page(window, static_cast<unsigned int>(selected_row), "pager");
}
void tpreferences::post_show(twindow& /*window*/)
void tpreferences::on_tab_select(twindow& window, const std::string& widget_id)
{
const int selected_row =
std::max(0, find_widget<tlistbox>(&window, widget_id, false).get_selected_row());
set_visible_page(window, static_cast<unsigned int>(selected_row), (widget_id + "_pager"));
}
} // end namespace gui2

View file

@ -15,6 +15,9 @@
#ifndef GUI_DIALOGS_PREFERENCES_DIALOG_HPP_INCLUDED
#define GUI_DIALOGS_PREFERENCES_DIALOG_HPP_INCLUDED
#include "config.hpp"
#include "game_preferences.hpp"
#include "make_enum.hpp"
#include "gui/dialogs/dialog.hpp"
// This file is not named preferences.hpp in order -I conflicts with
@ -23,24 +26,27 @@
namespace gui2
{
class tlistbox;
class tcombobox;
class tcontrol;
class tslider;
class ttext_box;
class ttoggle_button;
class ttree_view;
class ttree_view_node;
class tpreferences : public tdialog
{
public:
/**
* Constructor.
*/
tpreferences();
tpreferences(CVideo& video, const config& game_cfg);
/** The execute function -- see @ref tdialog for more information. */
//
// TODO: we want to get status info out in case it's necessary, e.g.
// to refresh the game display or stuff, hence this is execute() and
// not display(). But we probably should drop this later and force
// callers communicate with the dialog directly. Undecided. -- shadowm
//
static bool execute(CVideo& video)
/** The display function -- see @ref tdialog for more information. */
static bool display(CVideo& video, const config& game_cfg)
{
tpreferences().show(video);
tpreferences(video, game_cfg).show(video);
return true;
}
@ -51,16 +57,142 @@ private:
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
/** Initializers */
void initialize_members(twindow& window);
void initialize_tabs(twindow& window);
void setup_friends_list(twindow& window);
void add_pager_row(class tlistbox& selector, const std::string& icon, const std::string& label);
void set_visible_page(twindow& window, unsigned int page);
void add_friend_list_entry(const bool is_friend,
ttext_box& textbox, twindow& window);
/** Callback for page selection changes. */
void remove_friend_list_entry(tlistbox& friends_list,
ttext_box& textbox, twindow& window);
void add_tab(tlistbox& tab_bar, const std::string& label);
void add_pager_row(tlistbox& selector, const std::string& icon, const std::string& label);
void set_visible_page(twindow& window, unsigned int page, const std::string& pager_id);
/** Callback for selection changes */
void on_page_select(twindow& window);
void on_tab_select(twindow& window, const std::string& widget_id);
void on_node_select(ttree_view& tree);
void button_test_callback();
/** Special callback functions */
void handle_res_select(twindow& window);
void fullscreen_toggle_callback(twindow& window);
void accl_speed_slider_callback(tslider& slider);
/**
* Sets the initial state and callback for a simple bool-state toggle button
* In the callback, the bool value of the widget is passeed to the setter
*/
void setup_single_toggle(
const std::string& widget_id,
const bool start_value,
boost::function<void(bool)> callback,
twidget& find_in);
void single_toggle_callback(const ttoggle_button& widget,
boost::function<void(bool)> setter);
/**
* Sets the initial state and callback for a bool-state toggle button/slider
* pair. In the callback, the slider is set to active/inactive based on the
* button's value, which is also passed to the setter.
*/
void setup_toggle_slider_pair(
const std::string& toggle_widget,
const std::string& slider_widget,
const bool toggle_start_value,
const int slider_state_value,
boost::function<void(bool)> toggle_callback,
boost::function<void(int)> slider_callback,
twidget& find_in);
void toggle_slider_pair_callback(const ttoggle_button& toggle_widget,
tslider& slider_widget, boost::function<void(bool)> setter);
/**
* Sets the initial state and callback for a standalone slider
* In the callback, int value of the widget is passeed to the setter
*/
void setup_single_slider(
const std::string& widget_id,
const int start_value,
boost::function<void(int)> slider_callback,
twidget& find_in);
void single_slider_callback(const tslider& widget,
boost::function<void(int)> setter);
typedef std::pair<std::vector<std::string>, std::vector<std::string> > combo_data;
/**
* Sets the initial state and callback for a combobox
*/
void setup_combobox(
const std::string& widget_id,
const combo_data& options,
const unsigned start_value,
boost::function<void(std::string)> callback,
twidget& find_in);
void simple_combobox_callback(const tcombobox& widget,
boost::function<void(std::string)> setter, std::vector<std::string>& vec);
/**
* Sets the a radio button group
* Since (so far) there is only one group of these, the code is speciliazed.
* If (at a later date) more groups need to be added, this will have to be
* generalized.
*/
void setup_radio_toggle(
const std::string& toggle_id,
preferences::LOBBY_JOINS enum_value,
int start_value,
std::vector<std::pair<ttoggle_button*, int> >& vec,
twindow& window);
void toggle_radio_callback(
const std::vector<std::pair<ttoggle_button*, int> >& vec,
int& value,
ttoggle_button* active);
/**
* Sets up a label that always displays the value of another widget.
*/
template <typename T>
void bind_status_label(
T& parent,
const std::string& label_id,
twidget& find_in);
void bind_status_label(
tslider& parent,
const std::string& label_id,
twidget& find_in);
template <typename T>
void status_label_callback(T& parent_widget,
tcontrol& label_widget);
typedef std::pair<ttoggle_button*, int> lobby_radio_toggle;
std::vector<lobby_radio_toggle> lobby_joins_;
MAKE_ENUM(ADVANCED_PREF_TYPE,
(TOGGLE, "boolean")
(SLIDER, "int")
(COMBO, "combo")
(SPECIAL, "custom")
)
std::vector<std::pair<int,int> > resolutions_;
std::vector<config> adv_preferences_cfg_;
std::vector<std::string> friend_names_;
ttree_view_node* last_selected_node_;
std::vector<t_string> accl_speeds_;
};
} // namespace gui2

View file

@ -212,6 +212,10 @@ std::string get(const std::string& key) {
return prefs[key];
}
std::string get(const std::string& key, const std::string& def) {
return prefs[key].empty() ? def : prefs[key];
}
bool get(const std::string &key, bool def)
{
return prefs[key].to_bool(def);

View file

@ -49,6 +49,7 @@ namespace preferences {
void set_child(const std::string& key, const config& val);
const config &get_child(const std::string &key);
std::string get(const std::string& key);
std::string get(const std::string& key, const std::string& def);
bool get(const std::string &key, bool def);
void erase(const std::string& key);
bool have_setting(const std::string& key);

View file

@ -119,7 +119,8 @@ void set_idle_anim_rate(int rate) {
bool show_video_mode_dialog(CVideo& video)
{
const resize_lock prevent_resizing;
const events::event_context dialog_events_context;
// For some reason, this line prevents the dialog from being opened from GUI2...
//const events::event_context dialog_events_context;
std::vector<std::pair<int,int> > resolutions
= video.get_available_resolutions();

View file

@ -46,7 +46,6 @@ namespace preferences {
std::string show_wesnothd_server_search(CVideo&);
void show_preferences_dialog(CVideo& disp, const config& game_cfg);
bool show_video_mode_dialog(CVideo& disp);
bool show_theme_dialog(CVideo& disp);
void show_paths_dialog(CVideo& disp);
void show_mp_alerts_dialog(CVideo& disp);