/// <summary> /// Removes a position from the fleet /// </summary> /// <param name="uuid"></param> public void DeletePosition(string uuid) { OpPosition pos = GetPosition(uuid); if (pos != null) { // Remove the position from the unit it belongs to FleetUnit unit = GetUnit(pos.unitUUID); if (unit != null) { if (unit is Ship) { (unit as Ship).positions.Remove(pos); } else if (unit is Boat) { (unit as Boat).positions.Remove(pos); } } ClearPosition(uuid); // Remove position from the lookup positionsLookup.Remove(uuid); } }
private void Context_AddBoatPosition(object sender, RoutedEventArgs e) { FleetUnit unit = (sender as MenuItem).DataContext as FleetUnit; SimpleDropdownSelect select = new SimpleDropdownSelect( CommonData.boatRoles.ConvertAll <string>((r) => { return(r.name); })); select.ReturnSelected += (index) => { MessageRouter.Instance.Send( MessageRouter.Service.Ops, new ANWI.Messaging.Ops.AddPosition() { opUUID = opUUID, unitUUID = unit.uuid, roleID = new List <int>() { CommonData.boatRoles[index].id } }, null); }; select.ShowDialog(); }
private void List_Positions_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { // This event was sent by a the Positions listbox ListBox positions = sender as ListBox; // From that listbox we can get the root of the datatemplate // by going up one level Grid namedShip = positions.Parent as Grid; // This datatemplate has a FleetCompElement datacontext, which can // be used to set the currently selected item in the main OOB list List_Fleet.SelectedItem = namedShip.DataContext; selectedShip = namedShip.DataContext as FleetUnit; // Clear the selection from the previous listbox so it doesn't // get stuck if (activePositionList != null && activePositionList != positions) { activePositionList.SelectedItem = null; } activePositionList = positions; } }
List_Fleet_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { // Newly selected element FleetUnit elem = e.AddedItems[0] as FleetUnit; // If this element is set as the active outer list item then // this change was caused by List_Positions_SelectionChanged. // If that is the case there is nothing more to do // If this call was generated by an actual list selection, // these would not be equal if (elem != null && elem != selectedShip) { // This was generated by a click in the OOB listbox // Clear the selection of the positions list if (activePositionList != null) { activePositionList.SelectedItem = null; activePositionList = null; } selectedShip = elem; } } }
private void Context_DeleteUnit(object sender, RoutedEventArgs e) { FleetUnit elem = (sender as MenuItem).DataContext as FleetUnit; if (elem != null) { MessageRouter.Instance.Send( MessageRouter.Service.Ops, new ANWI.Messaging.Ops.DeleteOOBElement(opUUID, elem.uuid), null); } }
private void Context_SetWingCommander(object sender, RoutedEventArgs e) { FleetUnit unit = (sender as MenuItem).DataContext as FleetUnit; MessageRouter.Instance.Send( MessageRouter.Service.Ops, new ANWI.Messaging.Ops.ModifyUnit() { opUUID = opUUID, unitUUID = unit.uuid, type = ANWI.Messaging.Ops.ModifyUnit.ChangeType.SetWingCommander }, null ); }
// todo zavershit logiku. poluchit mody ot planet_charaktera // на планете должен быть метод который возвразает персоонажа а у персоонажа должен быть метод который возвращает планету // public void FleetConstruction(FleetUnit unit, int cuantity) { var db = new skagryDataContext(); var tblShipyard = db.GetTable <shipyard_turn>(); var startTime = DateTime.UtcNow; var endTime = startTime.AddHours(1); tblShipyard.InsertOnSubmit(new shipyard_turn { planet_id = 1, unit_name = unit.GetName(), cuantity = cuantity, start_time = startTime, end_time = endTime }); }
Context_MassAddBoatPosition(object sender, RoutedEventArgs e) { FleetUnit unit = (sender as MenuItem).DataContext as FleetUnit; MassAddRoles mar = new MassAddRoles(CommonData.boatRoles); mar.returnNewPositions += (positions) => { MessageRouter.Instance.Send( MessageRouter.Service.Ops, new ANWI.Messaging.Ops.AddPosition() { opUUID = opUUID, unitUUID = unit.uuid, roleID = positions }, null); }; mar.ShowDialog(); }
private void Context_AddWingMember(object sender, RoutedEventArgs e) { FleetUnit wing = (sender as MenuItem).DataContext as FleetUnit; SimpleDropdownSelect select = new SimpleDropdownSelect( CommonData.smallHulls.ConvertAll <string>((h) => { return(h.name); })); select.ReturnSelected += (index) => { MessageRouter.Instance.Send( MessageRouter.Service.Ops, new ANWI.Messaging.Ops.AddOOBUnit() { opUUID = opUUID, wingUUID = wing.uuid, type = ANWI.Messaging.Ops.AddOOBUnit.Type.Boat, hullId = CommonData.smallHulls[index].id }, null); }; select.ShowDialog(); }
/// <summary> /// Adds a position to a ship or boat set in the positions unitUUID /// field. /// </summary> /// <param name="pos"></param> public void AddPosition(OpPosition pos) { if (pos.unitUUID == "") { throw new ArgumentException( "Position must have a unitUUID to be added"); } FleetUnit unit = GetUnit(pos.unitUUID); if (unit is Ship) { Ship ship = unit as Ship; ship.positions.Add(pos); positionsLookup.Add(pos.uuid, pos); } else if (unit is Boat) { Boat boat = unit as Boat; boat.positions.Add(pos); positionsLookup.Add(pos.uuid, pos); } }
private void Context_WingRoleDropship(object sender, RoutedEventArgs e) { FleetUnit unit = (sender as MenuItem).DataContext as FleetUnit; ChangeWingtype(unit.uuid, Wing.Role.DROPSHIP); }
private void Context_WingRoleBomber(object sender, RoutedEventArgs e) { FleetUnit unit = (sender as MenuItem).DataContext as FleetUnit; ChangeWingtype(unit.uuid, Wing.Role.BOMBER); }
private void Context_WingRoleInterceptor(object sender, RoutedEventArgs e) { FleetUnit unit = (sender as MenuItem).DataContext as FleetUnit; ChangeWingtype(unit.uuid, Wing.Role.INTERCEPTOR); }
/// <summary> /// Adds a unit to the fleet /// </summary> /// <param name="unit"></param> public void AddUnit(FleetUnit unit) { // Check that this ship is not already in the list if (GetUnit(unit.uuid) != null) { throw new ArgumentException( $"Ship {unit.uuid} already in fleet"); } // Add relevant members to lookup dictionaries if (unit is Ship) { Ship ship = unit as Ship; // Add all positions foreach (OpPosition p in ship.positions) { positionsLookup.Add(p.uuid, p); if (p.filledById != -1) { assignedPositionAdded?.Invoke(p); } } fleetLookup.Add(unit.uuid, unit); fleetList.Add(unit); } else if (unit is Wing) { Wing wing = unit as Wing; // Add each boat foreach (Boat b in wing.members) { boatLookup.Add(b.uuid, b); // Add each position to the lookup foreach (OpPosition p in b.positions) { positionsLookup.Add(p.uuid, p); if (p.filledById != -1) { assignedPositionAdded?.Invoke(p); } } } fleetLookup.Add(unit.uuid, unit); fleetList.Add(unit); } else if (unit is Boat) { Boat boat = unit as Boat; Wing wing = GetUnit(boat.wingUUID) as Wing; wing.members.Add(boat); boat.callsign = $"{wing.callsign} {wing.members.Count}"; // Add all positions foreach (OpPosition p in boat.positions) { positionsLookup.Add(p.uuid, p); if (p.filledById != -1) { assignedPositionAdded?.Invoke(p); } } boatLookup.Add(boat.uuid, boat); } }
/// <summary> /// Deletes a unit from the fleet /// </summary> /// <param name="uuid"></param> /// <returns>A list of all player IDs which were assigned to /// positions on this ship</returns> public List <int> DeleteUnit(string uuid) { FleetUnit unit = GetUnit(uuid); // Clear all lookups List <int> removedPos = new List <int>(); if (unit is Ship) { Ship ship = unit as Ship; foreach (OpPosition pos in ship.positions) { // Unassign the position from the user if (pos.filledById != -1) { removedPos.Add(pos.filledById); ClearPosition(pos.uuid); } positionsLookup.Remove(pos.uuid); } // Remove from the fleet fleetLookup.Remove(uuid); fleetList.Remove(ship); } else if (unit is Wing) { // Remove each boat from the lookup Wing wing = unit as Wing; foreach (Boat boat in wing.members) { boatLookup.Remove(boat.uuid); // Unassign each position on the board foreach (OpPosition pos in boat.positions) { if (pos.filledById != -1) { removedPos.Add(pos.filledById); ClearPosition(pos.uuid); } positionsLookup.Remove(pos.uuid); } } // Remove from the fleet fleetLookup.Remove(uuid); fleetList.Remove(wing); } else if (unit is Boat) { Boat boat = unit as Boat; if (boat.wingUUID == "") { throw new ArgumentException( "Boat must have wingUUID to be added"); } // Remove all positions from the lookup foreach (OpPosition pos in boat.positions) { if (pos.filledById != -1) { removedPos.Add(pos.filledById); ClearPosition(pos.uuid); } positionsLookup.Remove(pos.uuid); } // Remove boat from lookup and wing boatLookup.Remove(boat.uuid); Wing wing = GetUnit(boat.wingUUID) as Wing; wing.members.Remove(boat); } return(removedPos); }
void Awake() { raycaster = GetComponent <GraphicRaycaster>(); parentFleet = transform.root.GetComponent <FleetUnit>(); fleetStatusIcon = transform.GetChild(0).gameObject.GetComponent <Image>(); }