private void numberTextBox_TextChanged(object sender, EventArgs e) { var text = numberTextBox.Text; int number; IsValidated = int.TryParse(text, out number); if (IsValidated) { //Valid only for correct values with name try { var units = ToUnits(number); units.GetOffOnName(CustomUnits); SelectedUnit = units; ShowSelectedItem(); } catch (Exception) { IsValidated = false; } } numberTextBox.BackColor = ColorConstants.GetValidationColor(IsValidated); }
/*Set chess pieces*/ void InitChessPieces() { ColorConstants RED = ColorConstants.RED; ColorConstants BLACK = ColorConstants.BLACK; RankConstants SOLDIER = RankConstants.SOLDIER; RankConstants HORSE = RankConstants.HORSE; RankConstants CARRIAGE = RankConstants.CARRIAGE; RankConstants SECRETARY = RankConstants.SECRETARY; RankConstants IMPERIAL_GUARD = RankConstants.IMPERIAL_GUARD; RankConstants KING = RankConstants.KING; RankConstants CANNON = RankConstants.CANNON; chessBoard = new ChessPiece[4, 8] { { CreatePiece(RED, KING), CreatePiece(BLACK, KING), CreatePiece(RED, IMPERIAL_GUARD), CreatePiece(RED, IMPERIAL_GUARD), CreatePiece(BLACK, IMPERIAL_GUARD), CreatePiece(BLACK, IMPERIAL_GUARD), CreatePiece(RED, SECRETARY), CreatePiece(RED, SECRETARY) }, { CreatePiece(BLACK, SECRETARY), CreatePiece(BLACK, SECRETARY), CreatePiece(RED, CARRIAGE), CreatePiece(RED, CARRIAGE), CreatePiece(BLACK, CARRIAGE), CreatePiece(BLACK, CARRIAGE), CreatePiece(RED, HORSE), CreatePiece(RED, HORSE) }, { CreatePiece(BLACK, HORSE), CreatePiece(BLACK, HORSE), CreatePiece(RED, CANNON), CreatePiece(RED, CANNON), CreatePiece(BLACK, CANNON), CreatePiece(BLACK, CANNON), CreatePiece(RED, SOLDIER), CreatePiece(RED, SOLDIER) }, { CreatePiece(RED, SOLDIER), CreatePiece(RED, SOLDIER), CreatePiece(RED, SOLDIER), CreatePiece(BLACK, SOLDIER), CreatePiece(BLACK, SOLDIER), CreatePiece(BLACK, SOLDIER), CreatePiece(BLACK, SOLDIER), CreatePiece(BLACK, SOLDIER) } }; }
private async void ColorValuesChanged(UISettings sender, object args) { bool darkTheme = ColorConstants.CurrentThemeIsDark(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ((Frame)Window.Current.Content).RequestedTheme = darkTheme ? ElementTheme.Dark : ElementTheme.Light; }); }
public async Task UpdatePage() { vm.Chart.IsLoading = true; vm.CurrencySymbol = App.currencySymbol; /// Empty diversification chart and reset the Total amounts PortfolioChartGrid.ColumnDefinitions.Clear(); PortfolioChartGrid.Children.Clear(); /// Update the purchase details first for (int i = 0; i < vm.Portfolio.Count; i++) { await PortfolioHelper.UpdatePurchase(vm.Portfolio[i]); } vm.TotalInvested = vm.Portfolio.Sum(x => x.InvestedQty); vm.TotalWorth = vm.Portfolio.Sum(x => x.Worth); vm.TotalDelta = vm.Portfolio.Sum(x => x.Profit); vm.ROI = Math.Round(100 * (vm.TotalWorth - vm.TotalInvested) / vm.TotalInvested, 1); /// Create the diversification grid var grouped = vm.Portfolio.GroupBy(x => x.Crypto).OrderByDescending(x => x.Sum(item => item.Worth)); foreach (var purchases in grouped) { var crypto = purchases.Key.ToUpperInvariant(); var worth = purchases.ToList().Sum(x => x.Worth); ColumnDefinition col = new ColumnDefinition(); col.Width = new GridLength(worth, GridUnitType.Star); PortfolioChartGrid.ColumnDefinitions.Add(col); // Use a grid for Vertical alignment var g = new Grid(); g.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 0, 255)); g.BorderThickness = new Thickness(0); g.VerticalAlignment = VerticalAlignment.Stretch; var val = Math.Round((worth / vm.TotalWorth) * 100, 1); ToolTipService.SetToolTip(g, $"{crypto} {val}% \n{worth}{vm.CurrencySymbol}"); ToolTipService.SetPlacement(g, PlacementMode.Right); var t = new TextBlock() { Text = crypto + "\n" + $"{val}%", FontSize = 12, HorizontalAlignment = HorizontalAlignment.Center, HorizontalTextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; g.Children.Add(t); g.Background = ColorConstants.GetCoinBrush(crypto, 100); PortfolioChartGrid.Children.Add(g); Grid.SetColumn(g, PortfolioChartGrid.Children.Count - 1); } /// Finally, update the chart of the portfolio's worth await UpdatePortfolioChart(); }
/// ######################################################################################### /// Update a card's charts private async Task UpdateCard(int i) { try { string crypto = App.pinnedCoins[i]; vm.PriceCards[i].Info.CurrencySym = App.currencySymbol; /// Save the current timeSpan for navigating to another page vm.PriceCards[i].Chart.TimeSpan = timeSpan; /// Colors var brush = vm.PriceCards[i].Chart.ChartStroke; brush = ColorConstants.GetCoinBrush(crypto); vm.PriceCards[i].Chart.ChartStroke = brush; /// Get Historic and create List of ChartData for the chart var histo = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, timeUnit, limit, aggregate); var chartData = new List <ChartPoint>(); foreach (var h in histo) { chartData.Add(new ChartPoint() { Date = h.DateTime, Value = h.Average, Volume = h.volumeto, High = h.high, Low = h.low, Open = h.open, Close = h.close }); } vm.PriceCards[i].Chart.ChartData = chartData; var temp = GraphHelper.AdjustLinearAxis(new ChartStyling(), timeSpan); vm.PriceCards[i].Chart.LabelFormat = temp.LabelFormat; vm.PriceCards[i].Chart.Minimum = temp.Minimum; vm.PriceCards[i].Chart.MajorStepUnit = temp.MajorStepUnit; vm.PriceCards[i].Chart.MajorStep = temp.MajorStep; vm.PriceCards[i].Chart.TickInterval = temp.TickInterval; /// Calculate min-max to adjust axis var MinMax = GraphHelper.GetMinMaxOfArray(chartData.Select(d => d.Value).ToList()); vm.PriceCards[i].Chart.PricesMinMax = GraphHelper.OffsetMinMaxForChart(MinMax.Min, MinMax.Max); vm.PriceCards[i].Chart.VolumeMax = GraphHelper.GetMaxOfVolume(chartData); /// Calculate the price difference double oldestPrice = histo[0].Average; double newestPrice = histo[histo.Count - 1].Average; vm.PriceCards[i].Info.Prices = (oldestPrice, newestPrice); /// Sum total volume from historic vm.PriceCards[i].Info.VolumeToTotal = histo.Sum(h => h.volumeto); vm.PriceCards[i].Info.VolumeFromTotal = histo.Sum(h => h.volumefrom); double total = histo.Sum(h => h.volumeto); /// Show that loading is done vm.PriceCards[i].Info.IsLoading = false; } catch (Exception) { } }
public SettingsDialog(string initialPage = "General") { InitializeComponent(); RequestedTheme = ColorConstants.CurrentThemeIsDark() ? ElementTheme.Dark : ElementTheme.Light; var version = Package.Current.Id.Version; FooterVersion = string.Format("Version {0}.{1}.{2}", version.Major, version.Minor, version.Build); NavigateFrame(initialPage); }
private void DecideColor(ColorConstants pieceColor) { ColorConstants remainingColor = pieceColor == ColorConstants.RED ? ColorConstants.BLACK : ColorConstants.RED; gameState.ActiveColor = pieceColor; gameState.PassiveColor = remainingColor; server.SendGameEvent(gameState.ActiveID, "COLOR", gameState.ActiveColor.ToString()); server.SendGameEvent(gameState.PassiveID, "COLOR", gameState.PassiveColor.ToString()); }
private async Task UpdateCoin() { var crypto = vm.Coin.Name; vm.CurrencySymbol = Currencies.GetCurrencySymbol(App.currency); /// Colors vm.Chart.ChartStroke = ColorConstants.GetCoinBrush(crypto); /// Get Historic and create List of ChartData for the chart (plus LinearAxis) var histo = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, timeUnit, limit, aggregate); var chartData = new List <ChartPoint>(); foreach (var h in histo) { chartData.Add(new ChartPoint() { Date = h.DateTime, Value = h.Average, Volume = h.volumeto, High = h.high, Low = h.low, Open = h.open, Close = h.close }); } vm.Chart.ChartData = chartData; var temp = GraphHelper.AdjustLinearAxis(new ChartStyling(), timeSpan); vm.Chart.LabelFormat = temp.LabelFormat; vm.Chart.Minimum = temp.Minimum; vm.Chart.MajorStepUnit = temp.MajorStepUnit; vm.Chart.MajorStep = temp.MajorStep; vm.Chart.TickInterval = temp.TickInterval; vm.Coin.VolumeToTotal = histo.Sum(x => x.volumeto); /// Calculate min-max to adjust axis var MinMax = GraphHelper.GetMinMaxOfArray(chartData.Select(d => d.Value).ToList()); vm.Chart.PricesMinMax = GraphHelper.OffsetMinMaxForChart(MinMax.Min, MinMax.Max); vm.Chart.VolumeMax = GraphHelper.GetMaxOfVolume(chartData); /// Calculate the price difference double oldestPrice = histo.FirstOrDefault()?.Average ?? 0; double newestPrice = histo.LastOrDefault()?.Average ?? 0; vm.Coin.Prices = (oldestPrice, newestPrice); vm.Coin.IsLoading = false; }
/// <summary> /// Generates the a Secondary Tile's background /// </summary> internal static async Task <Grid> SecondaryTileGrid(string crypto, List <HistoricPrice> hist = null) { var grid = new Grid() { Background = new SolidColorBrush(Color.FromArgb(0, 128, 128, 128)), Width = 300, Height = 150, }; try { if (hist == null) { hist = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, "hour", 168); } var polyline = new Polyline(); polyline.Stroke = ColorConstants.GetCoinBrush(crypto); polyline.Fill = ColorConstants.GetCoinBrush(crypto, 50); polyline.FillRule = FillRule.Nonzero; polyline.StrokeThickness = 1.5; polyline.VerticalAlignment = VerticalAlignment.Bottom; var points = new PointCollection(); int i = 0; var ordered = hist.OrderByDescending(x => x.Average); double min = ordered.LastOrDefault().Average; double max = ordered.FirstOrDefault().Average; foreach (var h in hist.GetRange(hist.Count - 150, 150)) { points.Add(new Point(2 * ++i, 90 - (90 * ((h.Average - min) / (max - min))))); } points.Add(new Point(2 * i, 90)); points.Add(new Point(0, 90)); polyline.Points = points; polyline.VerticalAlignment = VerticalAlignment.Bottom; grid.Children.Add(polyline); return(grid); } catch (Exception ex) { Analytics.TrackEvent("SecondaryTileGrid-error", new Dictionary <string, string>() { { "Exception", ex.Message } }); return(grid); } }
// ############################################################################################### private void ThemeRadioButtons_Changed(object sender, SelectionChangedEventArgs e) { RadioButtons r = sender as RadioButtons; if (r.SelectedIndex < 0) { return; } var theme = ((ContentControl)r.SelectedItem).Content.ToString(); var parentFrame = (Frame)Window.Current.Content; var parentDialog = (FrameworkElement)((FrameworkElement)((FrameworkElement)this.Parent).Parent).Parent; App._LocalSettings.Set(UserSettings.Theme, theme); var darkTheme = ColorConstants.CurrentThemeIsDark(); parentFrame.RequestedTheme = darkTheme ? ElementTheme.Dark : ElementTheme.Light; parentDialog.RequestedTheme = darkTheme ? ElementTheme.Dark : ElementTheme.Light; }
/// <summary> /// Calculate a purchase's worth, delta, boughtAt and profit /// </summary> /// <param name="purchase"></param> /// <returns></returns> public async static Task <PurchaseModel> UpdatePurchase(PurchaseModel purchase) { string crypto = purchase.Crypto; if (purchase.Current <= 0 || (DateTime.Now - purchase.LastUpdate).TotalSeconds > 20) { purchase.Current = await Ioc.Default.GetService <ICryptoCompare>().GetPrice_Extension( purchase.Crypto, purchase.Currency); } var curr = purchase.Current; purchase.Worth = NumberHelper.Rounder(curr * purchase.CryptoQty); /// If the user has also filled the invested quantity, we can calculate everything else if (purchase.InvestedQty >= 0) { double priceBought = purchase.InvestedQty / purchase.CryptoQty; priceBought = NumberHelper.Rounder(priceBought); var diff = Math.Round((curr - priceBought) * purchase.CryptoQty, 4); purchase.Delta = Math.Round(100 * diff / purchase.InvestedQty, 2); purchase.BoughtAt = priceBought; if (purchase.Delta > 100) { purchase.Delta -= 100; } purchase.Profit = Math.Round(diff, 2); purchase.ProfitFG = (diff < 0) ? ColorConstants.GetColorBrush("pastel_red") : ColorConstants.GetColorBrush("pastel_green"); } if (purchase.InvestedQty == 0) { purchase.Delta = 0; } return(purchase); }
public object Convert(object val, Type targetType, object param, string lang) { if (val != null) { var vals = (val as List <double>); color = (vals[vals.Count - 1] > vals[0]) ? SKColor.Parse(ColorConstants.GetColorBrush("pastel_green").Color.ToString()) : SKColor.Parse(ColorConstants.GetColorBrush("pastel_red").Color.ToString()); var entries = vals.ConvertAll(PointConverter); Chart chart = new LineChart() { Entries = entries, IsAnimated = false, LineAreaAlpha = 0, PointAreaAlpha = 0, BackgroundColor = SKColors.Transparent, LabelColor = SKColors.Green, LineMode = LineMode.Straight, LineSize = 1, PointSize = 1, MinValue = entries.Min(x => x.Value), MaxValue = entries.Max(x => x.Value), }; return(chart); } else { return new LineChart() { Entries = new List <ChartEntry>() { new ChartEntry(0) }, BackgroundColor = SKColors.Transparent, IsAnimated = false } }; }
public object Convert(object val, Type targetType, object param, string lang) => (double)val >= 0 ? ColorConstants.GetColorBrush("pastel_green") : ColorConstants.GetColorBrush("pastel_red");
public String GetIDBaseOnColor(ColorConstants color) { GamePlayer target = active.color == color ? active : passive; return(target.id); }
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { vm.Chart.ChartStroke = ColorConstants.GetCoinBrush(vm.Info.Name); }
public static Boolean CombineEquipment() { /* 0 1 2 3 4 * 0 D | D | D | D | D * 1 D | D | D | D | D * 2 D | X | X | X | N */ /* START AT (115, 535) * WHEN MOVING TO THE RIGHT DO (115 + (POS * 95), 535) * WHEN MOVING DOWN DO (115, 535 + (POS * 85)) * THIS SHOULD LEAVE U TO THE LAST Y = 705 * SO IN TOTAL THE CALCULATION IS * (115 + (POS * 95), 535 + (POS * 85)) */ ColorConstants.SetColours(); Main.ResetToHome(); OpenObjects.OpenBlackSmith(); Point startPos = LocationConstants.BLACKSMITH_DEFAULT; Point setPos = startPos; int combined = 0; Thread.Sleep(1000); for (int type = 0; type < 3; type++) { if (type == 1) { MouseHandler.MoveCursor(LocationConstants.BLACKSMITH_ARMOR, true); } else if (type == 2) { MouseHandler.MoveCursor(LocationConstants.BLACKSMITH_ACCESSORY, true); } else if (type == 3) { MouseHandler.MoveCursor(LocationConstants.BLACKSMITH_HELMET, true); } for (int y = 0; y < 4; y++) { for (int x = 0; x < 5; x++) { if (combined >= 3) { return(true); } setPos = new Point(115 + (x * 95), 535 + (y * 85)); try { if (PixelChecker.CheckPixelValue(setPos, ColorConstants.Equipments[y, x])) { if (setPos.X == 495) { setPos = new Point(setPos.X - 5, setPos.Y); } Console.WriteLine($"Found Equipment that needs to be combined. Location - {x}:{y}"); MouseHandler.MoveCursor(setPos, true); int CombineAmount = ImageToText.GetCombineAmount(); if (CombineAmount == -1) { Console.WriteLine($"Unable To Read Combine Amount. Combining it Once"); LowerCombineAmont(100); int price = ImageToText.GetBlacksmithPurchaseAmount(); MouseHandler.MoveCursor(LocationConstants.BLACKSMITH_PURCHASE, true); Thread.Sleep(3000); if (PixelChecker.CheckPixelValue(LocationConstants.BLACKSMITH_CLAIM, ColorConstants.BLACKSMITH_CLAIM_COLOR)) { MouseHandler.MoveCursor(LocationConstants.BLACKSMITH_CLAIM, true); combined++; } else { Console.WriteLine("Insufficient Gold!"); } } else { int loweramount = CombineAmount - 3; LowerCombineAmont(loweramount); int price = ImageToText.GetBlacksmithPurchaseAmount(); MouseHandler.MoveCursor(LocationConstants.BLACKSMITH_PURCHASE, true); Thread.Sleep(3000); if (PixelChecker.CheckPixelValue(LocationConstants.BLACKSMITH_CLAIM, ColorConstants.BLACKSMITH_CLAIM_COLOR)) { MouseHandler.MoveCursor(LocationConstants.BLACKSMITH_CLAIM, true); combined += 3; } else { Console.WriteLine("Insufficient Gold!"); } } } } catch { x++; } } } } Console.WriteLine("Finished"); return(true); }
public ChessPiece(ColorConstants color, RankConstants rank) { this.color = color; this.rank = rank; flipped = false; }
public void Awake() { instance = this; }
protected ChessPiece CreatePiece(ColorConstants color, RankConstants rank) { return(new ChessPiece(color, rank)); }
/// ############################################################################################### /// Update the chart of the historic values of the portfolio private async Task UpdatePortfolioChart() { var nPurchases = vm.Portfolio.Count; if (nPurchases == 0) { return; } /// Optimize by only getting historic for different cryptos var uniqueCryptos = new HashSet <string>(vm.Portfolio.Select(x => x.Crypto)).ToList(); /// Get historic for each unique crypto, get invested qty, and multiply /// to get the worth of each crypto to the user's wallet var cryptoQties = new List <double>(); var cryptoWorth = new List <List <double> >(); var histos = new List <List <HistoricPrice> >(nPurchases); foreach (var crypto in uniqueCryptos) { var histo = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, timeUnit, limit, aggregate); var cryptoQty = vm.Portfolio.Where(x => x.Crypto == crypto).Sum(x => x.CryptoQty); cryptoWorth.Add(histo.Select(x => x.Average * cryptoQty).ToList()); histos.Add(histo); } /// There might be young cryptos that didnt exist in the past, so take the common minimum var minCommon = histos.Min(x => x.Count); if (minCommon == 1) { return; } /// Check if all arrays are equal length, if not, remove the leading values var sameLength = cryptoWorth.All(x => x.Count == cryptoWorth[0].Count); if (!sameLength) { for (int i = 0; i < histos.Count; i++) { histos[i] = histos[i].Skip(Math.Max(0, histos[i].Count() - minCommon)).ToList(); } } var worth_arr = new List <double>(); var dates_arr = histos[0].Select(kk => kk.DateTime).ToList(); for (int i = 0; i < minCommon; i++) { worth_arr.Add(cryptoWorth.Select(x => x[i]).Sum()); } /// Create List for chart var chartData = new List <ChartPoint>(); for (int i = 0; i < minCommon; i++) { chartData.Add(new ChartPoint { Date = dates_arr.ElementAt(i), Value = (float)worth_arr[i], Volume = 0 }); } vm.Chart.ChartData = chartData; var temp = GraphHelper.AdjustLinearAxis(new ChartStyling(), timeSpan); vm.Chart.LabelFormat = temp.LabelFormat; vm.Chart.Minimum = temp.Minimum; vm.Chart.MajorStepUnit = temp.MajorStepUnit; vm.Chart.MajorStep = temp.MajorStep; vm.Chart.TickInterval = temp.TickInterval; vm.Chart.ChartStroke = (vm.TotalDelta >= 0) ? ColorConstants.GetColorBrush("pastel_green") : ColorConstants.GetColorBrush("pastel_red"); /// Calculate min-max to adjust axis var MinMax = GraphHelper.GetMinMaxOfArray(chartData.Select(d => d.Value).ToList()); vm.Chart.PricesMinMax = GraphHelper.OffsetMinMaxForChart(MinMax.Min, MinMax.Max); vm.Chart.VolumeMax = GraphHelper.GetMaxOfVolume(chartData); vm.Chart.VolumeMax = (vm.Chart.VolumeMax == 0) ? 10 : vm.Chart.VolumeMax; vm.Chart.IsLoading = false; }