-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGameSettingsFlyout.xaml.cs
119 lines (102 loc) · 4.04 KB
/
GameSettingsFlyout.xaml.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using MarkerMetro.Unity.WinIntegration.LocalNotifications;
using UnityProject.Config;
using MarkerMetro.Unity.WinShared;
// The Settings Flyout item template is documented at http://go.microsoft.com/fwlink/?LinkId=273769
namespace UnityProject.Win
{
public sealed partial class GameSettingsFlyout : SettingsFlyout
{
public GameSettingsFlyout()
{
this.InitializeComponent();
reminderSwitch.Visibility = AppConfig.Instance.NotificationsControlEnabled ?
Visibility.Visible : Visibility.Collapsed;
musicSwitch.Visibility = soundSwitch.Visibility = AppConfig.Instance.MusicFXControlEnabled ?
Visibility.Visible : Visibility.Collapsed;
// get the state of music/sound from the game
musicSwitch.IsOn = GameController.Instance.GameSettings.MusicEnabled;
soundSwitch.IsOn = GameController.Instance.GameSettings.SoundEnabled;
reminderSwitch.IsOn = GameController.Instance.GameSettings.RemindersEnabled;
this.Loaded += GameSettingsFlyout_Loaded;
this.Unloaded += GameSettingsFlyout_Unloaded;
}
bool inputDisableByThis;
void GameSettingsFlyout_Loaded(object sender, RoutedEventArgs e)
{
inputDisableByThis = true;
UnityPlayer.AppCallbacks.Instance.UnitySetInput(false);
var parent = Parent as Popup;
if (parent != null)
parent.Closed += parent_Closed;
}
void parent_Closed(object sender, object e)
{
if (inputDisableByThis)
{
inputDisableByThis = false;
UnityPlayer.AppCallbacks.Instance.UnitySetInput(true);
}
}
void GameSettingsFlyout_Unloaded(object sender, RoutedEventArgs e)
{
if (inputDisableByThis)
{
inputDisableByThis = false;
UnityPlayer.AppCallbacks.Instance.UnitySetInput(true);
}
}
public void ActivateSound(bool active)
{
// if clause to not play the sound when GameSettingsFlyout is constructed.
if (GameController.Instance.GameSettings.SoundEnabled != active)
{
GameController.Instance.GameSettings.SoundEnabled = active;
}
}
public void ActivateMusic(bool active)
{
// if clause to not play the sound when GameSettingsFlyout is constructed.
if (GameController.Instance.GameSettings.MusicEnabled != active)
{
GameController.Instance.GameSettings.MusicEnabled = active;
}
}
public void ActivateReminder(bool active)
{
if (GameController.Instance.GameSettings.RemindersEnabled != active)
{
GameController.Instance.GameSettings.RemindersEnabled = active;
}
}
void musicSwitch_Toggled(object sender, RoutedEventArgs e)
{
var value = musicSwitch.IsOn;
UnityPlayer.AppCallbacks.Instance.InvokeOnAppThread(() => ActivateMusic(value), false);
}
void soundSwitch_Toggled(object sender, RoutedEventArgs e)
{
var value = soundSwitch.IsOn;
UnityPlayer.AppCallbacks.Instance.InvokeOnAppThread(() => ActivateSound(value), false);
}
void reminderSwitch_Toggled(object sender, RoutedEventArgs e)
{
var value = reminderSwitch.IsOn;
UnityPlayer.AppCallbacks.Instance.InvokeOnAppThread(() => ActivateReminder(value), false);
}
}
}