private void AddLine(CoinConfig coinConfig, Coin coin, int lineIndex) { CoinLine newLine = new CoinLine(coin.ShortName, coinConfig.Index, lineIndex, Width); if (coinConfig.StartupPrice == 0) { coinConfig.StartupPrice = coin.Price; } Invoke((MethodInvoker) delegate { newLine.SetBoughtText(coinConfig.Bought.ToString()); newLine.SetPaidText(coinConfig.Paid.ToString()); Controls.Add(newLine.Table); _coinLines.Add(newLine); Globals.SetTheme(newLine.Table); }); }
public void populateTrackObjects(Transform trackObjectsRoot) { if (trackObjectsRoot == null) { Debug.Log("trackObjectsRoot yok"); } foreach (Transform trackItem in trackObjectsRoot.transform) { TrackObject currentTrackObject = trackItem.GetComponent <TrackObject>(); if (currentTrackObject != null) { if (currentTrackObject.placeHolder == true) { if (currentTrackObject.objectGroup == TrackObject.ObjectGroup.None) { GameObject selectedObject = getRandomTrackObjectByType(currentTrackObject.objectType); if (selectedObject != null) { // Positioning New Object selectedObject.transform.parent = trackItem.transform.parent; selectedObject.transform.position = trackItem.transform.position; // Handle Selected switch (currentTrackObject.objectType) { case TrackObject.ObjectType.PointsLine: CoinLine CurrencyLine_placeHolder = currentTrackObject.GetComponent <CoinLine>(); CoinLine CurrencyLine_selected = selectedObject.GetComponent <CoinLine>(); if (CurrencyLine_placeHolder != null && CurrencyLine_selected != null) { CurrencyLine_selected.coinSpacing = CurrencyLine_placeHolder.coinSpacing; CurrencyLine_selected.length = CurrencyLine_placeHolder.length; CurrencyLine_selected.coinLineRefraction = CurrencyLine_placeHolder.coinLineRefraction; CurrencyLine_selected.doActive(); } break; case TrackObject.ObjectType.PointsCurve: CoinCurve CurrencyCurve_placeHolder = currentTrackObject.GetComponent <CoinCurve>(); CoinCurve CurrencyCurve_selected = selectedObject.GetComponent <CoinCurve>(); if (CurrencyCurve_placeHolder != null && CurrencyCurve_selected != null) { CurrencyCurve_selected.offsetObject = null; CurrencyCurve_selected.offsetObject = CurrencyCurve_placeHolder.offsetObject; CurrencyCurve_selected.doActive(); } break; case TrackObject.ObjectType.PointsMovingLine: MovingCoin MovingCoin_placeHolder = currentTrackObject.GetComponent <MovingCoin>(); MovingCoin MovingCoin_selected = selectedObject.GetComponent <MovingCoin>(); if (MovingCoin_placeHolder != null && MovingCoin_selected != null) { MovingCoin_selected.speed = MovingCoin_placeHolder.speed; } CoinLine SubCoinLine_placeHolder = currentTrackObject.GetComponent <CoinLine>(); CoinLine SubCoinLine_selected = selectedObject.transform.Find("movingMesh").gameObject.AddComponent <CoinLine>(); if (SubCoinLine_placeHolder != null && SubCoinLine_selected != null) { SubCoinLine_selected.coinSpacing = SubCoinLine_placeHolder.coinSpacing; SubCoinLine_selected.length = SubCoinLine_placeHolder.length; SubCoinLine_selected.coinLineRefraction = SubCoinLine_placeHolder.coinLineRefraction; SubCoinLine_selected.doActive(); } // Moving Coin if (MovingCoin_selected != null) { MovingCoin_selected.doActive(); } break; } } else { Debug.Log("Regular Item not found" + currentTrackObject.name); } } else { GameObject selectedObject = null; if (currentTrackObject.disableShuffle == false) { selectedObject = getRandomTrackObjectByGroup(currentTrackObject.objectGroup); } else { selectedObject = getRandomTrackObjectByType(currentTrackObject.objectType); } // Power-up handle codes places here if (currentTrackObject.objectGroup == TrackObject.ObjectGroup.PowerUps) { if (checkPowerUpSpawning(selectedObject) == false) { continue; } } // Pickables handle codes places here if (currentTrackObject.objectGroup == TrackObject.ObjectGroup.Pickables) { if (checkPowerUpSpawning(selectedObject) == false) { continue; } } if (selectedObject != null) { // Handle Selected switch (currentTrackObject.objectGroup) { case TrackObject.ObjectGroup.None: break; case TrackObject.ObjectGroup.CharacterObstacles: // Character Obstacles CharacterObstacle CharacterObstacle_placeHolder = currentTrackObject.GetComponent <CharacterObstacle>(); CharacterObstacle CharacterObstacle_selected = selectedObject.GetComponent <CharacterObstacle>(); if (CharacterObstacle_placeHolder != null && CharacterObstacle_selected != null) { CharacterObstacle_selected.lastWarrior = CharacterObstacle_placeHolder.lastWarrior; CharacterObstacle_selected.singleWarrior = CharacterObstacle_placeHolder.singleWarrior; CharacterObstacle_selected.doActive(); } break; case TrackObject.ObjectGroup.Bales1: break; case TrackObject.ObjectGroup.Bales3: break; case TrackObject.ObjectGroup.Bales5: break; case TrackObject.ObjectGroup.Barriers: break; case TrackObject.ObjectGroup.MovingObstaclesSingle: // Moving Obstacles Single MovingObstacle MovingObstaclesSingle_placeHolder = currentTrackObject.GetComponent <MovingObstacle>(); MovingObstacle MovingObstaclesSingle_selected = selectedObject.GetComponent <MovingObstacle>(); if (MovingObstaclesSingle_placeHolder != null && MovingObstaclesSingle_selected != null) { MovingObstaclesSingle_selected.trainCount = MovingObstaclesSingle_placeHolder.trainCount; MovingObstaclesSingle_selected.speed = MovingObstaclesSingle_placeHolder.speed; MovingObstaclesSingle_selected.doActive(); } break; case TrackObject.ObjectGroup.MovingObstaclesTrail3: // Moving Obstacles Trail MovingObstacle MovingObstaclesTrail_placeHolder3 = currentTrackObject.GetComponent <MovingObstacle>(); MovingObstacle MovingObstaclesTrail_selected3 = selectedObject.GetComponent <MovingObstacle>(); if (MovingObstaclesTrail_placeHolder3 != null && MovingObstaclesTrail_selected3 != null) { MovingObstaclesTrail_selected3.trainCount = MovingObstaclesTrail_placeHolder3.trainCount; MovingObstaclesTrail_selected3.speed = MovingObstaclesTrail_placeHolder3.speed; MovingObstaclesTrail_selected3.doActive(); } break; case TrackObject.ObjectGroup.MovingObstaclesTrail5: // Moving Obstacles Trail MovingObstacle MovingObstaclesTrail_placeHolder5 = currentTrackObject.GetComponent <MovingObstacle>(); MovingObstacle MovingObstaclesTrail_selected5 = selectedObject.GetComponent <MovingObstacle>(); if (MovingObstaclesTrail_placeHolder5 != null && MovingObstaclesTrail_selected5 != null) { MovingObstaclesTrail_selected5.trainCount = MovingObstaclesTrail_placeHolder5.trainCount; MovingObstaclesTrail_selected5.speed = MovingObstaclesTrail_placeHolder5.speed; MovingObstaclesTrail_selected5.doActive(); } break; } // Positioning New Object selectedObject.transform.parent = trackItem.transform.parent; selectedObject.transform.position = trackItem.transform.position; } else { Debug.Log("Shuffled Item not found" + currentTrackObject.name); } } } } } }
private void UpdateCoins(string cryptoCompareResponse, string cryptoCompareCoinsResponse, string coinMarketCapResponse, List <CoinConfig> coinConfigs) { List <CoinConfig> removeConfigs = new List <CoinConfig>(); decimal totalPaid = 0; decimal totalOverall = 0; decimal totalNegativeProfits = 0; decimal totalPostivieProfits = 0; int lineIndex = 0; if (string.IsNullOrWhiteSpace(cryptoCompareResponse) || string.IsNullOrWhiteSpace(cryptoCompareCoinsResponse) || string.IsNullOrWhiteSpace(coinMarketCapResponse)) { MessageBox.Show("The API webservice is having issues at the moment. Please try again in a few minutes.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } _coinNames = MappingService.CryptoCompareCoinList(cryptoCompareCoinsResponse); _coins = MappingService.MapCombination(cryptoCompareResponse, coinMarketCapResponse, coinConfigs); MainService.CheckAlerts(_coins); if (_loadLines) { _cleanReset = true; RemoveLines(); } foreach (CoinConfig coinConfig in coinConfigs) { if (!_coins.Any(c => c.ShortName == coinConfig.Name)) { Task.Factory.StartNew(() => { MessageBox.Show($"Sorry, Crypto Compare and Coin Market Cap does not have any data for {coinConfig.Name}."); }); removeConfigs.Add(coinConfig); continue; } Coin coin = _coins.Find(c => c.ShortName == coinConfig.Name); if ((_cleanReset && _loadLines) || (!_coinLines.Any(c => c.CoinName.ExtEquals(coin.ShortName) && c.CoinIndex == coinConfig.Index))) { if (_resetStartupPrice) { coinConfig.StartupPrice = 0; } AddLine(coinConfig, coin, lineIndex); } lineIndex++; CoinLine line = (from c in _coinLines where c.CoinName.ExtEquals(coin.ShortName) && c.CoinIndex == coinConfig.Index select c).First(); decimal bought = line.BoughtTextBox.Text.ConvertToDecimal(); decimal paid = line.PaidTextBox.Text.ConvertToDecimal(); decimal total = bought * coin.Price; decimal profit = total - paid; coinConfig.Bought = bought; coinConfig.Paid = paid; totalPaid += paid; totalOverall += paid + profit; if (profit >= 0) { totalPostivieProfits += profit; } else { totalNegativeProfits += profit; } var coinIndexLabel = coinConfigs.Count(c => c.Name.ExtEquals(coinConfig.Name)) > 1 ? $"[{coinConfig.Index + 1}]" : string.Empty; var coinLabel = coin.ShortName; var priceLabel = $"{MainService.CurrencySymbol}{coin.Price.ConvertToString(8)}"; var boughtLabel = $"{MainService.CurrencySymbol}{bought.SafeDivision(paid).ConvertToString(8)}"; var totalLabel = $"{MainService.CurrencySymbol}{total:0.00}"; var profitLabel = $"{MainService.CurrencySymbol}{profit:0.00}"; var ratioLabel = paid != 0 ? $"{profit / paid:0.00}" : "0.00"; var changeDollarLabel = $"{MainService.CurrencySymbol}{(coin.Price - coinConfig.StartupPrice):0.000000}"; var changePercentLabel = $"{coinConfig.StartupPrice.SafeDivision(coin.Price - coinConfig.StartupPrice) * 100:0.00}%"; var change1HrLabel = $"{coin.Change1HourPercent:0.00}%"; var change24HrLabel = $"{coin.Change24HourPercent:0.00}%"; var change7DayLabel = $"{coin.Change7DayPercent:0.00}%"; Invoke((MethodInvoker) delegate { line.CoinIndexLabel.Text = coinIndexLabel; line.CoinLabel.Text = coinLabel; line.PriceLabel.Text = priceLabel; line.BoughtPriceLabel.Text = boughtLabel; line.TotalLabel.Text = totalLabel; line.ProfitLabel.Text = profitLabel; line.RatioLabel.Text = ratioLabel; line.ChangeDollarLabel.Text = changeDollarLabel; line.ChangePercentLabel.Text = changePercentLabel; line.Change1HrPercentLabel.Text = change1HrLabel; line.Change24HrPercentLabel.Text = change24HrLabel; line.Change7DayPercentLabel.Text = change7DayLabel; }); } //Remove unsupported coins foreach (var coinConfig in removeConfigs) { _coinConfigs.Remove(coinConfig); } if (_cleanReset) { _loadLines = false; _resetStartupPrice = false; } _refreshTime = DateTime.Now; UpdateStatus("Sleeping"); SetHeight(coinConfigs.Count); var totalProfitColor = totalOverall - totalPaid >= 0 ? ColorTranslator.FromHtml(UserConfigService.Theme.PositiveColor) : ColorTranslator.FromHtml(UserConfigService.Theme.NegativeColor); var totalProfitLabel = $"{MainService.CurrencySymbol}{totalOverall - totalPaid:0.00}"; var totalNegativeProfitLabel = $"{MainService.CurrencySymbol}{totalNegativeProfits:0.00}"; var totalPositiveProfitLabel = $"{MainService.CurrencySymbol}{totalPostivieProfits:0.00}"; var totalOverallLabel = $"{MainService.CurrencySymbol}{totalOverall:0.00}"; var totalInvested = $"{MainService.CurrencySymbol}{totalPaid:0.00}"; var profitPercentage = $"{Math.Abs(((1 - totalPaid.SafeDivision(totalOverall))) * 100):0.00}%"; Invoke((MethodInvoker) delegate { lblTotalProfit.ForeColor = totalProfitColor; lblProfitPercentage.ForeColor = totalProfitColor; lblTotalProfit.Text = totalProfitLabel; lblTotalNegativeProfit.Text = totalNegativeProfitLabel; lblTotalPositiveProfit.Text = totalPositiveProfitLabel; lblOverallTotal.Text = totalOverallLabel; lblTotalInvested.Text = totalInvested; lblProfitPercentage.Text = profitPercentage; alertsToolStripMenuItem.Enabled = true; coinsToolStripMenuItem.Enabled = true; }); }