Skip to content

Commit

Permalink
feat: 高级选项移到主页
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Apr 25, 2024
1 parent 893557f commit f134aba
Show file tree
Hide file tree
Showing 28 changed files with 727 additions and 711 deletions.
5 changes: 5 additions & 0 deletions src/Magpie.App/HomePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "HomePage.g.cpp"
#endif
#include "XamlUtils.h"
#include "ComboBoxHelper.h"

namespace winrt::Magpie::App::implementation {

Expand All @@ -12,4 +13,8 @@ void HomePage::TimerSlider_Loaded(IInspectable const& sender, RoutedEventArgs co
XamlUtils::UpdateThemeOfTooltips(sender.as<Controls::Slider>(), ActualTheme());
}

void HomePage::ComboBox_DropDownOpened(IInspectable const& sender, IInspectable const&) const {
ComboBoxHelper::DropDownOpened(*this, sender);
}

}
2 changes: 2 additions & 0 deletions src/Magpie.App/HomePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct HomePage : HomePageT<HomePage> {
return _viewModel;
}

void ComboBox_DropDownOpened(IInspectable const& sender, IInspectable const&) const;

private:
Magpie::App::HomeViewModel _viewModel;
};
Expand Down
86 changes: 80 additions & 6 deletions src/Magpie.App/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</local:SettingsCard>
</local:SettingsGroup>
<local:SettingsGroup x:Uid="Home_Activation">
<local:SettingsExpander x:Uid="Home_Timer">
<local:SettingsExpander x:Uid="Home_Activation_Timer">
<local:SettingsExpander.HeaderIcon>
<FontIcon Glyph="&#xE916;" />
</local:SettingsExpander.HeaderIcon>
Expand All @@ -86,7 +86,7 @@
</local:SimpleStackPanel>
</local:SettingsExpander.Content>
<local:SettingsExpander.Items>
<local:SettingsCard x:Uid="Home_Timer_Delay">
<local:SettingsCard x:Uid="Home_Activation_Timer_Delay">
<Slider Loaded="TimerSlider_Loaded"
Maximum="5"
Minimum="1"
Expand All @@ -96,15 +96,15 @@
</local:SettingsExpander.Items>
</local:SettingsExpander>
<Grid>
<local:SettingsCard x:Uid="Home_AutoRestore"
<local:SettingsCard x:Uid="Home_Activation_AutoRestore"
Visibility="{x:Bind ViewModel.IsWndToRestore, Mode=OneWay, Converter={StaticResource NegativeVisibilityConverter}}">
<local:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xE944;" />
</local:SettingsCard.HeaderIcon>
<ToggleSwitch x:Uid="ToggleSwitch"
IsOn="{x:Bind ViewModel.IsAutoRestore, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsExpander x:Uid="Home_AutoRestore"
<local:SettingsExpander x:Uid="Home_Activation_AutoRestore"
IsExpanded="{x:Bind ViewModel.IsWndToRestore, Mode=OneWay}"
Visibility="{x:Bind ViewModel.IsWndToRestore, Mode=OneWay}">
<local:SettingsExpander.HeaderIcon>
Expand All @@ -118,16 +118,90 @@
<local:SettingsCard Header="{x:Bind ViewModel.RestoreWndDesc, Mode=OneWay}">
<local:SimpleStackPanel Orientation="Horizontal"
Spacing="8">
<Button x:Uid="Home_AutoRestore_Activate"
<Button x:Uid="Home_Activation_AutoRestore_Activate"
Click="{x:Bind ViewModel.ActivateRestore}"
Style="{StaticResource AccentButtonStyle}" />
<Button x:Uid="Home_AutoRestore_Clear"
<Button x:Uid="Home_Activation_AutoRestore_Clear"
Click="{x:Bind ViewModel.ClearRestore}" />
</local:SimpleStackPanel>
</local:SettingsCard>
</local:SettingsExpander.Items>
</local:SettingsExpander>
</Grid>
<local:SettingsCard x:Uid="Home_Activation_AllowScalingMaximized">
<ToggleSwitch x:Uid="ToggleSwitch"
IsOn="{x:Bind ViewModel.IsAllowScalingMaximized, Mode=TwoWay}" />
</local:SettingsCard>
</local:SettingsGroup>
<local:SettingsGroup x:Uid="Home_Advanced">
<local:SettingsCard x:Uid="Home_Advanced_EnableTouchSupport">
<local:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xEBFC;" />
</local:SettingsCard.HeaderIcon>
<ToggleSwitch x:Uid="ToggleSwitch" />
</local:SettingsCard>
<local:SettingsCard x:Uid="Home_Advanced_InlineParams">
<local:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xE9E9;" />
</local:SettingsCard.HeaderIcon>
<ToggleSwitch x:Uid="ToggleSwitch"
IsOn="{x:Bind ViewModel.IsInlineParams, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsCard x:Uid="Home_Advanced_SimulateExclusiveFullscreen">
<local:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xec46;" />
</local:SettingsCard.HeaderIcon>
<ToggleSwitch x:Uid="ToggleSwitch"
IsOn="{x:Bind ViewModel.IsSimulateExclusiveFullscreen, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsExpander x:Name="DeveloperModeExpander"
x:Uid="Home_Advanced_DeveloperOptions"
x:Load="{x:Bind ViewModel.IsDeveloperMode, Mode=OneWay}"
IsExpanded="True">
<local:SettingsExpander.HeaderIcon>
<FontIcon Glyph="&#xEC7A;" />
</local:SettingsExpander.HeaderIcon>
<local:SettingsExpander.Content>
<ToggleSwitch x:Uid="ToggleSwitch"
IsOn="{x:Bind ViewModel.IsDeveloperMode, Mode=TwoWay}" />
</local:SettingsExpander.Content>
<local:SettingsExpander.Items>
<local:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="Home_Advanced_DeveloperOptions_DebugMode"
IsChecked="{x:Bind ViewModel.IsDebugMode, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="Home_Advanced_DeveloperOptions_DisableEffectCache"
IsChecked="{x:Bind ViewModel.IsEffectCacheDisabled, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="Home_Advanced_DeveloperOptions_DisableFontCache"
IsChecked="{x:Bind ViewModel.IsFontCacheDisabled, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="Home_Advanced_DeveloperOptions_SaveEffectSources"
IsChecked="{x:Bind ViewModel.IsSaveEffectSources, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsCard ContentAlignment="Left">
<CheckBox x:Uid="Home_Advanced_DeveloperOptions_WarningsAreErrors"
IsChecked="{x:Bind ViewModel.IsWarningsAreErrors, Mode=TwoWay}" />
</local:SettingsCard>
<local:SettingsCard x:Uid="Home_Advanced_DeveloperOptions_DuplicateFrameDetection"
IsWrapEnabled="True">
<ComboBox DropDownOpened="ComboBox_DropDownOpened"
SelectedIndex="{x:Bind ViewModel.DuplicateFrameDetectionMode, Mode=TwoWay}">
<ComboBoxItem x:Uid="Home_Advanced_DeveloperOptions_DuplicateFrameDetection_Always" />
<ComboBoxItem x:Uid="Home_Advanced_DeveloperOptions_DuplicateFrameDetection_Dynamic" />
<ComboBoxItem x:Uid="Home_Advanced_DeveloperOptions_DuplicateFrameDetection_Never" />
</ComboBox>
</local:SettingsCard>
<local:SettingsCard ContentAlignment="Left"
IsEnabled="{x:Bind ViewModel.IsDynamicDection, Mode=OneWay}">
<CheckBox x:Uid="Home_Advanced_DeveloperOptions_EnableStatisticsForDynamicDetection"
IsChecked="{x:Bind ViewModel.IsStatisticsForDynamicDetectionEnabled, Mode=TwoWay}" />
</local:SettingsCard>
</local:SettingsExpander.Items>
</local:SettingsExpander>
</local:SettingsGroup>
</local:SimpleStackPanel>
</local:PageFrame>
Expand Down
186 changes: 182 additions & 4 deletions src/Magpie.App/HomeViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ hstring HomeViewModel::TimerButtonText() const noexcept {
ResourceLoader resourceLoader =
ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
if (ScalingService.IsTimerOn()) {
return resourceLoader.GetString(L"Home_Timer_Cancel");
return resourceLoader.GetString(L"Home_Activation_Timer_Cancel");
} else {
hstring fmtStr = resourceLoader.GetString(L"Home_Timer_ButtonText");
hstring fmtStr = resourceLoader.GetString(L"Home_Activation_Timer_ButtonText");
return hstring(fmt::format(
fmt::runtime(std::wstring_view(fmtStr)),
AppSettings::Get().CountdownSeconds()
Expand Down Expand Up @@ -129,9 +129,9 @@ hstring HomeViewModel::RestoreWndDesc() const noexcept {

ResourceLoader resourceLoader =
ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
hstring curWindow = resourceLoader.GetString(L"Home_AutoRestore_CurWindow");
hstring curWindow = resourceLoader.GetString(L"Home_Activation_AutoRestore_CurWindow");
if (title.empty()) {
hstring emptyTitle = resourceLoader.GetString(L"Home_AutoRestore_EmptyTitle");
hstring emptyTitle = resourceLoader.GetString(L"Home_Activation_AutoRestore_EmptyTitle");
return hstring(StrUtils::Concat(curWindow, L"<", emptyTitle, L">"));
} else {
return curWindow + title;
Expand Down Expand Up @@ -185,6 +185,184 @@ void HomeViewModel::RemindMeLater() {
ShowUpdateCard(false);
}

bool HomeViewModel::IsAllowScalingMaximized() const noexcept {
return AppSettings::Get().IsAllowScalingMaximized();
}

void HomeViewModel::IsAllowScalingMaximized(bool value) {
AppSettings::Get().IsAllowScalingMaximized(value);

if (value) {
ScalingService::Get().CheckForeground();
}
}

bool HomeViewModel::IsInlineParams() const noexcept {
return AppSettings::Get().IsInlineParams();
}

void HomeViewModel::IsInlineParams(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsInlineParams() == value) {
return;
}

settings.IsInlineParams(value);
RaisePropertyChanged(L"IsInlineParams");
}

bool HomeViewModel::IsSimulateExclusiveFullscreen() const noexcept {
return AppSettings::Get().IsSimulateExclusiveFullscreen();
}

void HomeViewModel::IsSimulateExclusiveFullscreen(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsSimulateExclusiveFullscreen() == value) {
return;
}

settings.IsSimulateExclusiveFullscreen(value);
RaisePropertyChanged(L"IsSimulateExclusiveFullscreen");
}

bool HomeViewModel::IsDeveloperMode() const noexcept {
return AppSettings::Get().IsDeveloperMode();
}

void HomeViewModel::IsDeveloperMode(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsDeveloperMode() == value) {
return;
}

settings.IsDeveloperMode(value);
RaisePropertyChanged(L"IsDeveloperMode");
}

bool HomeViewModel::IsDebugMode() const noexcept {
return AppSettings::Get().IsDebugMode();
}

void HomeViewModel::IsDebugMode(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsDebugMode() == value) {
return;
}

settings.IsDebugMode(value);
RaisePropertyChanged(L"IsDebugMode");
}

bool HomeViewModel::IsEffectCacheDisabled() const noexcept {
return AppSettings::Get().IsEffectCacheDisabled();
}

void HomeViewModel::IsEffectCacheDisabled(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsEffectCacheDisabled() == value) {
return;
}

settings.IsEffectCacheDisabled(value);
RaisePropertyChanged(L"IsEffectCacheDisabled");
}

bool HomeViewModel::IsFontCacheDisabled() const noexcept {
return AppSettings::Get().IsFontCacheDisabled();
}

void HomeViewModel::IsFontCacheDisabled(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsFontCacheDisabled() == value) {
return;
}

settings.IsFontCacheDisabled(value);
RaisePropertyChanged(L"IsFontCacheDisabled");
}

bool HomeViewModel::IsSaveEffectSources() const noexcept {
return AppSettings::Get().IsSaveEffectSources();
}

void HomeViewModel::IsSaveEffectSources(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsSaveEffectSources() == value) {
return;
}

settings.IsSaveEffectSources(value);
RaisePropertyChanged(L"IsSaveEffectSources");
}

bool HomeViewModel::IsWarningsAreErrors() const noexcept {
return AppSettings::Get().IsWarningsAreErrors();
}

void HomeViewModel::IsWarningsAreErrors(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsWarningsAreErrors() == value) {
return;
}

settings.IsWarningsAreErrors(value);
RaisePropertyChanged(L"IsWarningsAreErrors");
}

int HomeViewModel::DuplicateFrameDetectionMode() const noexcept {
return (int)AppSettings::Get().DuplicateFrameDetectionMode();
}

void HomeViewModel::DuplicateFrameDetectionMode(int value) {
if (value < 0) {
return;
}

const auto mode = (::Magpie::Core::DuplicateFrameDetectionMode)value;

AppSettings& settings = AppSettings::Get();
if (settings.DuplicateFrameDetectionMode() == mode) {
return;
}

settings.DuplicateFrameDetectionMode(mode);

RaisePropertyChanged(L"DuplicateFrameDetectionMode");
RaisePropertyChanged(L"IsDynamicDection");

if (mode != ::Magpie::Core::DuplicateFrameDetectionMode::Dynamic) {
settings.IsStatisticsForDynamicDetectionEnabled(false);
RaisePropertyChanged(L"IsStatisticsForDynamicDetectionEnabled");
}
}

bool HomeViewModel::IsDynamicDection() const noexcept {
return AppSettings::Get().DuplicateFrameDetectionMode() == ::Magpie::Core::DuplicateFrameDetectionMode::Dynamic;
}

bool HomeViewModel::IsStatisticsForDynamicDetectionEnabled() const noexcept {
return AppSettings::Get().IsStatisticsForDynamicDetectionEnabled();
}

void HomeViewModel::IsStatisticsForDynamicDetectionEnabled(bool value) {
AppSettings& settings = AppSettings::Get();

if (settings.IsStatisticsForDynamicDetectionEnabled() == value) {
return;
}

settings.IsStatisticsForDynamicDetectionEnabled(value);
RaisePropertyChanged(L"IsStatisticsForDynamicDetectionEnabled");
}

void HomeViewModel::_ScalingService_IsTimerOnChanged(bool value) {
if (!value) {
RaisePropertyChanged(L"TimerProgressRingValue");
Expand Down
Loading

0 comments on commit f134aba

Please sign in to comment.