diff --git a/help/topics.txt b/help/topics.txt index d2a1436..75556a2 100644 --- a/help/topics.txt +++ b/help/topics.txt @@ -208,6 +208,7 @@ Groups can hold other groups. Select a group (drag a box around it) along with a [demo]groups[/demo] # Colours and themes +- [b]View ▾ → Sound…[/b] (or the ☰ menu) sets how loud the theme's sounds are, with a slider from Off to Loud. - [b]View ▾ → Theme…[/b] picks a theme and lets you change its colours, the background and panel gradients, the background pattern, the card border and the logo. Changes to a built-in theme are saved as a theme of your own. - Give a card, a thread or a group its own colour from its right-click menu ([b]Colour[/b]) or in the inspector, to sort things at a glance. [b]Any colour…[/b] at the end of the menu opens a full colour picker. diff --git a/tests/test_theme.gd b/tests/test_theme.gd index 0dd9e0b..60b634d 100644 --- a/tests/test_theme.gd +++ b/tests/test_theme.gd @@ -74,6 +74,7 @@ func _test_dialog() -> void: main.add_child(d) await _frames() _check(d._content.find_children("*", "FillEditor", true, false).size() == 2, "background and panel fill editors") + _check(bool(d._work.get("builtin", false)) and not d._delete_button.visible, "a built-in theme doesn't offer Delete") var basic := d._content.find_children("*", "ColorPickerButton", true, false).size() d._more = true d._rebuild() diff --git a/tests/test_theme_assets.gd b/tests/test_theme_assets.gd index d05f923..82a73cb 100644 --- a/tests/test_theme_assets.gd +++ b/tests/test_theme_assets.gd @@ -105,3 +105,14 @@ func _test_sounds() -> void: _check(not playing, "nothing plays when the sound is off") main.sound.set_volume(SoundBoard.DEFAULT_VOLUME) _eq(main.sound.level_name(), "Quiet", "the default level is Quiet") + var panel := SoundPanel.open(main, Vector2(40, 40)) + var sliders := panel.find_children("*", "HSlider", true, false) + _check(sliders.size() == 1 and is_equal_approx((sliders[0] as HSlider).value, SoundBoard.DEFAULT_VOLUME * 100.0), "Sound… opens a slider at the current volume") + (sliders[0] as HSlider).value = 65 + _check(is_equal_approx(main.sound.volume, 0.65), "moving the slider changes the volume") + panel.hide() + main.sound.set_volume(SoundBoard.DEFAULT_VOLUME) + var view_items: Array[String] = [] + for i in main.top_bar.view_menu.get_popup().item_count: + view_items.append(main.top_bar.view_menu.get_popup().get_item_text(i)) + _check(view_items.has("Sound…"), "View ▾ has Sound…") diff --git a/ui/actions.gd b/ui/actions.gd index 6a68b00..70f2883 100644 --- a/ui/actions.gd +++ b/ui/actions.gd @@ -187,11 +187,8 @@ static func background(m: Main, at: Vector2) -> Array: list.append({"sep": ""}) list.append({"text": "Theme…", "do": func() -> void: m.add_child(ThemeDialog.new(m))}) if m.sound: - var levels := [] - for level: Array in SoundBoard.LEVELS: - var mark := "✓ " if m.sound.level_name() == level[0] else " " - levels.append({"text": mark + str(level[0]), "do": m.sound.set_volume.bind(float(level[1]))}) - list.append({"text": "Sound", "sub": levels, "tip": "How loud the theme's sounds are"}) + list.append({"text": "Sound…", "do": func() -> void: SoundPanel.open(m, m.get_global_mouse_position()), + "tip": "How loud the theme's sounds are"}) if m.mobile: # The phone layout has no room for these on the bar. var build := m.mode == Main.Mode.BUILD diff --git a/ui/sound_board.gd b/ui/sound_board.gd index 382c5ba..0e787be 100644 --- a/ui/sound_board.gd +++ b/ui/sound_board.gd @@ -6,7 +6,8 @@ extends Node ## without a sound for an event stays quiet. The volume is an app setting. const SETTING := "sound_volume" -## Volume levels for View ▾ → Sound: [label, linear volume]. +## Named volume levels: [label, linear volume] (the Sound slider's default is +## Quiet). const LEVELS := [["Off", 0.0], ["Quiet", 0.35], ["Medium", 0.65], ["Loud", 1.0]] const DEFAULT_VOLUME := 0.35 const EVENTS := ["roll", "card_turn", "thread", "click", "ambient"] @@ -59,6 +60,12 @@ func play(event: String) -> void: voice.play() +## Changes the volume without saving it (while a slider moves). +func preview_volume(level: float) -> void: + volume = clampf(level, 0.0, 1.0) + _start_ambient() + + func set_volume(level: float) -> void: volume = clampf(level, 0.0, 1.0) if m.state: diff --git a/ui/sound_panel.gd b/ui/sound_panel.gd new file mode 100644 index 0000000..1dde45a --- /dev/null +++ b/ui/sound_panel.gd @@ -0,0 +1,43 @@ +class_name SoundPanel +extends RefCounted +## View ▾ → Sound… (and the ☰ menu): a small pop-up with a volume slider from +## Off to Loud. Dragging changes the volume at once; letting go saves it and +## plays the roll sound at the new level. + + +static func open(m: Main, at: Vector2) -> PopupPanel: + var popup := PopupPanel.new() + popup.theme = Style.card_theme() + var column := VBoxContainer.new() + column.add_theme_constant_override("separation", 6) + column.custom_minimum_size = Vector2(240, 0) + popup.add_child(column) + var heading := HBoxContainer.new() + heading.add_child(Style.make_label("Sound", Style.body_bold(), 15, Style.INK)) + var shown := Style.make_label("", Style.body(), 14, Style.MUTED) + shown.size_flags_horizontal = Control.SIZE_EXPAND_FILL + shown.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + heading.add_child(shown) + column.add_child(heading) + var slider := HSlider.new() + slider.min_value = 0 + slider.max_value = 100 + slider.step = 1 + slider.value = roundf(m.sound.volume * 100.0) + slider.tooltip_text = "How loud the theme's sounds are" + column.add_child(slider) + var words := func(percent: float) -> String: + return "Off" if percent <= 0.0 else "%d%%" % int(percent) + shown.text = words.call(slider.value) + slider.value_changed.connect(func(percent: float) -> void: + m.sound.preview_volume(percent / 100.0) + shown.text = words.call(percent)) + slider.drag_ended.connect(func(_changed: bool) -> void: + m.sound.set_volume(slider.value / 100.0) + m.sound.play("roll")) + popup.popup_hide.connect(func() -> void: + m.sound.set_volume(slider.value / 100.0) + popup.queue_free()) + m.add_child(popup) + popup.popup(Rect2i(Vector2i(at), Vector2i(260, 0))) + return popup diff --git a/ui/sound_panel.gd.uid b/ui/sound_panel.gd.uid new file mode 100644 index 0000000..8587451 --- /dev/null +++ b/ui/sound_panel.gd.uid @@ -0,0 +1 @@ +uid://dklnsrugi7svi diff --git a/ui/theme_dialog.gd b/ui/theme_dialog.gd index 30c05fd..319dd15 100644 --- a/ui/theme_dialog.gd +++ b/ui/theme_dialog.gd @@ -11,6 +11,7 @@ var _work: Dictionary = {} var _dirty := false var _picker: OptionButton var _content: VBoxContainer +var _delete_button: Button var _more := false @@ -28,7 +29,7 @@ func _init(p_main: Main) -> void: _content = VBoxContainer.new() _content.add_theme_constant_override("separation", 14) body.add_child(_content) - add_button("Delete", "plain", _delete) + _delete_button = add_button("Delete", "plain", _delete) add_button("Save as new…", "plain", _save_as_new) add_button("Close", "plain", close) add_button("Use theme", "primary", _use) @@ -58,6 +59,9 @@ func _load(t: Dictionary) -> void: func _rebuild() -> void: for c in _content.get_children(): c.queue_free() + # Built-in themes can't be deleted, so they don't offer it. + if _delete_button: + _delete_button.visible = not bool(_work.get("builtin", false)) if bool(_work.get("builtin", false)): _content.add_child(ModalCard.note("This theme is built in. Changes to it are saved as a new theme of your own.")) var bg := FillEditor.new(_work.get("background", {}), _color("BG")) diff --git a/ui/view_menu.gd b/ui/view_menu.gd index 6fc8fb8..bc3686e 100644 --- a/ui/view_menu.gd +++ b/ui/view_menu.gd @@ -12,6 +12,7 @@ const ID_MINIMAP := 4 const ID_THEME := 5 const ID_LIST := 6 const ID_BOOK := 7 +const ID_SOUND := 8 var m: Main @@ -39,6 +40,8 @@ func setup(p_main: Main) -> void: pm.add_separator() pm.add_item("Theme…", ID_THEME) pm.set_item_tooltip(pm.get_item_index(ID_THEME), "Colours, background, fonts and logo; save your own theme") + pm.add_item("Sound…", ID_SOUND) + pm.set_item_tooltip(pm.get_item_index(ID_SOUND), "How loud the theme's sounds are") pm.about_to_popup.connect(sync) pm.id_pressed.connect(activate) @@ -77,3 +80,5 @@ func activate(id: int) -> void: m.book.toggle() ID_THEME: m.add_child(ThemeDialog.new(m)) + ID_SOUND: + SoundPanel.open(m, get_global_rect().position + Vector2(0, size.y + 4))