Added a dice roller leveraging true randomness from random.org API.
This commit is contained in:
53
osrs-toolbox/Models/DiceRollerModel.cs
Normal file
53
osrs-toolbox/Models/DiceRollerModel.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace osrs_toolbox
|
||||||
|
{
|
||||||
|
public abstract class DiceRollerModel : ModelBase
|
||||||
|
{
|
||||||
|
private int _minValue;
|
||||||
|
private int _maxValue;
|
||||||
|
private int _numRolls;
|
||||||
|
private bool _allowDuplicates;
|
||||||
|
private string _rollResults;
|
||||||
|
|
||||||
|
private ICommand _rollDice;
|
||||||
|
|
||||||
|
public int MinValue
|
||||||
|
{
|
||||||
|
get { return _minValue; }
|
||||||
|
set { SetProperty(ref _minValue, value, nameof(MinValue)); }
|
||||||
|
}
|
||||||
|
public int MaxValue
|
||||||
|
{
|
||||||
|
get { return _maxValue; }
|
||||||
|
set { SetProperty(ref _maxValue, value, nameof(MaxValue)); }
|
||||||
|
}
|
||||||
|
public int NumRolls
|
||||||
|
{
|
||||||
|
get { return _numRolls; }
|
||||||
|
set { SetProperty(ref _numRolls, value, nameof(NumRolls)); }
|
||||||
|
}
|
||||||
|
public bool AllowDuplicates
|
||||||
|
{
|
||||||
|
get { return _allowDuplicates; }
|
||||||
|
set { SetProperty(ref _allowDuplicates, value, nameof(AllowDuplicates)); }
|
||||||
|
}
|
||||||
|
public string RollResults
|
||||||
|
{
|
||||||
|
get { return _rollResults; }
|
||||||
|
set { SetProperty(ref _rollResults, value, nameof(RollResults)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICommand RollDice
|
||||||
|
{
|
||||||
|
get { return _rollDice; }
|
||||||
|
set { SetProperty(ref _rollDice, value, nameof(RollDice)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -16,6 +16,7 @@ namespace osrs_toolbox
|
|||||||
private ICommand _openCombatLevelCalculator;
|
private ICommand _openCombatLevelCalculator;
|
||||||
private ICommand _openShopBuyoutCalculator;
|
private ICommand _openShopBuyoutCalculator;
|
||||||
private ICommand _openAPITest;
|
private ICommand _openAPITest;
|
||||||
|
private ICommand _openDiceRoller;
|
||||||
|
|
||||||
public ICommand OpenCompetitionOverlaySettings
|
public ICommand OpenCompetitionOverlaySettings
|
||||||
{
|
{
|
||||||
@@ -44,5 +45,10 @@ namespace osrs_toolbox
|
|||||||
get { return _openAPITest; }
|
get { return _openAPITest; }
|
||||||
set { SetProperty(ref _openAPITest, value, nameof(OpenAPITest)); }
|
set { SetProperty(ref _openAPITest, value, nameof(OpenAPITest)); }
|
||||||
}
|
}
|
||||||
|
public ICommand OpenDiceRoller
|
||||||
|
{
|
||||||
|
get { return _openDiceRoller; }
|
||||||
|
set { SetProperty(ref _openDiceRoller, value, nameof(OpenDiceRoller)); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
45
osrs-toolbox/ViewModels/DiceRollerViewModel.cs
Normal file
45
osrs-toolbox/ViewModels/DiceRollerViewModel.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace osrs_toolbox
|
||||||
|
{
|
||||||
|
public class DiceRollerViewModel : DiceRollerModel
|
||||||
|
{
|
||||||
|
public DiceRollerViewModel()
|
||||||
|
{
|
||||||
|
InitializeVariables();
|
||||||
|
InitializeCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeVariables()
|
||||||
|
{
|
||||||
|
MinValue = 0;
|
||||||
|
MaxValue = 100;
|
||||||
|
NumRolls = 1;
|
||||||
|
AllowDuplicates = true;
|
||||||
|
RollResults = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeCommands()
|
||||||
|
{
|
||||||
|
RollDice = new RelayCommand(DoRollDice);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void DoRollDice(object obj)
|
||||||
|
{
|
||||||
|
RollResults = "Rolling Dice...";
|
||||||
|
await Task.Delay(10);
|
||||||
|
int[] Rolls = await Random.GetRandomIntegersAsync(MinValue, MaxValue, NumRolls, AllowDuplicates).ConfigureAwait(false);
|
||||||
|
bool First = true;
|
||||||
|
RollResults = string.Empty;
|
||||||
|
foreach (int Roll in Rolls)
|
||||||
|
{
|
||||||
|
RollResults += string.Format("{0}{1}", First ? "" : ", ", Roll.ToString());
|
||||||
|
First = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -27,6 +27,7 @@ namespace osrs_toolbox
|
|||||||
OpenCombatLevelCalculator = new RelayCommand(DoOpenCombatLevelCalculator);
|
OpenCombatLevelCalculator = new RelayCommand(DoOpenCombatLevelCalculator);
|
||||||
OpenShopBuyoutCalculator = new RelayCommand(DoOpenShopBuyoutCalculator);
|
OpenShopBuyoutCalculator = new RelayCommand(DoOpenShopBuyoutCalculator);
|
||||||
OpenAPITest = new RelayCommand(DoOpenAPITest);
|
OpenAPITest = new RelayCommand(DoOpenAPITest);
|
||||||
|
OpenDiceRoller = new RelayCommand(DoOpenDiceRoller);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoOpenCompetitionOverlaySettings(object obj)
|
private void DoOpenCompetitionOverlaySettings(object obj)
|
||||||
@@ -98,5 +99,19 @@ namespace osrs_toolbox
|
|||||||
atv.Show();
|
atv.Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DoOpenDiceRoller(object obj)
|
||||||
|
{
|
||||||
|
if (DiceRollerView.Current != null)
|
||||||
|
{
|
||||||
|
DiceRollerView.Current.Close();
|
||||||
|
DiceRollerView.Current = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DiceRollerView drv = new DiceRollerView();
|
||||||
|
drv.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
osrs-toolbox/Views/DiceRollerView.xaml
Normal file
36
osrs-toolbox/Views/DiceRollerView.xaml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<Window x:Class="osrs_toolbox.DiceRollerView"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:osrs_toolbox"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Dice Roller" Height="450" Width="800" Closed="Window_Closed">
|
||||||
|
<Window.DataContext>
|
||||||
|
<local:DiceRollerViewModel/>
|
||||||
|
</Window.DataContext>
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBlock Text="Minimum Value:" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3"/>
|
||||||
|
<TextBlock Text="Maximum Value:" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3"/>
|
||||||
|
<TextBlock Text="Number of Rolls:" Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3"/>
|
||||||
|
<TextBlock Text="Allow Duplicates:" Grid.Column="0" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3"/>
|
||||||
|
<TextBox Text="{Binding MinValue, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="3" Padding="1"/>
|
||||||
|
<TextBox Text="{Binding MaxValue, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="3" Padding="1"/>
|
||||||
|
<TextBox Text="{Binding NumRolls, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="3" Padding="1"/>
|
||||||
|
<CheckBox IsChecked="{Binding AllowDuplicates, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3" Padding="1"/>
|
||||||
|
<Button Command="{Binding RollDice, UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="3" Padding="1" Content="Roll Dice"/>
|
||||||
|
<TextBox Text="{Binding RollResults, UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="2" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" Margin="3" Padding="1" IsEnabled="False"/>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
34
osrs-toolbox/Views/DiceRollerView.xaml.cs
Normal file
34
osrs-toolbox/Views/DiceRollerView.xaml.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace osrs_toolbox
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for DiceRollerView.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class DiceRollerView : Window
|
||||||
|
{
|
||||||
|
public static DiceRollerView Current;
|
||||||
|
public DiceRollerView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
Current = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Window_Closed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -104,7 +104,7 @@
|
|||||||
<local:OutlinedTextBlock Text="Open Shop Buyout Calculator" VerticalAlignment="Center" HorizontalAlignment="Center" Stroke="Black" Fill="Yellow" FontSize="30" StrokeThickness="1.2" IsHitTestVisible="False" TextWrapping="Wrap" TextAlignment="Center"/>
|
<local:OutlinedTextBlock Text="Open Shop Buyout Calculator" VerticalAlignment="Center" HorizontalAlignment="Center" Stroke="Black" Fill="Yellow" FontSize="30" StrokeThickness="1.2" IsHitTestVisible="False" TextWrapping="Wrap" TextAlignment="Center"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Button>
|
</Button>
|
||||||
<Button Command="{Binding OpenAPITest, UpdateSourceTrigger=PropertyChanged}" Template="{StaticResource NoMouseOverButtonTemplate}" Width="350" Height="90" Margin="3" Padding="3" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Transparent" BorderBrush="Transparent" BorderThickness="0">
|
<Button Command="{Binding OpenDiceRoller, UpdateSourceTrigger=PropertyChanged}" Template="{StaticResource NoMouseOverButtonTemplate}" Width="350" Height="90" Margin="3" Padding="3" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Transparent" BorderBrush="Transparent" BorderThickness="0">
|
||||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Image Source="/Resources/wood-button.png" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" StretchDirection="Both" Stretch="Fill" MouseEnter="Button_Hovered" MouseLeave="Button_Unhovered"/>
|
<Image Source="/Resources/wood-button.png" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" StretchDirection="Both" Stretch="Fill" MouseEnter="Button_Hovered" MouseLeave="Button_Unhovered"/>
|
||||||
<local:OutlinedTextBlock Text="Open API Test" VerticalAlignment="Center" HorizontalAlignment="Center" Stroke="Black" Fill="Yellow" FontSize="30" StrokeThickness="1.2" IsHitTestVisible="False" TextWrapping="Wrap" TextAlignment="Center"/>
|
<local:OutlinedTextBlock Text="Open Dice Roller" VerticalAlignment="Center" HorizontalAlignment="Center" Stroke="Black" Fill="Yellow" FontSize="30" StrokeThickness="1.2" IsHitTestVisible="False" TextWrapping="Wrap" TextAlignment="Center"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Button>
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
Reference in New Issue
Block a user