diff --git a/Client/origin-client/autoloads/Music.gd b/Client/origin-client/autoloads/Music.gd new file mode 100644 index 0000000..bd0e273 --- /dev/null +++ b/Client/origin-client/autoloads/Music.gd @@ -0,0 +1,153 @@ +extends Node +## Music autoload — fetches BGM config from the server and plays context-appropriate tracks. +## +## Usage: +## Music.play_context("Game") # start/crossfade to the Game context track +## Music.play_context("Lobby") # switch to Lobby context +## Music.stop() # fade out and stop +## +## Volume and mute are controlled via Settings.music_volume / Settings.music_muted. +## This node streams audio via an AudioStreamPlayer on the "Music" bus. + +const CROSSFADE_DURATION := 1.2 # seconds +const CONTEXT_AUDIO_MSG := "content.get_audio_config" + +## _tracks[context] = Array of { "name": String, "url": String } +var _tracks : Dictionary = {} +var _current_context: String = "" +var _player_a : AudioStreamPlayer +var _player_b : AudioStreamPlayer +var _active_player : AudioStreamPlayer # the one currently audible + +# ── Lifecycle ───────────────────────────────────────────────────────────────── + +func _ready() -> void: + _player_a = _make_player() + _player_b = _make_player() + _active_player = _player_a + + # Fetch BGM config once at startup (connection must be established by then). + # Scenes that start music will typically call play_context after login. + +func _make_player() -> AudioStreamPlayer: + var p := AudioStreamPlayer.new() + p.bus = Settings.BUS_MUSIC + p.volume_db = linear_to_db(Settings.music_volume) if not Settings.music_muted else -80.0 + add_child(p) + return p + +# ── Public API ───────────────────────────────────────────────────────────────── + +## Fetch the BGM track list from the server. +## Call this once after the player is authenticated and connected. +func fetch_config() -> void: + Network.request(CONTEXT_AUDIO_MSG, {}, + func(_type: String, resp: Variant) -> void: + var d := resp as Dictionary + if not d.has("tracks"): + return + _tracks.clear() + for t: Dictionary in d.get("tracks", []): + var ctx : String = str(t.get("context", "")) + if ctx.is_empty(): + continue + if not _tracks.has(ctx): + _tracks[ctx] = [] + _tracks[ctx].append({ + "name": str(t.get("trackName", "")), + "url": str(t.get("trackCdnUrl", "")), + }), + func(code: String, msg: String) -> void: + push_warning("Music: fetch_config failed — %s: %s" % [code, msg])) + +## Start playing a track for the given context. +## Crossfades from the currently playing track. No-ops if already on this context. +func play_context(ctx: String) -> void: + if ctx == _current_context: + return + _current_context = ctx + + var list : Array = _tracks.get(ctx, []) + if list.is_empty(): + stop() + return + + var entry : Dictionary = list[randi() % list.size()] + var url : String = str(entry.get("url", "")) + if url.is_empty(): + return + + _crossfade_to(url) + +## Stop music with a short fade-out. +func stop() -> void: + _current_context = "" + _fade_out(_active_player) + +# ── Internal ────────────────────────────────────────────────────────────────── + +func _crossfade_to(url: String) -> void: + var next : AudioStreamPlayer = _player_b if _active_player == _player_a else _player_a + + # Load stream from URL (Godot's ResourceLoader supports http URLs if configured, + # otherwise fall back to local path for bundled tracks). + var stream := await _load_stream(url) + if stream == null: + return + + next.stream = stream + next.volume_db = -80.0 + next.play() + + var tween := create_tween().set_parallel(true) + tween.tween_property(next, "volume_db", + linear_to_db(Settings.music_volume) if not Settings.music_muted else -80.0, + CROSSFADE_DURATION) + tween.tween_property(_active_player, "volume_db", -80.0, CROSSFADE_DURATION) + await tween.finished + + _active_player.stop() + _active_player = next + +func _fade_out(player: AudioStreamPlayer) -> void: + if not player.playing: + return + var tween := create_tween() + tween.tween_property(player, "volume_db", -80.0, CROSSFADE_DURATION) + await tween.finished + player.stop() + +func _load_stream(url: String) -> AudioStream: + # If it looks like a local resource path, load directly. + if url.begins_with("res://") or url.begins_with("user://"): + return load(url) as AudioStream + + # For CDN URLs: use HTTPRequest to download and create stream from bytes. + # This is an async download approach compatible with Godot 4. + var http := HTTPRequest.new() + add_child(http) + http.request(url) + var result : Array = await http.request_completed + http.queue_free() + + var response_code : int = result[1] + var body : PackedByteArray = result[3] + if response_code != 200 or body.is_empty(): + push_warning("Music: failed to download %s (HTTP %d)" % [url, response_code]) + return null + + # Determine format from URL extension and create appropriate stream. + var ext := url.get_extension().to_lower() + if ext == "ogg": + return AudioStreamOggVorbis.load_from_buffer(body) + elif ext in ["mp3"]: + var stream := AudioStreamMP3.new() + stream.data = body + return stream + elif ext == "wav": + # WAV loading from bytes is not directly supported; warn and return null. + push_warning("Music: WAV from URL not supported. Use OGG or MP3.") + return null + + push_warning("Music: unknown audio format '%s'" % ext) + return null diff --git a/Client/origin-client/project.godot b/Client/origin-client/project.godot index c9f355b..23dcd13 100644 --- a/Client/origin-client/project.godot +++ b/Client/origin-client/project.godot @@ -25,6 +25,7 @@ Chat="*res://autoloads/Chat.gd" Settings="*res://autoloads/Settings.gd" Game="*res://autoloads/Game.gd" ModelCache="*res://autoloads/ModelCache.gd" +Music="*res://autoloads/Music.gd" [display] diff --git a/Client/origin-client/scenes/game/GameScreen.tscn b/Client/origin-client/scenes/game/GameScreen.tscn index e914132..535b308 100644 --- a/Client/origin-client/scenes/game/GameScreen.tscn +++ b/Client/origin-client/scenes/game/GameScreen.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://b17evi1hw4dqu"] +[gd_scene load_steps=3 format=3 uid="uid://b17evi1hw4dqu"] [ext_resource type="Script" uid="uid://b8x84lb58h6gx" path="res://scenes/game/game_screen.gd" id="1_gscr"] +[ext_resource type="PackedScene" path="res://scenes/game/InGameSettings.tscn" id="2_igs"] [node name="GameScreen" type="Node3D"] script = ExtResource("1_gscr") @@ -166,11 +167,11 @@ layout_mode = 2 theme_override_font_sizes/font_size = 13 text = "End Turn" -[node name="ConcedeBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"] +[node name="SettingsBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"] unique_name_in_owner = true layout_mode = 2 theme_override_font_sizes/font_size = 12 -text = "Concede" +text = "Settings" [node name="ContextPopup" type="PanelContainer" parent="HUD"] unique_name_in_owner = true @@ -305,6 +306,20 @@ layout_mode = 2 theme_override_font_sizes/font_size = 15 text = "Return to Main Menu" +[node name="InGameSettings" parent="HUD" instance=ExtResource("2_igs")] +unique_name_in_owner = true +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -220.0 +offset_top = -260.0 +offset_right = 220.0 +offset_bottom = 260.0 +grow_horizontal = 2 +grow_vertical = 2 + [node name="HoldTimer" type="Timer" parent="."] unique_name_in_owner = true wait_time = 0.5 diff --git a/Client/origin-client/scenes/game/InGameSettings.tscn b/Client/origin-client/scenes/game/InGameSettings.tscn new file mode 100644 index 0000000..5260096 --- /dev/null +++ b/Client/origin-client/scenes/game/InGameSettings.tscn @@ -0,0 +1,140 @@ +[gd_scene load_steps=2 format=3 uid="uid://in_game_settings"] + +[ext_resource type="Script" path="res://scenes/game/in_game_settings.gd" id="1_script"] + +[node name="InGameSettings" type="PanelContainer"] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -220.0 +offset_top = -260.0 +offset_right = 220.0 +offset_bottom = 260.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_script") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 16 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 16 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 12 + +[node name="TitleRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + +[node name="Title" type="Label" parent="MarginContainer/VBoxContainer/TitleRow"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Settings" +theme_override_font_sizes/font_size = 18 + +[node name="ResumeBtn" type="Button" parent="MarginContainer/VBoxContainer/TitleRow"] +unique_name_in_owner = true +layout_mode = 2 +text = "Resume" + +[node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + +[node name="AudioLabel" type="Label" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Audio" +theme_override_font_sizes/font_size = 13 + +[node name="MusicRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + +[node name="MusicLabel" type="Label" parent="MarginContainer/VBoxContainer/MusicRow"] +layout_mode = 2 +custom_minimum_size = Vector2(80, 0) +text = "Music" +vertical_alignment = 1 + +[node name="MusicSlider" type="HSlider" parent="MarginContainer/VBoxContainer/MusicRow"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +min_value = 0.0 +max_value = 1.0 +step = 0.01 +value = 1.0 + +[node name="MusicMute" type="CheckButton" parent="MarginContainer/VBoxContainer/MusicRow"] +unique_name_in_owner = true +layout_mode = 2 +text = "Mute" + +[node name="SfxRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + +[node name="SfxLabel" type="Label" parent="MarginContainer/VBoxContainer/SfxRow"] +layout_mode = 2 +custom_minimum_size = Vector2(80, 0) +text = "SFX" +vertical_alignment = 1 + +[node name="SfxSlider" type="HSlider" parent="MarginContainer/VBoxContainer/SfxRow"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +min_value = 0.0 +max_value = 1.0 +step = 0.01 +value = 1.0 + +[node name="SfxMute" type="CheckButton" parent="MarginContainer/VBoxContainer/SfxRow"] +unique_name_in_owner = true +layout_mode = 2 +text = "Mute" + +[node name="HSeparator2" type="HSeparator" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + +[node name="GameplayLabel" type="Label" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Gameplay" +theme_override_font_sizes/font_size = 13 + +[node name="CameraFollowUnit" type="CheckButton" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "Center camera on selected unit" + +[node name="HSeparator3" type="HSeparator" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + +[node name="ConcedeBtn" type="Button" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "Concede Game" +theme_override_colors/font_color = Color(1, 0.3, 0.3, 1) + +[node name="ConcedeConfirmRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +visible = false + +[node name="ConfirmLabel" type="Label" parent="MarginContainer/VBoxContainer/ConcedeConfirmRow"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Are you sure?" +vertical_alignment = 1 + +[node name="ConcedeYes" type="Button" parent="MarginContainer/VBoxContainer/ConcedeConfirmRow"] +unique_name_in_owner = true +layout_mode = 2 +text = "Yes, Concede" +theme_override_colors/font_color = Color(1, 0.3, 0.3, 1) + +[node name="ConcedeNo" type="Button" parent="MarginContainer/VBoxContainer/ConcedeConfirmRow"] +unique_name_in_owner = true +layout_mode = 2 +text = "Cancel" diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 00998bd..772f9ee 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -45,7 +45,8 @@ enum Mode { @onready var _discard_btn : Button = %DiscardBtn @onready var _draw_btn : Button = %DrawBtn @onready var _end_turn_btn : Button = %EndTurnBtn -@onready var _concede_btn : Button = %ConcedeBtn +@onready var _settings_btn : Button = %SettingsBtn +@onready var _in_game_settings: PanelContainer = %InGameSettings @onready var _ctx_popup : PanelContainer = %ContextPopup @onready var _ctx_tile_lbl : Label = %ContextTileLabel @onready var _ctx_unit_lbl : Label = %ContextUnitLabel @@ -159,7 +160,7 @@ func _ready() -> void: _draw_btn.pressed.connect(_on_draw_pressed) _end_turn_btn.pressed.connect(_on_end_turn_pressed) - _concede_btn.pressed.connect(_on_concede_pressed) + _settings_btn.pressed.connect(func() -> void: _in_game_settings.open()) _discard_btn.pressed.connect(func() -> void: _show_own_discard()) _opp_discard_btn.pressed.connect(func() -> void: _show_opp_discard()) _ctx_close_btn.pressed.connect(func() -> void: _ctx_popup.visible = false) @@ -1888,14 +1889,3 @@ func _on_state_updated(state: Dictionary) -> void: func _on_draw_pressed() -> void: Game.send_draw() func _on_end_turn_pressed() -> void: _set_mode(Mode.NONE); Game.send_end_turn() -func _on_concede_pressed() -> void: - var dlg := ConfirmationDialog.new() - dlg.title = "Concede" - dlg.dialog_text = "Are you sure you want to concede?" - dlg.ok_button_text = "Concede" - dlg.cancel_button_text = "Cancel" - dlg.min_size = Vector2(280, 100) - add_child(dlg) - dlg.popup_centered() - dlg.confirmed.connect(func() -> void: Game.send_concede(); dlg.queue_free()) - dlg.canceled.connect(func() -> void: dlg.queue_free()) diff --git a/Client/origin-client/scenes/game/in_game_settings.gd b/Client/origin-client/scenes/game/in_game_settings.gd new file mode 100644 index 0000000..6e71df1 --- /dev/null +++ b/Client/origin-client/scenes/game/in_game_settings.gd @@ -0,0 +1,77 @@ +extends PanelContainer +## In-game settings overlay — audio controls, gameplay options, and concede. +## Shown/hidden by game_screen.gd when the player taps the gear button. + +@onready var _music_slider : HSlider = %MusicSlider +@onready var _music_mute : CheckButton = %MusicMute +@onready var _sfx_slider : HSlider = %SfxSlider +@onready var _sfx_mute : CheckButton = %SfxMute +@onready var _cam_follow : CheckButton = %CameraFollowUnit +@onready var _concede_btn : Button = %ConcedeBtn +@onready var _confirm_row : HBoxContainer = %ConcedeConfirmRow +@onready var _confirm_yes : Button = %ConcedeYes +@onready var _confirm_no : Button = %ConcedeNo +@onready var _resume_btn : Button = %ResumeBtn + +# ── Lifecycle ───────────────────────────────────────────────────────────────── + +func _ready() -> void: + visible = false + _sync_from_settings() + + _music_slider.value_changed.connect(_on_music_volume_changed) + _music_mute.toggled.connect(_on_music_mute_toggled) + _sfx_slider.value_changed.connect(_on_sfx_volume_changed) + _sfx_mute.toggled.connect(_on_sfx_mute_toggled) + _cam_follow.toggled.connect(func(v: bool) -> void: Settings.camera_follow_unit = v) + + _concede_btn.pressed.connect(_on_concede_pressed) + _confirm_yes.pressed.connect(_on_concede_confirmed) + _confirm_no.pressed.connect(func() -> void: _confirm_row.visible = false; _concede_btn.visible = true) + _resume_btn.pressed.connect(close) + + Settings.settings_changed.connect(_sync_from_settings) + +# ── Public ───────────────────────────────────────────────────────────────────── + +func open() -> void: + _sync_from_settings() + _confirm_row.visible = false + _concede_btn.visible = true + visible = true + +func close() -> void: + visible = false + +# ── Internal ────────────────────────────────────────────────────────────────── + +func _sync_from_settings() -> void: + _music_slider.set_value_no_signal(Settings.music_volume) + _music_mute.set_pressed_no_signal(Settings.music_muted) + _sfx_slider.set_value_no_signal(Settings.sfx_volume) + _sfx_mute.set_pressed_no_signal(Settings.sfx_muted) + _cam_follow.set_pressed_no_signal(Settings.camera_follow_unit) + _music_slider.modulate.a = 0.4 if Settings.music_muted else 1.0 + _sfx_slider.modulate.a = 0.4 if Settings.sfx_muted else 1.0 + +func _on_music_volume_changed(v: float) -> void: + Settings.music_volume = v + +func _on_music_mute_toggled(v: bool) -> void: + Settings.music_muted = v + _music_slider.modulate.a = 0.4 if v else 1.0 + +func _on_sfx_volume_changed(v: float) -> void: + Settings.sfx_volume = v + +func _on_sfx_mute_toggled(v: bool) -> void: + Settings.sfx_muted = v + _sfx_slider.modulate.a = 0.4 if v else 1.0 + +func _on_concede_pressed() -> void: + _concede_btn.visible = false + _confirm_row.visible = true + +func _on_concede_confirmed() -> void: + close() + Game.send_concede() diff --git a/Server/src/SOR.Admin/Components/Layout/NavMenu.razor b/Server/src/SOR.Admin/Components/Layout/NavMenu.razor index c9b70cc..1841a5a 100644 --- a/Server/src/SOR.Admin/Components/Layout/NavMenu.razor +++ b/Server/src/SOR.Admin/Components/Layout/NavMenu.razor @@ -117,6 +117,11 @@ AI Art Tracker +
| Action | CDN URL | AI | Upload | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Action | Animation CDN URL | Cast Sound URL | Impact Sound URL | AI | Upload | ||||||||||
| + | + placeholder="https://cdn.sor.gg/anims/…" /> + | ++ + | ++ |
diff --git a/Server/src/SOR.Admin/Components/Pages/Content/AudioConfig.razor b/Server/src/SOR.Admin/Components/Pages/Content/AudioConfig.razor
new file mode 100644
index 0000000..c71f961
--- /dev/null
+++ b/Server/src/SOR.Admin/Components/Pages/Content/AudioConfig.razor
@@ -0,0 +1,202 @@
+@page "/content/audio"
+@attribute [Authorize(Roles = "Admin,SuperAdmin")]
+@using Microsoft.EntityFrameworkCore
+@using SOR.Database.Contexts
+@using SOR.Database.Entities.Catalog
+@inject CatalogDbContext Db
+
+
+
+
+@if (_message is not null)
+{
+
+
+
+Background Music+Configure BGM tracks served to clients per game context
+
+ @_message
+
+
+}
+
+
+
+
+Tracks
+
+ @if (_loading)
+ {
+
+Loading… + } + else if (_tracks.Count == 0) + { +No tracks configured. Add one below. + } + else + { +
+
+
+@code {
+ private ListAdd Track
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |