aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx/UI/Views/User/UserSelectorView.axaml.cs
blob: fa3383aa9c01b2b825691cb8f778c89382cbb886 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using FluentAvalonia.UI.Controls;
using FluentAvalonia.UI.Navigation;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Controls;
using Ryujinx.Ava.UI.Models;
using Ryujinx.Ava.UI.ViewModels;
using Button = Avalonia.Controls.Button;

namespace Ryujinx.Ava.UI.Views.User
{
    public partial class UserSelectorViews : UserControl
    {
        private NavigationDialogHost _parent;

        public UserProfileViewModel ViewModel { get; set; }

        public UserSelectorViews()
        {
            InitializeComponent();

            if (Program.PreviewerDetached)
            {
                AddHandler(Frame.NavigatedToEvent, (s, e) =>
                {
                    NavigatedTo(e);
                }, RoutingStrategies.Direct);
            }
        }

        private void NavigatedTo(NavigationEventArgs arg)
        {
            if (Program.PreviewerDetached)
            {
                if (arg.NavigationMode == NavigationMode.New)
                {
                    _parent = (NavigationDialogHost)arg.Parameter;
                    ViewModel = _parent.ViewModel;
                }

                if (arg.NavigationMode == NavigationMode.Back)
                {
                    ((ContentDialog)_parent.Parent).Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle];
                }

                DataContext = ViewModel;
            }
        }

        private void Grid_PointerEntered(object sender, PointerEventArgs e)
        {
            if (sender is Grid grid)
            {
                if (grid.DataContext is UserProfile profile)
                {
                    profile.IsPointerOver = true;
                }
            }
        }

        private void Grid_OnPointerExited(object sender, PointerEventArgs e)
        {
            if (sender is Grid grid)
            {
                if (grid.DataContext is UserProfile profile)
                {
                    profile.IsPointerOver = false;
                }
            }
        }

        private void ProfilesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender is ListBox listBox)
            {
                int selectedIndex = listBox.SelectedIndex;

                if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
                {
                    if (ViewModel.Profiles[selectedIndex] is UserProfile userProfile)
                    {
                        _parent?.AccountManager?.OpenUser(userProfile.UserId);

                        foreach (BaseModel profile in ViewModel.Profiles)
                        {
                            if (profile is UserProfile uProfile)
                            {
                                uProfile.UpdateState();
                            }
                        }
                    }
                }
            }
        }

        private void AddUser(object sender, RoutedEventArgs e)
        {
            _parent.AddUser();
        }

        private void EditUser(object sender, RoutedEventArgs e)
        {
            if (sender is Button button)
            {
                if (button.DataContext is UserProfile userProfile)
                {
                    _parent.EditUser(userProfile);
                }
            }
        }

        private void ManageSaves(object sender, RoutedEventArgs e)
        {
            _parent.ManageSaves();
        }

        private void RecoverLostAccounts(object sender, RoutedEventArgs e)
        {
            _parent.RecoverLostAccounts();
        }

        private void Close(object sender, RoutedEventArgs e)
        {
            ((ContentDialog)_parent.Parent).Hide();
        }
    }
}