public string getControlsKey(InputPurpose purpose) { switch (purpose) { case InputPurpose.DELETE_TILE: return(controlsOK[0]); case InputPurpose.PLACE_TILE: return(controlsOK[1]); case InputPurpose.INTERACT_TILE: return(controlsOK[2]); case InputPurpose.TILE_ROTATE_LEFT: return(controlsOK[3]); case InputPurpose.TILE_ROTATE_RIGHT: return(controlsOK[4]); case InputPurpose.SELECTIONBAR: return(controlsOK[5]); case InputPurpose.PAUSE_MENU: return(controlsOK[6]); case InputPurpose.SELECTOR: return(controlsOK[7]); case InputPurpose.DELETE_SELECTED: return(controlsOK[8]); } return(null); }
// Create wallet with non-zero balance public Wallet(string str, Currency val, decimal sum, InputPurpose pur) { if (str == null || str.Length < 1) { throw new ArgumentException("Such name can't be used"); } name = str; currency = val; if (sum <= 0) { throw new ArgumentException("Amount of your wallet can't be less than 0"); } amount = sum; history = new List <Payment>(); history.Add(new InputPayment(sum, pur)); // Add events if (SuccesOperation == null) { SuccesOperation += new OperationHandler(DisplaySucces); } if (ErrorMessage == null) { ErrorMessage += new OperationHandler(DisplayError); } // Show succes SuccesOperation?.Invoke($"Wallet \"{this.name}\" has been created \n" + "Amount of this wallet is: ", amount); }
// Show purposes of input payments and choose one static InputPurpose ChooseInputPay() { InputPurpose pur = InputPurpose.Else; bool changed = false; int choice = 0; while (!changed) { Console.WriteLine("Choose the purpose of this amount:\n" + "1. Salary\n" + "2. Gift\n" + "3. Else"); changed = Int32.TryParse(Console.ReadLine(), out choice); // Choose purpose switch (choice) { case 1: pur = InputPurpose.Salary; changed = true; break; case 2: pur = InputPurpose.Gift; changed = true; break; case 3: pur = InputPurpose.Else; changed = true; break; default: DisplayError(); changed = false; break; } } return(pur); }
public static float getMovementInput(InputPurpose purpose) { switch (purpose) { case InputPurpose.CAM_MOVEMENT_HORIZ: return(Input.GetAxis("Horizontal")); case InputPurpose.CAM_MOVEMENT_VERT: return(Input.GetAxis("Vertical")); } return(0); }
static Entry PutSingleInput(Component component, PropertyInfo field, InputPurpose fillter, Fixed fixd, ref int offset) { //Label Label lbl = new Label(); lbl.Name = "lbl"; lbl.Text = field.Name; fixd.Put(lbl, 0, offset); lbl.Show(); offset += 20; //Field Entry entry = new Entry(); entry.WidthRequest = 180; entry.Name = "entry"; fixd.Put(entry, 0, offset); entry.Show(); entry.InputPurpose = fillter; offset += 40; entry.Text = field.GetValue(component).ToString(); entry.Changed += (s, e) => { if (field.PropertyType == typeof(int)) { int value = 0; int.TryParse(entry.Text, out value); field.SetValue(component, value); } else if (field.PropertyType == typeof(float)) { float value = 0; float.TryParse(entry.Text, out value); field.SetValue(component, value); } else if (field.PropertyType == typeof(string)) { field.SetValue(component, entry.Text); } }; return(entry); }
// Show data in percents of recived funds public void FundsRecived(Currency currency) { int count = 0; for (InputPurpose i = InputPurpose.Salary; i <= InputPurpose.Else; i++) { count++; } decimal[,] funds = new decimal[count, 2]; decimal allFunds = 0; foreach (Wallet wal in wallet) { if (wal.currency == currency) { int n = wal.history.Count; for (int i = 0; i < n; i++) { if (wal.history[i] is InputPayment) { InputPayment pay = (InputPayment)wal.history[i]; funds[(int)pay.purpose, 0] += wal.history[i].sum; allFunds += wal.history[i].sum; } } } } string val = FindCurrency(currency); if (allFunds == 0) { Console.WriteLine("There was not any payment in this currency"); } else { for (int i = 0; i < funds.Length / 2; i++) { funds[i, 1] = Math.Round(funds[i, 0] / allFunds, 5); Console.WriteLine((InputPurpose)i + " " + funds[i, 0] + $" {val} " + funds[i, 1] * 100 + "%"); } } Console.WriteLine(); }
// Operation to put money on the wallet public void Deposit(decimal sum, InputPurpose pur) { amount += sum; // Add money to amount history.Add(new InputPayment(sum, pur)); // Add deposit payment into history SuccesOperation?.Invoke($"Amount of \"{this.name}\" wallet is: ", this.amount); // Show succes }
static void SetVectorValue(Component component, int pos, PropertyInfo property, Entry entry, InputPurpose purpose, ref float val) { entry.Text = val.ToString(); entry.Changed += (s, e) => { if (purpose == InputPurpose.Number) { float value = 0; float.TryParse(entry.Text, out value); property.SetValue(component, value); } else { int value = 0; int.TryParse(entry.Text, out value); property.SetValue(component, value); } }; }
static void PutVectorInput(Component component, PropertyInfo property, Fixed fixd, ref int offset) { Label lbl = new Label(); lbl.Name = "lbl"; lbl.Text = property.Name; string[] namings = { "x", "y", "z", "w" }; fixd.Put(lbl, 0, offset); lbl.Show(); offset += 20; int count = 0; InputPurpose purpose = InputPurpose.Number; if (property.PropertyType == typeof(Vector2)) { count = 2; } else if (property.PropertyType == typeof(Vector3)) { count = 3; } else if (property.PropertyType == typeof(Vector4)) { count = 4; } int offsetX = 0; for (int i = 0; i < count; i++) { Label lbl1 = new Label(); lbl1.Name = "lbl"; lbl1.Text = namings[i]; fixd.Put(lbl1, offsetX, offset); lbl1.Show(); offsetX += 15; Entry entry = new Entry(); entry.WidthChars = 4; entry.Name = "entry"; entry.InputPurpose = purpose; int n = i; if (property.PropertyType == typeof(Vector2)) { Vector2 val = (Vector2)property.GetValue(component); entry.Text = val[i].ToString(); if (property.SetMethod != null) { entry.Changed += (s, e) => { float value = 0; float.TryParse(entry.Text, out value); val[n] = value; property.SetValue(component, val); }; } } else if (property.PropertyType == typeof(Vector3)) { Vector3 val = (Vector3)property.GetValue(component); entry.Text = val[i].ToString(); if (property.SetMethod != null) { entry.Changed += (s, e) => { float value = 0; float.TryParse(entry.Text, out value); val[n] = value; property.SetValue(component, val); }; } } else if (property.PropertyType == typeof(Vector4)) { Vector4 val = (Vector4)property.GetValue(component); entry.Text = val[i].ToString(); if (property.SetMethod != null) { entry.Changed += (s, e) => { float value = 0; float.TryParse(entry.Text, out value); val[n] = value; property.SetValue(component, val); }; } } fixd.Put(entry, offsetX, offset); entry.Show(); offsetX += 45; } offset += 40; }
static void Main(string[] args) { WalletList myWallet = new WalletList(); myWallet.AddWallet(new Wallet("Russian Wallet", Currency.Ruble, 15, InputPurpose.Salary)); myWallet.AddWallet(new Wallet("Hrivna Wallet", Currency.Hryvnia, 15, InputPurpose.Salary)); myWallet.AddWallet(new Wallet("Dollar Wallet", Currency.Dollar, 15, InputPurpose.Gift)); myWallet.AddWallet(new Wallet("Euro Wallet", Currency.Euro, 15, InputPurpose.Salary)); myWallet.wallet[1].Deposit(11, InputPurpose.Else); myWallet.wallet[1].Deposit(21, InputPurpose.Gift); myWallet.wallet[1].Deposit(33, InputPurpose.Salary); myWallet.wallet[1].Deposit(10, InputPurpose.Else); myWallet.wallet[1].Withdrawal(11, OutputPurpose.Else); bool start = true; Console.WriteLine("Welcome in program!\n" + "Choose what do you want to do: \n" + "1. Start\n" + "2. Exit"); int choice = Convert.ToInt32(Console.ReadLine()); if (choice == 1) { while (start) { choice = 0; bool chang = false; while (!chang) { // User can't do operations if he hasn't got any wallet if (myWallet.wallet.Count == 0) { Console.WriteLine("Now you have not got any wallet. You can:\n" + "1. Create wallet with zero balance\n" + "2. Create wallet with nonzero balance\n" + "10. Exit"); chang = Int32.TryParse(Console.ReadLine(), out choice); if (choice != 1 && choice != 2 && choice != 10) { chang = false; } } // User can use all operations if he has got created wallets else { Console.WriteLine("Operations that you can do:\n" + "1. Create wallet with zero balance\n" + "2. Create wallet with nonzero balance\n" + "3. Do money operations\n" + "4. Show Current Amount\n" + "5. Show History\n" + "6. Show Payment by date\n" + "7. FundsWithdrawn\n" + "8. FundsRecived\n" + "9. Remove wallet\n" + "10. Exit"); chang = Int32.TryParse(Console.ReadLine(), out choice); } if (!chang) { DisplayError(); } } switch (choice) { case 1: // Create wallet with zero balance { string name = NameOfWallet(myWallet); // Input name of the wallet Currency cur = ChooseCurrency(); // Choose currency of this wallet myWallet.AddWallet(new Wallet(name, cur)); // Create new wallet with this name and currency break; } case 2: // Create wallet with nonzero balance { string name = NameOfWallet(myWallet); // Input name of the wallet Currency cur = ChooseCurrency(); // Choose currency of this wallet decimal amount = SumCheck("Write initial amount of your wallet: "); // Input an initial amount of this wallet InputPurpose pur = InputPurpose.Else; pur = ChooseInputPay(); // Choose a type of input payment myWallet.AddWallet(new Wallet(name, cur, amount, pur)); // Create wallet with this parameters break; } case 3: // Do money operations { choice = 0; bool changed = false; // Choose option while (!changed) { Console.WriteLine("Choose money operation:\n" + "1. Put money on your wallet\n" + "2. Transfer current sum FROM one wallet to another\n" + "3. Transfer current sum TO one wallet from another\n" + "4. Get monet from your wallet\n" + "5. Go back"); changed = Int32.TryParse(Console.ReadLine(), out choice); if (choice <= 0 || choice > 5) { changed = false; DisplayError(); } } switch (choice) { case 1: // Put money on your wallet { changed = false; while (!changed) { Console.WriteLine("Choose on which wallet you would put money:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } int to = choice - 1; // Inder of chosen wallet decimal sum = SumCheck("Write what sum whould you put on this wallet: "); // Input payment's sum InputPurpose pur = InputPurpose.Else; pur = ChooseInputPay(); // Choose a type of input payment myWallet.wallet[to].Deposit(sum, pur); // Deposin money on this wallet break; } case 2: // Transfer current sum FROM one wallet to another { // Choose wallet to transfer from changed = false; while (!changed) { Console.WriteLine("Choose from which wallet would be taken money:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } int from = choice - 1; // Index of the wallet money whould be taken from // Choose wallet to transfer to changed = false; while (!changed) { Console.WriteLine("Choose to which wallet would be put money:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } int to = choice - 1; // Index of the wallet money whould be put on decimal sum = SumCheck("Write what sum would you like to transfer: "); // Sum to transfer myWallet.wallet[from].TransferFrom(sum, myWallet.wallet[to]); // Do transfer break; } case 3: // Transfer current sum TO one wallet from another { // Choose wallet to transfer from changed = false; while (!changed) { Console.WriteLine("Choose from which wallet would be taken money:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } int from = choice - 1; // Index of the wallet money whould be taken from // Choose wallet to transfer to changed = false; while (!changed) { Console.WriteLine("Choose to which wallet would be put money:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } int to = choice - 1; // Index of the wallet money whould be put on decimal sum = SumCheck("Write what sum would you like to transfer: "); // Sum to transfer myWallet.wallet[from].TransferTo(sum, myWallet.wallet[to]); // Do transfer break; } case 4: // Get monet from your wallet { changed = false; while (!changed) { Console.WriteLine("Choose from which wallet you would take money:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } int to = choice - 1; // Index of wallet to withdrawal decimal sum = SumCheck("Write sum of withdraw: "); // Sum to withdraw OutputPurpose pur = OutputPurpose.Else; pur = ChooseOutputPay(); // Choose purpose of payment myWallet.wallet[to].Withdrawal(sum, pur); // Do withdrawal break; } case 5: break; // Go back } break; } case 4: // Show Current Amount { choice = 0; // Choose option bool changed = false; while (!changed) { Console.WriteLine("There are some info that I can show you:\n" + "1. Amount for each wallet in your wallets\n" + "2. Amount for current wallet\n" + "3. Amount for each wallet in your wallets, that has current currency\n" + "4. How much money does I have in current currency?\n" + "5. Go back"); changed = Int32.TryParse(Console.ReadLine(), out choice); if (choice <= 0 || choice > 5) { changed = false; DisplayError(); } } switch (choice) { case 1: // Amount for each wallet in your wallets { myWallet.ShowCurrentAmount(); break; } case 2: // Amount for current wallet { changed = false; while (!changed) { Console.WriteLine("Choose amount of which wallet wounl be shown:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } myWallet.ShowCurrentAmount(myWallet.wallet[choice - 1]); break; } case 3: // Amount for each wallet in your wallets, that has current currency { Currency cur = ChooseCurrency(); myWallet.ShowCurrentAmount(cur); break; } case 4: // How much money does I have in current currency? { Currency cur = ChooseCurrency(); myWallet.ShowAmountInCurrency(cur); break; } case 5: // Go back break; } break; } case 5: // Show History { choice = 0; // Choose option bool changed = false; while (!changed) { Console.WriteLine("There is some info that I can show you:\n" + "1. History for each wallet in your wallets\n" + "2. History for current wallet\n" + "3. History for each wallet in your wallets, that has current currency\n" + "4. Go back"); changed = Int32.TryParse(Console.ReadLine(), out choice); if (choice <= 0 || choice > 4) { changed = false; DisplayError(); } } switch (choice) { case 1: // History for each wallet in your wallets { myWallet.ShowHistory(); break; } case 2: // History for current wallet { changed = false; while (!changed) { Console.WriteLine("Choose amount of which wallet wounl be shown:"); (choice, changed) = ShowWalletAndChoose(myWallet); // Choose wallet } myWallet.ShowHistory(myWallet.wallet[choice - 1]); break; } case 3: // History for each wallet in WalletList, that has current currency { Currency cur = ChooseCurrency(); myWallet.ShowHistory(cur); break; } case 4: // Go back break; } break; } case 6: // Show Payment by date { choice = 0; // Choose option bool changed = false; while (!changed) { Console.WriteLine("There is some info that I can show you:\n" + "1. Show payments by date\n" + "2. Show payments in period\n" + "3. Go back"); changed = Int32.TryParse(Console.ReadLine(), out choice); if (choice <= 0 || choice > 3) { changed = false; DisplayError(); } } switch (choice) { case 1: // Show payments by date { // Input date to show payments changed = false; DateTime date = DateTime.Now; while (!changed) { Console.Write("Write what date you would like to see all payments (dd.mm.yyyy): "); changed = DateTime.TryParse(Console.ReadLine(), out date); if (!changed) { Console.WriteLine("Wrong input! Try again\n"); } } // Show payments Console.WriteLine(); myWallet.ShowPaymentByDate(date); break; } case 2: // Show payments in period { // Input date to show payments from changed = false; DateTime datefrom = DateTime.Now; while (!changed) { Console.Write("Write what date you would like to see all payments from (dd.mm.yyyy): "); changed = DateTime.TryParse(Console.ReadLine(), out datefrom); if (!changed) { Console.WriteLine("Wrong input! Try again\n"); } } // Input date to show payments to changed = false; DateTime dateto = DateTime.Now; while (!changed) { Console.Write("Write what date you would like to see all payments to (dd.mm.yyyy): "); changed = DateTime.TryParse(Console.ReadLine(), out dateto); if (!changed) { Console.WriteLine("Wrong input! Try again\n"); } } // Show payments Console.WriteLine(); myWallet.ShowPaymentInPeriod(datefrom, dateto); break; } case 3: // Go back break; } break; } case 7: // FundsWithdrawn { Currency cur = ChooseCurrency(); myWallet.FundsWithdrawn(cur); break; } case 8: // FundsRecived { Currency cur = ChooseCurrency(); myWallet.FundsRecived(cur); break; } case 9: // Remove wallet { choice = 0; bool changed = false; while (!changed) { Console.WriteLine("Choose which wallet to remove:"); (choice, changed) = ShowWalletAndChoose(myWallet); } myWallet.RemoveWallet(myWallet.wallet[choice - 1]); break; } case 10: // Exit { start = false; break; } default: { DisplayError(); break; } } } } }
public InputPayment(decimal tempSum, InputPurpose pur) : base(tempSum) { purpose = pur; }
public static bool getInput(InputPurpose purpose) { switch (purpose) { case InputPurpose.UNIVERSAL_BACK: return(Input.GetKeyDown(KeyCode.Escape)); case InputPurpose.DELETE_TILE: return(Input.GetKey(parseKeyCode(OptionController.controlsOK[0]))); case InputPurpose.PLACE_TILE: return(Input.GetKey(parseKeyCode(OptionController.controlsOK[1]))); case InputPurpose.INTERACT_TILE: return(Input.GetKeyDown(parseKeyCode(OptionController.controlsOK[2]))); case InputPurpose.TILE_ROTATE_LEFT: return(Input.GetKeyDown(parseKeyCode(OptionController.controlsOK[3]))); case InputPurpose.TILE_ROTATE_RIGHT: return(Input.GetKeyDown(parseKeyCode(OptionController.controlsOK[4]))); case InputPurpose.ZOOM_OUT: return(Input.GetAxis("Mouse ScrollWheel") < 0f && Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.Space)); case InputPurpose.ZOOM_IN: return(Input.GetAxis("Mouse ScrollWheel") > 0f && Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.Space)); case InputPurpose.SELECTIONBAR: return(Input.GetKeyDown(parseKeyCode(OptionController.controlsOK[5]))); case InputPurpose.SELECTIONBAR_LEFT: return(Input.GetAxis("Mouse ScrollWheel") > 0f && Input.GetKey(KeyCode.Space) && !Input.GetKey(KeyCode.LeftShift)); case InputPurpose.SELECTIONBAR_RIGHT: return(Input.GetAxis("Mouse ScrollWheel") < 0f && Input.GetKey(KeyCode.Space) && !Input.GetKey(KeyCode.LeftShift)); case InputPurpose.SELECTIONBAR_UP: return(Input.GetKeyUp(parseKeyCode(OptionController.controlsOK[5]))); case InputPurpose.ACTIONBAR_LEFT: return(Input.GetAxis("Mouse ScrollWheel") > 0f && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.Space)); case InputPurpose.ACTIONBAR_RIGHT: return(Input.GetAxis("Mouse ScrollWheel") < 0f && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.Space)); case InputPurpose.RESET_ACTIONBAR: return(Input.GetKeyDown(KeyCode.C)); case InputPurpose.SELECTOR: return(Input.GetKeyDown(parseKeyCode(OptionController.controlsOK[6]))); case InputPurpose.DELETE_SELECTED: return(Input.GetKeyDown(parseKeyCode(OptionController.controlsOK[7]))); case InputPurpose.UNDO: return(Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Z)); case InputPurpose.DUPLICATE: return(Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.D)); case InputPurpose.CAM_MOVEMENT_DRAG: return(Input.GetMouseButton(2)); } return(false); }