public void OnVoucherClick(object sender, MouseButtonEventArgs e) { TextBlock textBlock = (TextBlock)sender; Debug.Log(textBlock.Text + " clicked"); int id = -1; string idStr = MUtil.GetStringToSpecialChar(textBlock.Text, ')'); if (!int.TryParse(idStr, out id)) { Debug.ConversionError(idStr, "id", id); return; } if (id > vouchers.Count || id < 0) { Debug.LogError("Bad ID"); return; } targetVoucher = vouchers[id]; UpdateVoucherDisplay(); ResetVouchersListColors(); textBlock.Foreground = selectedVoucherColor; }
public void RefreshVouchersList() { ClearVouchersList(); string response = AdminCommands.GetVouchersList(); string voucherLine; while (response.Length != 0) { response = MUtil.GetStringToSpecialCharAndDelete(response, '\n', out voucherLine); Voucher v = ParseStringToVoucher(voucherLine); if (v == null) { Debug.LogError("Error in vouchers data"); return; } AddVoucher(v); } }
public Voucher ParseStringToVoucher(string data) { Voucher voucher = new Voucher("", -1, -1, -1); string wStr = ""; if (data.Length == 0) { Debug.LogError("Voucher data is corrupted"); return(null); } // Code data = MUtil.GetStringToSpecialCharAndDelete(data, ':', out wStr); voucher.code = wStr; if (data.Length == 0) { Debug.LogError("Voucher data is corrupted"); return(null); } // Coins / game data = MUtil.GetStringToSpecialCharAndDelete(data, ';', out wStr); if (wStr[0] == 'c') { long coins = -1; wStr = wStr.Remove(0, 1); if (!long.TryParse(wStr, out coins)) { Debug.ConversionError(wStr, "coins", coins); return(null); } voucher.coinsAddon = coins; } else { long gameID = -1; if (!long.TryParse(wStr, out gameID)) { Debug.ConversionError(wStr, "gameID", gameID); return(null); } voucher.gameID = gameID; } if (data.Length == 0) { Debug.LogError("Voucher data is corrupted"); return(null); } int usesLeft = -1; if (!int.TryParse(data, out usesLeft)) { Debug.ConversionError(wStr, "usesLeft", usesLeft); return(null); } voucher.usesLeft = usesLeft; return(voucher); }