/** * <summary> * Updates the cottage interface, if any selected * </summary> */ public void UpdateCottageUI(Cottage cottage) { if (cottage == null) { //Disable buttons for (int i = 0; i < cottageList.Length; i++) { cottageList[i].IsVisible = false; } } else { List <WorldObject> people = cottage.GetPeople(); //Enable buttons for each person for (int i = 0; i < people.Count; i++) { WorldObject wo = people[i]; cottageList[i].Text = string.Format("{0}: {1} - {2}/{3}", i + 1, wo.GetWoName(), wo.GetHealth(), wo.GetMaxHealth()); cottageList[i].IsVisible = true; } //Disable the rest of buttons for (int i = people.Count; i < cottageList.Length; i++) { cottageList[i].IsVisible = false; } } }
public bool CanAct(WorldObject other) { bool res = other != null && !other.IsDestroyed(); if (res) { Cottage cottage = other.Owner.FindComponent <Cottage>(); LayerTile l1 = Map.map.GetTileByWorldPosition(cottage.wo.GetCenteredPosition()); LayerTile l2 = Map.map.GetTileByWorldPosition(wo.GetCenteredPosition()); res = !cottage.UnderConstruction() && cottage.GetCount() < cottage.maxOccupation && !cottage.GetPeople().Contains(wo) && wo.player == cottage.wo.player && Map.map.Adjacent(l1, l2) && (wo.GetAction() == ActionEnum.Exit || wo.GetAction() == ActionEnum.Idle); } return(res); }
/** * <summary> * Assumes selectedWO is not null. Checks all posible actions between selectedWO and any of the mouse tile WOs * </summary> */ private void HandleAction() { //We can't do anything if we are moving (you'd better not modify that) if (!selectedWO.IsActionBlocking()) { ui.ClearActionButtons(); //As always, when handling actions we must save the instances at the moment //If you remove this lines, when a person tries to exit a cottage, for example, //the tile for exit will be the currentTile below the button at the moment it is pressed (which will probably be null), and not the tile that was selected WorldObject currentWO = null; WorldObject currentMobile = null; LayerTile currentTile = this.currentTile; if (fog == null || fog.IsVisible(currentTile.X, currentTile.Y)) { currentWO = this.currentWO; currentMobile = this.currentMobile; } else if (fog.IsPartiallyVisible(currentTile.X, currentTile.Y)) { currentWO = fog.GetRevealedWO(currentTile.X, currentTile.Y); } foreach (ActionBehavior act in selectedWO.allActions) { if (act.CanShowButton(currentMobile)) { ui.AddAction(act.GetCommandName(currentMobile), () => HandleMovementAction(currentMobile, currentTile, act)); } if (act.CanShowButton(currentWO)) { ui.AddAction(act.GetCommandName(currentWO), () => HandleMovementAction(currentWO, currentTile, act)); } } if (selectedWO.IsMobile()) { //A button to move if "we see" the tile is free if ((currentWO == null || currentWO.IsTraversable(selectedWO)) && (currentMobile == null || currentMobile.IsTraversable(selectedWO))) { ui.AddAction("Move", () => CalculatePathDStar(selectedWO, currentTile)); } } Cottage cottage = selectedWO.Owner.FindComponent <Cottage>(); if (cottage != null) { for (int i = 0; i < cottage.GetPeople().Count; i++) { //Careful with event handlers, actions in loops, because the i variable wont work int aux = i; WorldObject peopleInside = cottage.GetPeople()[aux]; if ((currentMobile == null || currentMobile.IsTraversable(peopleInside)) && (currentWO == null || currentWO.IsTraversable(peopleInside))) { ui.AddAction(string.Format("Exit cottage {0}: {1}", aux + 1, cottage.GetPeople()[aux].GetWoName()), () => SendExit(aux + 1, currentTile)); } } } if (ui.actions.Count == 1) { //if there is only an action, we directly execute it ui.ExecuteAction(0); } else if (ui.actions.Count > 1) { for (int i = 0; i < ui.actions.Count; i++) { //Careful with event handlers, actions in loops, because the i variable wont work int aux = i; if (i >= ui.buttons.Count) { //We have less buttons than actions, create a new one ui.CreateActionButton(); } ui.UpdateActionButton(aux); } ui.optionsAlreadyShown = true; lastActionTile = currentTile; WaveServices.Layout.PerformLayout(Owner.Scene); } } }