Skip to content

Commit

Permalink
Merge pull request #38 from XiteSDF/ddmode
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcintyre authored Aug 26, 2023
2 parents c021f77 + 64fe49b commit 22e278f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 6 deletions.
33 changes: 28 additions & 5 deletions Orchestrion/Audio/BGMManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public static class BGMManager
private static readonly OrchestrionIpcManager _ipcManager;

private static bool _isPlayingReplacement;

private static bool _isDDMode;
private static string _DDPlaylist = "";

public delegate void SongChanged(int oldSong, int currentSong, int oldSecondSong, int oldCurrentSong, bool oldPlayedByOrch, bool playedByOrchestrion);
public static event SongChanged OnSongChanged;

Expand Down Expand Up @@ -65,6 +67,15 @@ private static void HandleSongChanged(int oldSong, int newSong, int oldSecondSon
if (secondChanged)
PluginLog.Debug($"[HandleSongChanged] Second song ID changed from {_bgmController.OldSecondSongId} to {_bgmController.SecondSongId}");

if (PlayingSongId != 0 && _isDDMode)
{
if (_DDPlaylist != "" && !Configuration.Instance.Playlists.ContainsKey(_DDPlaylist)) // user deleted playlist
Stop();
else
PlayRandomSong(_DDPlaylist, true);
return;
}

if (PlayingSongId != 0 && !_isPlayingReplacement) return; // manually playing track
if (secondChanged && !currentChanged && !_isPlayingReplacement) return; // don't care about behind song if not playing replacement

Expand Down Expand Up @@ -105,7 +116,7 @@ private static void HandleSongChanged(int oldSong, int newSong, int oldSecondSon
Play(toPlay, isReplacement: true); // we only ever play a replacement here
}

public static void Play(int songId, bool isReplacement = false)
public static void Play(int songId, bool isReplacement = false, bool isDDMode = false)
{
var wasPlaying = PlayingSongId != 0;
var oldSongId = CurrentAudibleSong;
Expand All @@ -115,6 +126,7 @@ public static void Play(int songId, bool isReplacement = false)
InvokeSongChanged(oldSongId, songId, secondSongId, oldSongId, oldPlayedByOrch: wasPlaying, playedByOrch: true);
_bgmController.SetSong((ushort)songId);
_isPlayingReplacement = isReplacement;
_isDDMode = isDDMode;
}

public static void Stop()
Expand Down Expand Up @@ -154,12 +166,23 @@ private static void InvokeSongChanged(int oldSongId, int newSongId, int oldSecon
PluginLog.Debug($"[InvokeSongChanged] Invoking SongChanged event with {oldSongId} -> {newSongId}, {oldSecondSongId} -> {newSecondSongId} | {oldPlayedByOrch} {playedByOrch}");
OnSongChanged?.Invoke(oldSongId, newSongId, oldSecondSongId, newSecondSongId, oldPlayedByOrch, playedByOrch);
}
public static void PlayRandomSong(string playlistName = "")

public static void PlayRandomSong(string playlistName = "", bool isDDMode = false)
{
if (SongList.Instance.TryGetRandomSong(playlistName, out var randomFavoriteSong))
Play(randomFavoriteSong);
Play(randomFavoriteSong, isDDMode: isDDMode);
else
DalamudApi.ChatGui.PrintError(Loc.Localize("NoPossibleSongs", "No possible songs found."));
}

public static void StartDeepDungeonMode(string playlistName = "")
{
if (playlistName != "" && !Configuration.Instance.Playlists.ContainsKey(playlistName))
{
DalamudApi.ChatGui.PrintError(String.Format("Playlist {0} not found.", playlistName));
return;
}
_DDPlaylist = playlistName;
PlayRandomSong(_DDPlaylist, true);
}
}
4 changes: 4 additions & 0 deletions Orchestrion/Loc/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
"message": "General Settings",
"description": "SettingsWindow.Draw"
},
"DDPlaylistAll": {
"message": "All Songs",
"description": "SettingsWindow.Draw"
},
"AudioStreamingDisabledWarning": {
"message": "Audio streaming is disabled. This may be due to Sound Filter or a third-party plugin. The above setting may not work as expected and you may encounter other audio issues such as popping or tracks not swapping channels. This is not related to the Orchestrion Plugin.",
"description": "SettingsWindow.Draw"
Expand Down
9 changes: 8 additions & 1 deletion Orchestrion/OrchestrionPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ private void OnCommand(string command, string args)
case "repeat":
DalamudApi.ChatGui.PrintError(BuildChatMessage(Loc.Localize("NoRepeatModeSpecified", "Please specify a repeat mode.")));
break;
case "ddmode":
BGMManager.StartDeepDungeonMode();
break;
}
break;
case 2:
Expand Down Expand Up @@ -254,7 +257,10 @@ private void OnCommand(string command, string args)
PlaylistManager.CurrentPlaylist.ShuffleMode = ShuffleMode.Off;
PlaylistManager.CurrentPlaylist.RepeatMode = repeatMode;
}
break;
break;
case "ddmode":
BGMManager.StartDeepDungeonMode(argSplit[1]);
break;
}
break;
case >= 3 when argSplit[1].ToLowerInvariant() == "playlist":
Expand Down Expand Up @@ -323,6 +329,7 @@ private void PrintHelp()
DalamudApi.ChatGui.Print(BuildChatMessage("/porch play [song name] - " + Loc.Localize("HelpPlaySongWithName", "Play the song with the specified name (both English and Japanese titles work)")));
DalamudApi.ChatGui.Print(BuildChatMessage("/porch random - " + Loc.Localize("HelpPlayRandomSong", "Play a random song")));
DalamudApi.ChatGui.Print(BuildChatMessage("/porch stop - " + Loc.Localize("HelpStopSong", "Stop the current playing song, replacement song, or playlist")));
DalamudApi.ChatGui.Print(BuildChatMessage("/porch ddmode [playlist] - " + Loc.Localize("HelpDDMode", "On every in-game BGM change replace BGM with random song from specified playlist")));
DalamudApi.ChatGui.Print(BuildChatMessage(Loc.Localize("PlaylistCommandsColon", "Playlist Commands:")));
DalamudApi.ChatGui.Print(BuildChatMessage("/porch random [playlist] - " + Loc.Localize("HelpPlayRandomSongFromPlaylist", "Play a random song from the specified playlist (does not begin the playlist)")));
DalamudApi.ChatGui.Print(BuildChatMessage("/porch play playlist [playlist name] - " + Loc.Localize("HelpPlayPlaylist", "Play the specified playlist with its current settings")));
Expand Down
56 changes: 56 additions & 0 deletions Orchestrion/UI/Windows/MainWindow/MainWindow.DDMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using CheapLoc;
using ImGuiNET;
using Orchestrion.Audio;
using Orchestrion.Persistence;
using Orchestrion.Struct;

namespace Orchestrion.UI.Windows.MainWindow;

public partial class MainWindow
{
private string _selectedDDPlaylist = "";
private void DrawDeepDungeonModeTab()
{
ImGui.BeginChild("##ddmode");
DrawDeepDungeonModeSelector();
ImGui.EndChild();
}

private void DrawDeepDungeonModeSelector()
{
ImGui.Spacing();

var targetText = $"{SongList.Instance.GetSong(_tmpReplacement.TargetSongId).Id} - {SongList.Instance.GetSong(_tmpReplacement.TargetSongId).Name}";
string replacementText;
if (_tmpReplacement.ReplacementId == SongReplacementEntry.NoChangeId)
replacementText = _noChange;
else
replacementText = $"{SongList.Instance.GetSong(_tmpReplacement.ReplacementId).Id} - {SongList.Instance.GetSong(_tmpReplacement.ReplacementId).Name}";

// This fixes the ultra-wide combo boxes, I guess
var width = ImGui.GetWindowWidth() * 0.60f;

string allSongsLoc = Loc.Localize("DDPlaylistAll", "All Songs");
if (ImGui.BeginCombo(Loc.Localize("DDPlaylist", "Playlist"), _selectedDDPlaylist == "" ? allSongsLoc : _selectedDDPlaylist))
{
if (ImGui.Selectable(allSongsLoc))
{
_selectedDDPlaylist = "";
}
foreach (var pInfo in Configuration.Instance.Playlists)
{
var pName = pInfo.Key;
if (ImGui.Selectable(pName))
{
_selectedDDPlaylist = pName;
}
}
ImGui.EndCombo();
}
var text = Loc.Localize("DDModeStart", "Start DD Mode");
if (ImGui.Button(text))
{
BGMManager.StartDeepDungeonMode(_selectedDDPlaylist);
}
}
}
2 changes: 2 additions & 0 deletions Orchestrion/UI/Windows/MainWindow/MainWindow.Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private enum TabType
{
AllSongs,
Playlist,
DDMode,
History,
Replacements,
Debug,
Expand Down Expand Up @@ -159,6 +160,7 @@ public override void Draw()
{
DrawTab(Loc.Localize("AllSongs", "All Songs"), "orch_AllSongs", DrawSongListTab, TabType.AllSongs);
DrawTab(Loc.Localize("Playlists", "Playlists"), "orch_Playlists", DrawPlaylistsTab, TabType.Playlist);
DrawTab(Loc.Localize("DDMode", "DDMode"), "orch_DDMode", DrawDeepDungeonModeTab, TabType.DDMode);
DrawTab(Loc.Localize("History", "History"), "orch_History", DrawSongHistoryTab, TabType.History);
DrawTab(Loc.Localize("Replacements", "Replacements"), "orch_Replacements", DrawReplacementsTab, TabType.Replacements);
#if DEBUG
Expand Down

0 comments on commit 22e278f

Please sign in to comment.