From 4e72ecaf95d71e56a43c6c6e2c97fe457487bd49 Mon Sep 17 00:00:00 2001 From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:09:24 +0000 Subject: [PATCH] add a scam warning to the flag editor --- Bloxstrap/Models/Persistable/State.cs | 2 +- Bloxstrap/Resources/Strings.Designer.cs | 20 +++++++ Bloxstrap/Resources/Strings.resx | 8 +++ .../UI/Elements/Settings/MainWindow.xaml | 1 + .../Pages/FastFlagEditorScamWarningPage.xaml | 52 +++++++++++++++++++ .../FastFlagEditorScamWarningPage.xaml.cs | 22 ++++++++ .../Pages/FastFlagEditorWarningBase.cs | 43 +++++++++++++++ .../Pages/FastFlagEditorWarningPage.xaml | 6 +-- .../Pages/FastFlagEditorWarningPage.xaml.cs | 23 +------- .../Settings/Pages/FastFlagsPage.xaml.cs | 2 +- .../FastFlagEditorWarningViewModel.cs | 38 +++++++++++--- 11 files changed, 183 insertions(+), 34 deletions(-) create mode 100644 Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml create mode 100644 Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml.cs create mode 100644 Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningBase.cs diff --git a/Bloxstrap/Models/Persistable/State.cs b/Bloxstrap/Models/Persistable/State.cs index de05265..82f1df5 100644 --- a/Bloxstrap/Models/Persistable/State.cs +++ b/Bloxstrap/Models/Persistable/State.cs @@ -2,7 +2,7 @@ { public class State { - public bool ShowFFlagEditorWarning { get; set; } = true; + public bool ShowFFlagEditorWarnings { get; set; } = true; public bool PromptWebView2Install { get; set; } = true; diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index 0201300..22176bd 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -2318,6 +2318,26 @@ namespace Bloxstrap.Resources { } } + /// + /// Looks up a localized string similar to If you bought fast flags, you have been scammed. + /// + ///Ask for your money back immediately.. + /// + public static string Menu_FastFlagEditor_ScamWarning_Text { + get { + return ResourceManager.GetString("Menu.FastFlagEditor.ScamWarning.Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Scam Warning. + /// + public static string Menu_FastFlagEditor_ScamWarning_Title { + get { + return ResourceManager.GetString("Menu.FastFlagEditor.ScamWarning.Title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Search. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index aea14a5..59520dd 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1271,4 +1271,12 @@ Please close any applications that may be using Roblox's files, and relaunch.All Bloxstrap logs Label that appears next to a checkbox + + If you bought fast flags, you have been scammed. + +Ask for your money back immediately. + + + Scam Warning + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/Settings/MainWindow.xaml b/Bloxstrap/UI/Elements/Settings/MainWindow.xaml index b1f7e2d..6d97b16 100644 --- a/Bloxstrap/UI/Elements/Settings/MainWindow.xaml +++ b/Bloxstrap/UI/Elements/Settings/MainWindow.xaml @@ -62,6 +62,7 @@ + diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml new file mode 100644 index 0000000..9a1554d --- /dev/null +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml.cs b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml.cs new file mode 100644 index 0000000..2166153 --- /dev/null +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorScamWarningPage.xaml.cs @@ -0,0 +1,22 @@ +using Bloxstrap.UI.ViewModels.Settings; +using System.Windows; + +namespace Bloxstrap.UI.Elements.Settings.Pages +{ + /// + /// Interaction logic for FastFlagEditorScamWarningPage.xaml + /// + public partial class FastFlagEditorScamWarningPage + { + public FastFlagEditorScamWarningPage() : base(typeof(FastFlagEditorPage)) + { + InitializeComponent(); + } + + protected override void ContinueCallback() + { + App.State.Prop.ShowFFlagEditorWarnings = false; + App.State.Save(); // should we be force saving? + } + } +} diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningBase.cs b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningBase.cs new file mode 100644 index 0000000..00aa63b --- /dev/null +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningBase.cs @@ -0,0 +1,43 @@ +using Bloxstrap.UI.ViewModels.Settings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Wpf.Ui.Controls; + +namespace Bloxstrap.UI.Elements.Settings.Pages +{ + public class FastFlagEditorWarningBase : UiPage + { + private bool _initialLoad = false; + + protected FastFlagEditorWarningBase(Type nextPageType) + { + Loaded += Page_Loaded; + + var vm = new FastFlagEditorWarningViewModel(this, nextPageType, ContinueCallback); + DataContext = vm; + vm.StartCountdown(); + } + + protected virtual void ContinueCallback() + { + } + + private void Page_Loaded(object sender, RoutedEventArgs e) + { + // refresh datacontext on page load to reset timer + + if (!_initialLoad) + { + _initialLoad = true; + return; + } + + ((FastFlagEditorWarningViewModel)DataContext).StartCountdown(); + } + } +} diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml index 9a2b938..e2878af 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml @@ -1,15 +1,15 @@ - @@ -22,4 +22,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs index 89d1e4c..5774de2 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs @@ -1,32 +1,13 @@ -using Bloxstrap.UI.ViewModels.Settings; -using System.Windows; - -namespace Bloxstrap.UI.Elements.Settings.Pages +namespace Bloxstrap.UI.Elements.Settings.Pages { /// /// Interaction logic for FastFlagEditorWarningPage.xaml /// public partial class FastFlagEditorWarningPage { - private bool _initialLoad = false; - - public FastFlagEditorWarningPage() + public FastFlagEditorWarningPage() : base(typeof(FastFlagEditorScamWarningPage)) { - DataContext = new FastFlagEditorWarningViewModel(this); InitializeComponent(); } - - private void Page_Loaded(object sender, RoutedEventArgs e) - { - // refresh datacontext on page load to reset timer - - if (!_initialLoad) - { - _initialLoad = true; - return; - } - - DataContext = new FastFlagEditorWarningViewModel(this); - } } } diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagsPage.xaml.cs b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagsPage.xaml.cs index 63b3ada..43057b2 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagsPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagsPage.xaml.cs @@ -35,7 +35,7 @@ namespace Bloxstrap.UI.Elements.Settings.Pages { if (Window.GetWindow(this) is INavigationWindow window) { - if (App.State.Prop.ShowFFlagEditorWarning) + if (App.State.Prop.ShowFFlagEditorWarnings) window.Navigate(typeof(FastFlagEditorWarningPage)); else window.Navigate(typeof(FastFlagEditorPage)); diff --git a/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs b/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs index c335d35..c5ea018 100644 --- a/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs @@ -12,6 +12,10 @@ namespace Bloxstrap.UI.ViewModels.Settings internal class FastFlagEditorWarningViewModel : NotifyPropertyChangedViewModel { private Page _page; + private Type _nextPageType; + private Action _continueCallback; + + private CancellationTokenSource? _cancellationTokenSource; public string ContinueButtonText { get; set; } = ""; @@ -21,20 +25,39 @@ namespace Bloxstrap.UI.ViewModels.Settings public ICommand ContinueCommand => new RelayCommand(Continue); - public FastFlagEditorWarningViewModel(Page page) + public FastFlagEditorWarningViewModel(Page page, Type nextPageType, Action continueCallback) { _page = page; - DoCountdown(); + _nextPageType = nextPageType; + _continueCallback = continueCallback; } - private async void DoCountdown() + public void StartCountdown() { + _cancellationTokenSource?.Cancel(); + + _cancellationTokenSource = new CancellationTokenSource(); + DoCountdown(_cancellationTokenSource.Token); + } + + private async void DoCountdown(CancellationToken token) + { + CanContinue = false; + OnPropertyChanged(nameof(CanContinue)); + for (int i = 10; i > 0; i--) { ContinueButtonText = $"({i}) {Strings.Menu_FastFlagEditor_Warning_Continue}"; OnPropertyChanged(nameof(ContinueButtonText)); - await Task.Delay(1000); + try + { + await Task.Delay(1000, token); + } + catch (TaskCanceledException) + { + return; + } } ContinueButtonText = Strings.Menu_FastFlagEditor_Warning_Continue; @@ -42,9 +65,6 @@ namespace Bloxstrap.UI.ViewModels.Settings CanContinue = true; OnPropertyChanged(nameof(CanContinue)); - - App.State.Prop.ShowFFlagEditorWarning = false; - App.State.Save(); } private void Continue() @@ -52,8 +72,10 @@ namespace Bloxstrap.UI.ViewModels.Settings if (!CanContinue) return; + _continueCallback(); + if (Window.GetWindow(_page) is INavigationWindow window) - window.Navigate(typeof(FastFlagEditorPage)); + window.Navigate(_nextPageType); } private void GoBack()