Fix reached macOS UI primitives and audio fade behavior

This commit is contained in:
shen
2026-09-24 00:31:51 -07:00
parent 330ec9745b
commit 400973da11
14 changed files with 439 additions and 66 deletions
+12 -4
View File
@@ -71,9 +71,13 @@ auto CScreen::RenderLine2d(float sx, float sy, float ex, float ey, float) -> voi
UIRenderAdd({UIRenderCommand::Line, sx, sy, ex, ey, ms_diffuseColor});
}
auto CScreen::RenderBox2d(float, float, float, float, float) -> void
auto CScreen::RenderBox2d(float sx, float sy, float ex, float ey, float) -> void
{
MT_PLATFORM_STUB();
// 40250's four line pairs, including its one-pixel extension of the bottom edge.
UIRenderAdd({UIRenderCommand::Line, sx, sy, ex, sy, ms_diffuseColor});
UIRenderAdd({UIRenderCommand::Line, sx, sy, sx, ey, ms_diffuseColor});
UIRenderAdd({UIRenderCommand::Line, ex, sy, ex, ey, ms_diffuseColor});
UIRenderAdd({UIRenderCommand::Line, sx, ey, ex + 1.0f, ey, ms_diffuseColor});
}
auto CScreen::RenderBar2d(float sx, float sy, float ex, float ey, float) -> void
@@ -81,9 +85,13 @@ auto CScreen::RenderBar2d(float sx, float sy, float ex, float ey, float) -> void
UIRenderAdd({UIRenderCommand::Bar, sx, sy, ex, ey, ms_diffuseColor});
}
auto CScreen::RenderGradationBar2d(float, float, float, float, DWORD, DWORD, float) -> void
auto CScreen::RenderGradationBar2d(float sx, float sy, float ex, float ey, DWORD start, DWORD end, float) -> void
{
MT_PLATFORM_STUB();
if (sx == ex || sy == ey)
return;
UIRenderCommand command{UIRenderCommand::GradientBar, sx, sy, ex, ey, start};
command.end_argb = end;
UIRenderAdd(std::move(command));
}
auto CScreen::RenderCircle2d(float, float, float, float, int) -> void
@@ -7,9 +7,10 @@
// Commands emitted by the 40250 UI drawing calls, consumed by Godot's CanvasItem.
// The port layer stays independent of godot-cpp.
struct UIRenderCommand {
enum Kind { Bar, Line, Text, Image } kind;
enum Kind { Bar, Line, Text, Image, GradientBar } kind;
float x1, y1, x2, y2;
std::uint32_t argb;
std::uint32_t end_argb = 0; // GradientBar only: colour on the bottom edge.
float clip_x1 = 0, clip_y1 = 0, clip_x2 = 0, clip_y2 = 0;
std::string text;
// Image only: text is the texture's file, drawn as the quad (vertices 0..3 = TL, TR, BL, BR)
@@ -16,6 +16,9 @@ struct AudioCommand
FadeOutAllMusic = 7,
SetSoundVolume = 8,
SetMusicVolume = 9,
FadeInMusic = 10,
FadeLimitOutMusic = 11,
SetSoundVolume3D = 12,
};
Type type = PlaySound2D;
@@ -171,14 +171,20 @@ void CSoundManager::SetMusicVolumeGrade(int iGrade)
void CSoundManager::SaveVolume()
{
m_fBackupMusicVolume = m_fMusicVolume;
m_fBackupSoundVolume = m_fSoundVolume;
if (m_isSoundDisable)
return;
const float musicVolume = m_fMusicVolume;
const float soundVolume = m_fSoundVolume;
SetMusicVolume(0.0f);
SetSoundVolume(0.0f);
m_fBackupMusicVolume = musicVolume;
m_fBackupSoundVolume = soundVolume;
m_isSoundDisable = TRUE;
}
void CSoundManager::RestoreVolume()
{
m_isSoundDisable = FALSE;
SetMusicVolume(m_fBackupMusicVolume);
SetSoundVolume(m_fBackupSoundVolume);
}
@@ -251,8 +257,13 @@ void CSoundManager::PlayCharacterSound3D(float fx, float fy, float fz, const cha
PlaySound3D(fx, fy, fz, c_szFileName, 1);
}
void CSoundManager::SetSoundVolume3D(int, float)
void CSoundManager::SetSoundVolume3D(int index, float volume)
{
AudioCommand cmd;
cmd.type = AudioCommand::SetSoundVolume3D;
cmd.id = index;
cmd.volume = volume;
PushAudioCommand(cmd);
}
void CSoundManager::StopAllSound3D()
@@ -274,9 +285,16 @@ void CSoundManager::PlayMusic(const char * c_szFileName)
PushAudioCommand(cmd);
}
void CSoundManager::FadeInMusic(const char * c_szFileName, float)
void CSoundManager::FadeInMusic(const char * c_szFileName, float speed)
{
PlayMusic(c_szFileName);
if (!c_szFileName || !c_szFileName[0])
return;
AudioCommand cmd;
cmd.type = AudioCommand::FadeInMusic;
cmd.filename = c_szFileName;
cmd.volume = m_fMusicVolume;
cmd.speed = speed;
PushAudioCommand(cmd);
}
void CSoundManager::FadeOutMusic(const char * c_szFileName, float fSpeed)
@@ -288,9 +306,14 @@ void CSoundManager::FadeOutMusic(const char * c_szFileName, float fSpeed)
PushAudioCommand(cmd);
}
void CSoundManager::FadeLimitOutMusic(const char * c_szFileName, float, float fSpeed)
void CSoundManager::FadeLimitOutMusic(const char * c_szFileName, float limit, float speed)
{
FadeOutMusic(c_szFileName, fSpeed);
AudioCommand cmd;
cmd.type = AudioCommand::FadeLimitOutMusic;
cmd.filename = c_szFileName ? c_szFileName : "";
cmd.volume = __ConvertRatioVolumeToApplyVolume(limit);
cmd.speed = speed;
PushAudioCommand(cmd);
}
void CSoundManager::FadeOutAllMusic()
+8 -2
View File
@@ -91,14 +91,17 @@ Array Metin2PythonHost::ui_render_commands() {
Array out;
for (const auto &command : UIRenderCommands()) {
Dictionary item;
item["kind"] = command.kind == UIRenderCommand::Bar ? "bar" :
item["kind"] = command.kind == UIRenderCommand::GradientBar ? "gradient_bar" :
(command.kind == UIRenderCommand::Bar ? "bar" :
(command.kind == UIRenderCommand::Line ? "line" :
(command.kind == UIRenderCommand::Image ? "image" : "text"));
(command.kind == UIRenderCommand::Image ? "image" : "text")));
item["x1"] = command.x1;
item["y1"] = command.y1;
item["x2"] = command.x2;
item["y2"] = command.y2;
item["argb"] = static_cast<int64_t>(command.argb);
if (command.kind == UIRenderCommand::GradientBar)
item["end_argb"] = static_cast<int64_t>(command.end_argb);
item["clip_x1"] = command.clip_x1;
item["clip_y1"] = command.clip_y1;
item["clip_x2"] = command.clip_x2;
@@ -259,6 +262,9 @@ Array Metin2PythonHost::audio_commands() {
case AudioCommand::FadeOutAllMusic: item["type"] = "fade_out_all_music"; break;
case AudioCommand::SetSoundVolume: item["type"] = "set_sound_volume"; break;
case AudioCommand::SetMusicVolume: item["type"] = "set_music_volume"; break;
case AudioCommand::FadeInMusic: item["type"] = "fade_in_music"; break;
case AudioCommand::FadeLimitOutMusic: item["type"] = "fade_limit_out_music"; break;
case AudioCommand::SetSoundVolume3D: item["type"] = "set_sound_volume_3d"; break;
default: continue;
}
item["filename"] = String::utf8(cmd.filename.c_str());