aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs
blob: c650fe0363e1bebb1cea6da6feb7fc30049d346f (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
using System;

namespace Ryujinx.HLE.HOS.SystemState
{
    public class SystemStateMgr
    {
        internal static string[] LanguageCodes = {
            "ja",
            "en-US",
            "fr",
            "de",
            "it",
            "es",
            "zh-CN",
            "ko",
            "nl",
            "pt",
            "ru",
            "zh-TW",
            "en-GB",
            "fr-CA",
            "es-419",
            "zh-Hans",
            "zh-Hant",
            "pt-BR",
        };

        internal long DesiredKeyboardLayout { get; private set; }

        internal SystemLanguage DesiredSystemLanguage { get; private set; }

        internal long DesiredLanguageCode { get; private set; }

        internal uint DesiredRegionCode { get; private set; }

        public TitleLanguage DesiredTitleLanguage { get; private set; }

        public bool DockedMode { get; set; }

        public ColorSet ThemeColor { get; set; }

        public string DeviceNickName { get; set; }

        public SystemStateMgr()
        {
            // TODO: Let user specify fields.
            DesiredKeyboardLayout = (long)KeyboardLayout.Default;
            DeviceNickName = "Ryujinx's Switch";
        }

        public void SetLanguage(SystemLanguage language)
        {
            DesiredSystemLanguage = language;
            DesiredLanguageCode = GetLanguageCode((int)DesiredSystemLanguage);

            DesiredTitleLanguage = language switch
            {
                SystemLanguage.Taiwanese or
                SystemLanguage.TraditionalChinese => TitleLanguage.TraditionalChinese,
                SystemLanguage.Chinese or
                SystemLanguage.SimplifiedChinese => TitleLanguage.SimplifiedChinese,
                _ => Enum.Parse<TitleLanguage>(Enum.GetName<SystemLanguage>(language)),
            };
        }

        public void SetRegion(RegionCode region)
        {
            DesiredRegionCode = (uint)region;
        }

        internal static long GetLanguageCode(int index)
        {
            if ((uint)index >= LanguageCodes.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            long code = 0;
            int shift = 0;

            foreach (char chr in LanguageCodes[index])
            {
                code |= (long)(byte)chr << shift++ * 8;
            }

            return code;
        }
    }
}