112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
using MahApps.Metro.Controls.Dialogs;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace GTAOnlineCasinoHelper.Views
|
|
{
|
|
|
|
public partial class LuckyWheel : UserControl
|
|
{
|
|
|
|
public DateTimeOffset TimeStamp { get; set; }
|
|
public DateTimeOffset TimeStampReady
|
|
{
|
|
get
|
|
{
|
|
return AddHours(TimeStamp, 24);
|
|
}
|
|
}
|
|
|
|
private Timer timer;
|
|
|
|
public LuckyWheel()
|
|
{
|
|
this.InitializeComponent();
|
|
if (DateTimeOffset.TryParse(Properties.Settings.Default.LuckyWheelTimeStamp, out DateTimeOffset timeStamp))
|
|
{
|
|
TimeStamp = timeStamp;
|
|
}
|
|
this.timer = new Timer((state) =>
|
|
{
|
|
Dispatcher.Invoke(() => Refresh());
|
|
}, this, Timeout.Infinite, 500);
|
|
this.timer.Change(0, 500);
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if (TimeStamp == null)
|
|
{
|
|
return;
|
|
}
|
|
DateTimeOffset then = TimeStampReady;
|
|
TextBlock_TimeStampTextBlock.Text = string.Format("{0}\n->\n{1}", TimeStamp.LocalDateTime.ToString(), then.LocalDateTime.ToString());
|
|
TimeSpan offset = then - DateTimeOffset.Now;
|
|
if (offset.TotalMilliseconds < 0)
|
|
{
|
|
TextBlock_TimerTextBlock.Text = "READY!";
|
|
}
|
|
else
|
|
{
|
|
string hoursString = ((int)offset.TotalHours).ToString();
|
|
while (hoursString.Length < 2) hoursString = "0" + hoursString;
|
|
string minutesString = offset.Minutes.ToString();
|
|
while (minutesString.Length < 2) minutesString = "0" + minutesString;
|
|
string secondsString = offset.Seconds.ToString();
|
|
while (secondsString.Length < 2) secondsString = "0" + secondsString;
|
|
TextBlock_TimerTextBlock.Text = string.Format("{0}:{1}:{2}", hoursString, minutesString, secondsString);
|
|
}
|
|
}
|
|
|
|
private async void Button_AddTimeStamp(object sesnder, System.Windows.RoutedEventArgs e)
|
|
{
|
|
DateTimeOffset now;
|
|
if (CheckBox_UseTextBoxTimeStamp.IsChecked.HasValue && CheckBox_UseTextBoxTimeStamp.IsChecked.Value)
|
|
{
|
|
if (!DateTimeOffset.TryParse(TextBox_TimeStamp.Text, out now))
|
|
{
|
|
await MainWindow.Instance.ShowMessageAsync("Could not parse TimeStamp", "You have to specify a string that conforms to DateTimeOffset.Parse(string)");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
now = DateTimeOffset.Now;
|
|
DateTimeOffset then = AddHours(now, 24);
|
|
if (then > now)
|
|
{
|
|
await MainWindow.Instance.ShowMessageAsync("Lucky Wheel not ready yet", "You can't spin the wheel yet, to override this add a custom timestamp");
|
|
return;
|
|
}
|
|
}
|
|
TimeStamp = now;
|
|
Properties.Settings.Default.LuckyWheelTimeStamp = now.ToString();
|
|
Properties.Settings.Default.Save();
|
|
Properties.Settings.Default.Reload();
|
|
Refresh();
|
|
//await MainWindow.Instance.ShowMessageAsync("Set TimeStamp", string.Format("You set the timestamp to {0}", timeStamp.ToString()));
|
|
}
|
|
|
|
private DateTimeOffset AddHours(DateTimeOffset offset, int hours)
|
|
{
|
|
return offset + new TimeSpan(hours, 0, 0);
|
|
}
|
|
|
|
private void CheckBox_UseTextBoxTimeStamp_Checked(object sender, RoutedEventArgs e)
|
|
{
|
|
TextBox_TimeStamp.Visibility = Visibility.Visible;
|
|
}
|
|
|
|
private void CheckBox_UseTextBoxTimeStamp_Unchecked(object sender, RoutedEventArgs e)
|
|
{
|
|
TextBox_TimeStamp.Visibility = Visibility.Collapsed;
|
|
}
|
|
}
|
|
|
|
} |