Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Magpie.Core/include/ScalingOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,26 @@ struct FrameGenerationChainValidation {
bool HasFrameGeneration() const noexcept { return count != 0; }
};

// 配置层的 EffectItem 带 enabled 字段,运行期的 EffectOption 没有。
// 被禁用的效果不参与渲染,因此也不应参与补帧冲突校验。这里用概念做鸭子类型
// 判断,让所有调用点(含 UI 的 CanAddEffect 与运行期装配)都自动忽略禁用项,
// 不会因为漏过滤而误报「一组内存在多个补帧效果」。
template <typename T>
concept HasEnabledFlag = requires(T effect) {
effect.enabled ? 0 : 1;
};

template <typename EffectRange>
FrameGenerationChainValidation ValidateFrameGenerationChain(
const EffectRange& effects
) noexcept {
FrameGenerationChainValidation result;
for (const auto& effect : effects) {
if constexpr (HasEnabledFlag<decltype(effect)>) {
if (!effect.enabled) {
continue;
}
}
const FrameGenerationEffectKind kind =
ClassifyFrameGenerationEffect(effect.name);
if (kind == FrameGenerationEffectKind::None) {
Expand Down
6 changes: 6 additions & 0 deletions src/Magpie/Resources.language-en-US.resw
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@
<data name="ScalingModes_AddEffect.Text" xml:space="preserve">
<value>Add effect</value>
</data>
<data name="ScalingModes_EffectDisable" xml:space="preserve">
<value>Disable</value>
</data>
<data name="ScalingModes_EffectEnable" xml:space="preserve">
<value>Enable</value>
</data>
<data name="ScalingModes_Delete.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Delete</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/Magpie/Resources.language-zh-Hans.resw
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@
<data name="ScalingModes_AddEffect.Text" xml:space="preserve">
<value>添加效果器</value>
</data>
<data name="ScalingModes_EffectDisable" xml:space="preserve">
<value>禁用</value>
</data>
<data name="ScalingModes_EffectEnable" xml:space="preserve">
<value>启用</value>
</data>
<data name="ScalingModes_Delete.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>删除</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/Magpie/Resources.language-zh-Hant.resw
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@
<data name="ScalingModes_AddEffect.Text" xml:space="preserve">
<value>新增效果器</value>
</data>
<data name="ScalingModes_EffectDisable" xml:space="preserve">
<value>停用</value>
</data>
<data name="ScalingModes_EffectEnable" xml:space="preserve">
<value>啟用</value>
</data>
<data name="ScalingModes_Delete.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>刪除</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Magpie/ScalingMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ struct EffectItem {
std::pair<float, float> scale = { 1.0f,1.0f };
bool isRecoveryInvalid = false;
std::string recoveryOriginal;
// 临时禁用:效果仍保留在配置与列表中,但不参与渲染。
// 放在末尾以免影响任何按位置聚合初始化的写法。
bool enabled = true;

bool HasScale() const noexcept {
return scalingType != ScalingType::Normal ||
Expand Down
41 changes: 41 additions & 0 deletions src/Magpie/ScalingModeEffectItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,47 @@ hstring ScalingModeEffectItem::IssueDescription() const noexcept {
_Data().isRecoveryInvalid ? L"ScalingModes_RecoveryInvalid_Description" : L"ScalingModes_MissingEffect_Description");
}

bool ScalingModeEffectItem::IsEffectEnabled() const noexcept {
if (_IsRemoved()) {
return true;
}

return _Data().enabled;
}

void ScalingModeEffectItem::IsEffectEnabled(bool value) {
if (_IsRemoved()) {
return;
}

EffectItem& data = _Data();
if (data.enabled == value) {
return;
}

// 与删除效果一致,不阻止用户禁用全部效果;此时运行期会按空效果组报错
data.enabled = value;
RaisePropertyChanged(L"IsEffectEnabled");
RaisePropertyChanged(L"RowOpacity");
RaisePropertyChanged(L"ToggleToolTip");
AppSettings::Get().SaveAsync();
}

double ScalingModeEffectItem::RowOpacity() const noexcept {
return IsEffectEnabled() ? 1.0 : 0.45;
}

hstring ScalingModeEffectItem::ToggleToolTip() const noexcept {
ResourceLoader resourceLoader =
ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
return resourceLoader.GetString(IsEffectEnabled()
? L"ScalingModes_EffectDisable" : L"ScalingModes_EffectEnable");
}

void ScalingModeEffectItem::ToggleEnabled() {
IsEffectEnabled(!IsEffectEnabled());
}

IVector<IInspectable> ScalingModeEffectItem::ScalingTypes() noexcept {
using Windows::ApplicationModel::Resources::ResourceLoader;
ResourceLoader resourceLoader =
Expand Down
13 changes: 13 additions & 0 deletions src/Magpie/ScalingModeEffectItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ struct ScalingModeEffectItem : ScalingModeEffectItemT<ScalingModeEffectItem>,
bool HasParameters() const noexcept;
hstring IssueDescription() const noexcept;

// 临时禁用:效果保留在列表中,但不进入渲染链
bool IsEffectEnabled() const noexcept;
void IsEffectEnabled(bool value);

// 禁用时整行变暗
double RowOpacity() const noexcept;

// 悬停提示:当前启用则提示「禁用」,当前禁用则提示「启用」
hstring ToggleToolTip() const noexcept;

// 按钮点击:切换启用/禁用
void ToggleEnabled();

IVector<IInspectable> ScalingTypes() noexcept;

int ScalingType() const noexcept;
Expand Down
6 changes: 6 additions & 0 deletions src/Magpie/ScalingModeEffectItem.idl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace Magpie {
Boolean CanScale { get; };
Boolean HasParameters { get; };

Boolean IsEffectEnabled;
Double RowOpacity { get; };
String ToggleToolTip { get; };

void ToggleEnabled();

IVector<IInspectable> ScalingTypes { get; };
Int32 ScalingType;
Boolean IsShowScaleFactors { get; };
Expand Down
15 changes: 15 additions & 0 deletions src/Magpie/ScalingModesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
<local:SettingsCard Header="{x:Bind Name}"
Description="{x:Bind IssueDescription}"
Loaded="EffectSettingsCard_Loaded"
Opacity="{x:Bind RowOpacity, Mode=OneWay}"
Style="{StaticResource DefaultSettingsExpanderItemStyle}">
<local:SimpleStackPanel Orientation="Horizontal">
<local:SimpleStackPanel.Resources>
Expand All @@ -465,6 +466,20 @@
<Setter Property="FontSize" Value="15" />
</Style>
</local:SimpleStackPanel.Resources>
<Button Click="{x:Bind ToggleEnabled}"
Margin="0,0,4,0">
<ToolTipService.ToolTip>
<ToolTip Content="{x:Bind ToggleToolTip, Mode=OneWay}" />
</ToolTipService.ToolTip>
<Button.Content>
<Grid>
<FontIcon Glyph="&#xE890;"
Visibility="{x:Bind IsEffectEnabled, Mode=OneWay}" />
<FontIcon Glyph="&#xE711;"
Visibility="{x:Bind IsEffectEnabled, Mode=OneWay, Converter={StaticResource NegativeVisibilityConverter}}" />
</Grid>
</Button.Content>
</Button>
<Button x:Uid="ScalingModes_Scale"
Margin="0,0,4,0"
Visibility="{x:Bind CanScale}">
Expand Down
8 changes: 8 additions & 0 deletions src/Magpie/ScalingModesService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ static void WriteScalingMode(rapidjson::PrettyWriter<rapidjson::StringBuffer>& w
writer.String(effect.recoveryOriginal.data(), static_cast<rapidjson::SizeType>(effect.recoveryOriginal.size()));
}

// 只写非默认值,保持配置文件精简
if (!effect.enabled) {
writer.Key("enabled");
writer.Bool(false);
}

if (effect.HasScale()) {
writer.Key("scalingType");
writer.Uint((uint32_t)effect.scalingType);
Expand Down Expand Up @@ -240,6 +246,8 @@ static bool LoadScalingMode(
}
}
JsonHelper::ReadBool(elemObj, "recoveryInvalid", effect.isRecoveryInvalid);
// 缺失该键时保持默认值 true(启用)
JsonHelper::ReadBool(elemObj, "enabled", effect.enabled);
if (auto raw = elemObj.FindMember("recoveryOriginal"); raw != elemObj.MemberEnd() && raw->value.IsString())
effect.recoveryOriginal.assign(raw->value.GetString(), raw->value.GetStringLength());
// Frame Rate Filter used to live in the Utility folder. Keep existing
Expand Down
13 changes: 13 additions & 0 deletions src/Magpie/ScalingService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ ScalingError ScalingService::_StartScaleImpl(HWND hWnd, const Profile& profile,
return ScalingError::ScalingModeEmpty;
} else {
for (const EffectItem& effect : effects) {
// 被禁用的效果不参与渲染,即使文件缺失也不应阻止启动,
// 这样用户可以靠禁用来绕过损坏的效果器
if (!effect.enabled) {
continue;
}
if (effect.isRecoveryInvalid || !EffectsService::Get().GetEffect(effect.name)) {
// 存在无法解析的效果
return ScalingError::ScalingModeUnknownEffect;
Expand Down Expand Up @@ -409,8 +414,16 @@ ScalingError ScalingService::_StartScaleImpl(HWND hWnd, const Profile& profile,

options.effects.reserve(effects.size());
for (const EffectItem& effectItem : effects) {
// 被禁用的效果保留在配置里,但不进入渲染链
if (!effectItem.enabled) {
continue;
}
options.effects.push_back((EffectOption)effectItem);
}
if (options.effects.empty()) {
// 全部效果都被禁用,等价于效果组为空
return ScalingError::ScalingModeEmpty;
}

// 尝试启用触控支持
bool isTouchSupportEnabled;
Expand Down