The game can be adjusted to user needs by a few settings, including a player name, music volume, or a consent to send the player location to the external web service. The design of the Settings screen is specified in the SettingsPage.xaml
file. The main layout of the screen is similar to the previous ones, however, it contains two controls that have not been described yet, the Slider
and Checkbox
controls.
The Slider
control makes it possible to select a value from a specified range by moving the indicator placed on the line. You can specify the current value, as well as the minimum and maximum ones using the Value
, Minimum
, and Maximum
properties respectively. The Slider
control supports the ValueChanged
event that is fired whenever a chosen value is modified, that is, when the user moves the indicator. You can also bind its value to some property, as shown in the following code. By using the two-way mode, the source property (for example, Volume
in SettingsViewModel
) always stores the current value:
<Slider (...) Minimum="0.0" Maximum="1.0" Value="{Binding Volume, Mode=TwoWay}" (...) />
The CheckBox
control can be used for presenting a logical value. It is a small rectangle that can be checked or unchecked by the user. Similarly to the Slider
control, it can be adjusted by properties. The CheckBox
control supports the Checked
and Unchecked
events. The first event is fired when the box is checked, and the second one when it is unchecked. You can easily bind the IsChecked
property to a Boolean value, as shown in the following code:
<CheckBox (...) IsChecked="{Binding Vibrations, Mode=TwoWay}" />
Currently, the
Settings screen should contain the TextBox
(with a user name), Slider
(music volume), and two CheckBox
controls (a consent to using vibrations and sending location data). Fortunately, you do not need to add events for any of these elements, because you can bind their properties to the view model (the Name
, Volume
, Vibrations
, and UseLocation
properties) in the two-way mode. Thus, you can easily access the current values of the settings using the view model.
The view also contains the Button
element. When the player clicks on it, the website with privacy policy should be presented. Thus, you specify the command (CmdPrivacyPolicy
), which is executed in such a scenario.
Apart from the view, the Settings screen requires an additional class in the model, which performs the operation of opening the website in the web browser from the Windows Phone 8. It can be implemented in the GameHelpers
static class, which will contain a few auxiliary methods for performing operations common for many screens.
Currently you will add the OpenWebsite
method that takes an address as a parameter, as follows:
public static class GameHelpers { public const string PROJECT_WEBSITE = "http://jamro.biz/spaceaim3d/"; public static void OpenWebsite(string link) { WebBrowserTask wbt = new WebBrowserTask(); wbt.Uri = new Uri(link, UriKind.Absolute); wbt.Show(); } }
Opening the website can be performed using the WebBrowserTask
class. You specify the address of the website that should be opened, by setting a suitable value for the Uri
property to an instance of the Uri
class. Its constructor takes two parameters, an address and a type of URI. The web browser is automatically started after calling the Show
method. The GameHelpers
class also contains the public constant field PROJECT_WEBSITE
, which stores an address of the project website (http://jamro.biz/spaceaim3d/ in the example).
You should also prepare the simple implementation of the SettingsViewModel
class, which is very similar to the view models presented earlier. It contains four constant fields, with default settings (NAME_DEFAULT
, VOLUME_DEFAULT
, VIBRATIONS_DEFAULT
, and LOCATION_DEFAULT
) and four properties, together with private fields, representing particular options (Name
, Volume
, Vibrations
, and UseLocation
). Apart from them, the class is equipped with the CmdPrivacyPolicy
command, a constructor, and a private method that is called when the command is executed. The latter is shown in the following code snippet:
private void OpenPrivacyPolicy()
{
GameHelpers.OpenWebsite(GameHelpers.PROJECT_WEBSITE);
}
An implementation of the method consists of calling the OpenWebsite
static method from the GameHelpers
class.
18.119.159.178