static public void EndPresentation() { if (formViewer.InvokeRequired) { formViewer.Invoke(new Action(() => formViewer.Close())); } else { formViewer.Close(); } formViewer = null; if (Connection.CurrentGroup.settings.Download) { FormAlert formAlert1 = new FormAlert("Presentation finished", "Would you like to download slides?"); if (formAlert1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FormDownloadSlide formProgress = new FormDownloadSlide(); formProgress.ShowDialog(); } } else { FormAlert formAlert2 = new FormAlert("Presentation finished", "Thank you for using ShareP!", true); formAlert2.ShowDialog(); } if (Connection.FormMenu.InvokeRequired) { Connection.FormMenu.Invoke(new Action(() => Connection.FormMenu.OnViewerClosed())); } else { Connection.FormMenu.OnViewerClosed(); } }
private void Buy() { if (selectedEquipment != null && !sellSideSelected) { Commander cmdr = game.Commander; EquipmentType baseType = selectedEquipment.EquipmentType; if (baseType == EquipmentType.Gadget && cmdr.Ship.HasGadget(((Gadget)selectedEquipment).Type) && ((Gadget)selectedEquipment).Type != GadgetType.ExtraCargoBays) FormAlert.Alert(AlertType.EquipmentAlreadyOwn, this); else if (cmdr.Debt > 0) FormAlert.Alert(AlertType.DebtNoBuy, this); else if (selectedEquipment.Price > cmdr.CashToSpend) FormAlert.Alert(AlertType.EquipmentIF, this); else if ((baseType == EquipmentType.Weapon && cmdr.Ship.FreeSlotsWeapon == 0) || (baseType == EquipmentType.Shield && cmdr.Ship.FreeSlotsShield == 0) || (baseType == EquipmentType.Gadget && cmdr.Ship.FreeSlotsGadget == 0)) FormAlert.Alert(AlertType.EquipmentNotEnoughSlots, this); else if (FormAlert.Alert(AlertType.EquipmentBuy, this, selectedEquipment.Name, Functions.FormatNumber(selectedEquipment.Price)) == DialogResult.Yes) { cmdr.Ship.AddEquipment(selectedEquipment); cmdr.Cash -= selectedEquipment.Price; DeselectAll(); UpdateSell(); game.ParentWindow.UpdateAll(); } } }
private void HireFire(object sender, System.EventArgs e) { if (selectedCrewMember != null && btnHireFire.Visible) { if (game.Commander.Ship.HasCrew(selectedCrewMember.Id)) { if (FormAlert.Alert(AlertType.CrewFireMercenary, this, selectedCrewMember.Name) == DialogResult.Yes) { game.Commander.Ship.Fire(selectedCrewMember.Id); UpdateAll(); game.ParentWindow.UpdateAll(); } } else { if (game.Commander.Ship.FreeCrewQuarters == 0) { FormAlert.Alert(AlertType.CrewNoQuarters, this, selectedCrewMember.Name); } else { game.Commander.Ship.Hire(selectedCrewMember); UpdateAll(); game.ParentWindow.UpdateAll(); } } } }
public static bool SaveFile(string fileName, object toSerialize, System.Windows.Forms.IWin32Window owner) { FileStream outStream = null; bool saveOk = false; try { outStream = new FileStream(fileName, FileMode.Create); (new BinaryFormatter()).Serialize(outStream, toSerialize); outStream.Close(); outStream = null; saveOk = true; } catch (IOException ex) { FormAlert.Alert(AlertType.FileErrorSave, owner, fileName, ex.Message); } finally { if (outStream != null) { outStream.Close(); } } return(saveOk); }
public static void UserBanned() { if (CurrentGroup == null) { Log.LogInfo("Trying to close group after ban when it's null"); return; } Log.LogInfo("Banned from the group."); try { ViewerController.OnAppClosing(); clientConnection.Disconnect(); CurrentGroup = null; role = Role.Notconnected; formMenu.RestoreWindow(); FormAlert formAlert = new FormAlert("Ban", "You was banned from the group", true); int overlay = Helper.ShowOverlay(); formAlert.ShowDialog(); Helper.HideOverlay(overlay); ChatController.CleanChat(); } catch (Exception e) { Log.LogException(e, "Error during UserBanned"); } }
private void BanUser() { if (listBox1.SelectedItem != null) { if (listBox1.SelectedItem.ToString().CompareTo(Connection.CurrentUser.Username) == 0) { int ov1 = Helper.ShowOverlay(this); FormAlert formAlert1 = new FormAlert("Error", "You cannot ban yourself", true); formAlert1.ShowDialog(); Helper.HideOverlay(ov1); return; } int ov2 = Helper.ShowOverlay(this); FormAlert formAlert = new FormAlert("Confirm action", "Ban " + listBox1.SelectedItem.ToString() + "?"); if (formAlert.ShowDialog() == DialogResult.OK) { ServerController.BanUser(listBox1.SelectedItem.ToString()); } Helper.HideOverlay(ov2); } else { int ov3 = Helper.ShowOverlay(this); FormAlert formAlert1 = new FormAlert("Error", "No user is selected to ban", true); formAlert1.ShowDialog(); Helper.HideOverlay(ov3); return; } }
private void CheckStatusConnection() { if (Connection.CurrentRole == Role.Notconnected) { ChangeStatusConnection(); } else if (Connection.clientConnection.Faulted) { ChangeStatusConnection(); } else { ChangeStatusConnection(true); string newIp = Helper.GetMyIP(); if (newIp.CompareTo(labelIP.Text) != 0) { Log.LogInfo("IP Changed from " + labelIP.Text + " to " + newIp); timerConnection.Enabled = false; RestoreWindow(); Disconnect(true); int overlay = Helper.ShowOverlay(); FormAlert formAlert = new FormAlert("IP Changed", "Probably network was changed. You will be disconnected.", true); formAlert.ShowDialog(); Helper.HideOverlay(overlay); labelIP.Text = Helper.GetMyIP(); timerConnection.Enabled = true; } } labelIP.Text = Helper.GetMyIP(); }
private void Disconnect(bool force = false) { if (Connection.CurrentRole == Role.Host) { int overlay = Helper.ShowOverlay(this); FormAlert formAlert = new FormAlert("Confirmation", "Close the group?"); if (force || formAlert.ShowDialog() == DialogResult.OK) { Helper.HideOverlay(overlay); ServerController.OnGroupClose(); PresentationController.OnAppClosing(); ViewerController.OnAppClosing(); Connection.Disconnect(); LoadConnectionTab(); buttonJoin.Enabled = true; } Helper.HideOverlay(overlay); } else if (Connection.CurrentRole == Role.Client) { int overlay = Helper.ShowOverlay(this); FormAlert formAlert = new FormAlert("Confirmation", "Disconnect from the group?"); if (force || formAlert.ShowDialog() == DialogResult.OK) { Helper.HideOverlay(overlay); ViewerController.OnAppClosing(); PresentationController.OnAppClosing(); Connection.Disconnect(); LoadConnectionTab(); buttonJoin.Enabled = true; } Helper.HideOverlay(overlay); } }
private void Sell() { if (selectedEquipment != null && sellSideSelected) { if (FormAlert.Alert(AlertType.EquipmentSell, this) == DialogResult.Yes) { // The slot is the selected index. Two of the three list boxes will have selected indices of -1, so adding // 2 to the total cancels those out. int slot = lstSellWeapon.SelectedIndex + lstSellShield.SelectedIndex + lstSellGadget.SelectedIndex + 2; Commander cmdr = game.Commander; if (selectedEquipment.EquipmentType == EquipmentType.Gadget && (((Gadget)selectedEquipment).Type == GadgetType.ExtraCargoBays || ((Gadget)selectedEquipment).Type == GadgetType.HiddenCargoBays) && cmdr.Ship.FreeCargoBays < 5) { FormAlert.Alert(AlertType.EquipmentExtraBaysInUse, this); } else { cmdr.Cash += selectedEquipment.SellPrice; cmdr.Ship.RemoveEquipment(selectedEquipment.EquipmentType, slot); UpdateSell(); game.ParentWindow.UpdateAll(); } } } }
public static void GroupClosed(bool faulted = false) { if (CurrentGroup == null) { Log.LogInfo("Trying to close group when it's null"); return; } Log.LogInfo("Disconnect from group. Faulted: " + faulted); try { ViewerController.OnAppClosing(); clientConnection.Disconnect(); CurrentGroup = null; role = Role.Notconnected; formMenu.RestoreWindow(); FormAlert formAlert; if (faulted) { formAlert = new FormAlert("Connection faulted", "Probably host lost network connection", true); } else { formAlert = new FormAlert("Group was closed", "Host closed the group", true); } int overlay = Helper.ShowOverlay(); formAlert.ShowDialog(); Helper.HideOverlay(overlay); ChatController.CleanChat(); } catch (Exception e) { Log.LogException(e, "Error during GroupClosed"); } }
public void ShowFirstTimeInstruction() { Log.LogInfo("First time user. Asking for instruction"); int overlay = Helper.ShowOverlay(this); FormAlert formAlert = new FormAlert("Welcome to ShareP", "It looks like your first time here. Want to read an instruction?", false, "Yes", "No"); if (formAlert.ShowDialog() == DialogResult.OK) { // Show instruction } Helper.HideOverlay(overlay); }
private void labelIP_Click(object sender, EventArgs e) { int overlay = Helper.ShowOverlay(this); FormChangeIp formChangeIp = new FormChangeIp(); if (Connection.CurrentRole != Role.Notconnected) { FormAlert formAlert = new FormAlert("Error", "You are not allowed to change network when connected.", true); formAlert.ShowDialog(); } else if (formChangeIp.ShowDialog() == DialogResult.OK) { CheckStatusConnection(); } Helper.HideOverlay(overlay); }
public FormOptions() { InitializeComponent(); if (game != null) { Options.CopyValues(game.Options); } else { Options.LoadFromDefaults(false, this); btnOk.Enabled = false; FormAlert.Alert(AlertType.OptionsNoGame, this); } UpdateAll(); }
private void labelUsername_Click(object sender, EventArgs e) { FormChangeUsername formChangeUsername = new FormChangeUsername(); int overlay = Helper.ShowOverlay(this); if (Connection.CurrentRole != Role.Notconnected) { FormAlert formAlert = new FormAlert("Error", "You are not allowed to change username when connected.", true); formAlert.ShowDialog(); } else { formChangeUsername.ShowDialog(); } Helper.HideOverlay(overlay); labelUsername.Text = m_user.Username; }
private void btnPayBack_Click(object sender, System.EventArgs e) { if (cmdr.Debt == 0) { FormAlert.Alert(AlertType.DebtNone, this); } else { FormPayBackLoan form = new FormPayBackLoan(); if (form.ShowDialog(this) == DialogResult.OK) { cmdr.Cash -= form.Amount; cmdr.Debt -= form.Amount; UpdateAll(); game.ParentWindow.UpdateAll(); } } }
private void btnGetLoan_Click(object sender, System.EventArgs e) { if (cmdr.Debt >= MaxLoan) { FormAlert.Alert(AlertType.DebtTooLargeLoan, this); } else { FormGetLoan form = new FormGetLoan(MaxLoan - cmdr.Debt); if (form.ShowDialog(this) == DialogResult.OK) { cmdr.Cash += form.Amount; cmdr.Debt += form.Amount; UpdateAll(); game.ParentWindow.UpdateAll(); } } }
public FormShipList() { InitializeComponent(); #region Array of controls lblPrice = new Label[] { lblPrice0, lblPrice1, lblPrice2, lblPrice3, lblPrice4, lblPrice5, lblPrice6, lblPrice7, lblPrice8, lblPrice9, }; btnBuy = new Button[] { btnBuy0, btnBuy1, btnBuy2, btnBuy3, btnBuy4, btnBuy5, btnBuy6, btnBuy7, btnBuy8, btnBuy9, }; #endregion UpdateAll(); Info((int)game.Commander.Ship.Type); if (game.Commander.Ship.Tribbles > 0 && !game.TribbleMessage) { FormAlert.Alert(AlertType.TribblesTradeIn, this); game.TribbleMessage = true; } }
private void btnBuyInsurance_Click(object sender, System.EventArgs e) { if (cmdr.Insurance) { if (FormAlert.Alert(AlertType.InsuranceStop, this) == DialogResult.Yes) { cmdr.Insurance = false; cmdr.NoClaim = 0; } } else if (!cmdr.Ship.EscapePod) { FormAlert.Alert(AlertType.InsuranceNoEscapePod, this); } else { cmdr.Insurance = true; cmdr.NoClaim = 0; } UpdateAll(); game.ParentWindow.UpdateAll(); }
public static object LoadFile(string fileName, bool ignoreMissingFile, System.Windows.Forms.IWin32Window owner) { object obj = null; FileStream inStream = null; try { inStream = new FileStream(fileName, FileMode.Open); obj = (new BinaryFormatter()).Deserialize(inStream); inStream.Close(); inStream = null; } catch (FileNotFoundException ex) { if (!ignoreMissingFile) { FormAlert.Alert(AlertType.FileErrorOpen, owner, fileName, ex.Message); } } catch (IOException ex) { FormAlert.Alert(AlertType.FileErrorOpen, owner, fileName, ex.Message); } catch (System.Runtime.Serialization.SerializationException) { FormAlert.Alert(AlertType.FileErrorOpen, owner, fileName, Strings.FileFormatBad); } finally { if (inStream != null) { inStream.Close(); } } return(obj); }
private void CreateNewGroup(Group newGroup) { if (String.IsNullOrEmpty(newGroup.hostName)) { newGroup.hostName = m_user.Username; } if (String.IsNullOrEmpty(newGroup.hostIp)) { newGroup.hostIp = Helper.GetMyIP(); } if (Connection.CreateGroup(newGroup)) { Connection.CurrentGroup.AddUser(m_user); } else { int overlay = Helper.ShowOverlay(this); FormAlert formAlert = new FormAlert("Error", "Server could not be started. Make sure to run application as an administator", true); formAlert.ShowDialog(); Helper.HideOverlay(overlay); } LoadConnectionTab(); CheckStatusConnection(); }
public bool TradeShip(ShipSpec specToBuy, int netPrice, string newShipName, IWin32Window owner) { bool traded = false; if (netPrice > 0 && Debt > 0) { FormAlert.Alert(AlertType.DebtNoBuy, owner); } else if (netPrice > CashToSpend) { FormAlert.Alert(AlertType.ShipBuyIF, owner); } else if (specToBuy.CrewQuarters < Ship.SpecialCrew.Length) { string passengers = Ship.SpecialCrew[1].Name; if (Ship.SpecialCrew.Length > 2) { passengers += " and " + Ship.SpecialCrew[2].Name; } FormAlert.Alert(AlertType.ShipBuyPassengerQuarters, owner, passengers); } else if (specToBuy.CrewQuarters < Ship.CrewCount) { FormAlert.Alert(AlertType.ShipBuyCrewQuarters, owner); } else if (Ship.ReactorOnBoard) { FormAlert.Alert(AlertType.ShipBuyReactor, owner); } else { Equipment[] special = new Equipment[] { Consts.Weapons[(int)WeaponType.MorgansLaser], Consts.Weapons[(int)WeaponType.QuantumDistruptor], Consts.Shields[(int)ShieldType.Lightning], Consts.Gadgets[(int)GadgetType.FuelCompactor], Consts.Gadgets[(int)GadgetType.HiddenCargoBays] }; bool[] add = new bool[special.Length]; bool addPod = false; int extraCost = 0; for (int i = 0; i < special.Length; i++) { if (Ship.HasEquipment(special[i])) { if (specToBuy.Slots(special[i].EquipmentType) == 0) { FormAlert.Alert(AlertType.ShipBuyNoSlots, owner, newShipName, special[i].Name, Strings.EquipmentTypes[(int)special[i].EquipmentType]); } else { extraCost += special[i].TransferPrice; add[i] = true; } } } if (Ship.EscapePod) { addPod = true; extraCost += Consts.PodTransferCost; } if (netPrice + extraCost > CashToSpend) { FormAlert.Alert(AlertType.ShipBuyIFTransfer, owner); } extraCost = 0; for (int i = 0; i < special.Length; i++) { if (add[i]) { if (netPrice + extraCost + special[i].TransferPrice > CashToSpend) { FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, special[i].Name); } else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, special[i].Name, special[i].Name.ToLower(), Functions.FormatNumber(special[i].TransferPrice)) == DialogResult.Yes) { extraCost += special[i].TransferPrice; } else { add[i] = false; } } } if (addPod) { if (netPrice + extraCost + Consts.PodTransferCost > CashToSpend) { FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, Strings.ShipInfoEscapePod); } else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, Strings.ShipInfoEscapePod, Strings.ShipInfoEscapePod.ToLower(), Functions.FormatNumber(Consts.PodTransferCost)) == DialogResult.Yes) { extraCost += Consts.PodTransferCost; } else { addPod = false; } } if (FormAlert.Alert(AlertType.ShipBuyConfirm, owner, Ship.Name, newShipName, (add[0] || add[1] || add[2] || addPod ? Strings.ShipBuyTransfer : "")) == DialogResult.Yes) { CrewMember[] oldCrew = Ship.Crew; Ship = new Ship(specToBuy.Type); Cash -= (netPrice + extraCost); for (int i = 0; i < Math.Min(oldCrew.Length, Ship.Crew.Length); i++) { Ship.Crew[i] = oldCrew[i]; } for (int i = 0; i < special.Length; i++) { if (add[i]) { Ship.AddEquipment(special[i]); } } if (addPod) { Ship.EscapePod = true; } else if (Insurance) { Insurance = false; NoClaim = 0; } traded = true; } } return(traded); }
private async void button5_Click_1(object sender, EventArgs e) { if (!CheckLengthPresentationName()) { return; } if (!PresentationController.CheckApp()) { int ov = Helper.ShowOverlay(this); FormAlert formAlert = new FormAlert("PowerPoint error", "Make sure You have installed PowerPoint 2007 or newer", true); formAlert.ShowDialog(); Helper.HideOverlay(ov); return; } if ((Connection.CurrentRole == Role.Client && !Connection.clientConnection.ClRequestPresentationStart()) || (Connection.CurrentRole == Role.Host && Connection.ReservePresentation)) { int ov = Helper.ShowOverlay(this); FormAlert formAlert = new FormAlert("Error", "Someone in the group has already started presentation", true); formAlert.ShowDialog(); Helper.HideOverlay(ov); return; } string file = textBoxFile.Text; string name = textBoxPresentationName.Text; int overlay = Helper.ShowOverlay(); if (file.Length < 1) { (new FormAlert("No file", "Please, choose presentation file.", true)).ShowDialog(); } else { var formLoading = new FormLoading("Loading presentation. Please wait..."); try { if (Connection.CurrentRole == Role.Host) { Connection.ReservePresentation = true; } formLoading.Show(); await Task.Run(() => PresentationController.LoadPPT(file)); formLoading.Close(); StartPresentation(name); } catch (Exception ex) { if (formLoading != null) { formLoading.Close(); } Log.LogException(ex, "Can't load presentation"); (new FormAlert("Error", "Problem occured while opening the file", true)).ShowDialog(); if (Connection.CurrentRole == Role.Host) { Connection.ReservePresentation = false; } } } Helper.HideOverlay(overlay); }
private void btnTestAlert_Click(object sender, System.EventArgs e) { FormAlert.Alert(AlertType.Alert, this, "Result", "The result was " + FormAlert.Alert((AlertType)selAlertType.SelectedItem, this, txtValue1.Text, txtValue2.Text, txtValue3.Text).ToString()); }