public override void Perform() { window.Close(); perform.Invoke(cost); OnMapUI.Get().UpdatePanel(pos); }
protected override void ClickFirst() { string moveTyp = ((UnitInfo)mapElementInfo).dataUnit.movement; int cost = GameMgmt.Get().newMap.PathFinding(mapElementInfo.Pos().level).Cost(player, moveTyp, mapElementInfo.Pos(), new NVector(LastClickPos.x, LastClickPos.y, mapElementInfo.Pos().level)); OnMapUI.Get().unitUI.ShowPanelMessage($"You want to move to this field for {cost} AP? Click again!"); }
public void ShowNextAvailableUnitForPlayer() { //has an active unit? //Debug.LogWarning(FindObjectOfType<OnMapUI>()); UnitInfo u = FindObjectOfType <OnMapUI>().unitUI.active; UnitInfo[] unitP = GetByPlayer(S.ActPlayer().id); //has units? if (unitP.Length == 0) { return; } //get startpos? int s = u == null?0:Array.IndexOf(unitP, u); //find next for (int i = 0; i < unitP.Length; i++) { UnitInfo ui = unitP[(i + s + 1) % unitP.Length]; //right unit? if (!ui.IsUnderConstruction() && ui.data.ap > 0 && ui.data.waiting == null) { FindObjectOfType <OnMapUI>().UpdatePanel(ui.GetData().pos); S.CameraMove().MoveTo(ui.GetData().pos); return; } } //nothing found? OnMapUI.Get().ShowPanelMessageError("No available unit found."); }
public static void WaitRound(ActionHolders holder, ActionHolder action, MapElementInfo info, NVector pos, int cost = -1, string sett = null, ActionEvent evt = ActionEvent.Direct) { FDataAction da = action.DataAction(); cost = cost == -1 ? action.cost : cost; int round = (int)Math.Ceiling((1f * cost - info.data.ap) / info.data.apMax); WindowPanelBuilder wpb = WindowPanelBuilder.Create($"Wait for {da.Name()}?"); wpb.panel.RichText(da.Desc()); wpb.panel.AddImageLabel($"Action {da.Name()} need {cost - info.data.ap} AP more. You can wait {round} rounds.", "round"); wpb.panel.AddButton($"Wait {round} rounds", () => { var aw = new ActionWaiting(action, holder, pos); aw.apMax = cost; aw.sett = sett; aw.evt = evt; info.SetWaitingAction(aw); L.b.animations.Create("sandClock", pos); OnMapUI.Get().UpdatePanel(info.Pos()); wpb.Close(); }); wpb.AddClose(); wpb.Finish(); }
protected override void Perform(ActionEvent evt, Player player, ActionHolder holder) { var towns = S.Towns().GetByPlayer(player.id); if (towns.Count == 0) { OnMapUI.Get().ShowPanelMessageError("No town for trading."); return; } if (towns.Count == 1) { new ActionTradeWindow(towns[0], holder.data["trade"]); return; } WindowPanelBuilder wpb = WindowPanelBuilder.Create("Where do you want to trade?"); foreach (var town in towns) { wpb.panel.AddImageTextButton(town.name, town.GetIcon(), () => { new ActionTradeWindow(town, holder.data["trade"]); wpb.Close(); }); } wpb.AddClose(); wpb.Finish(); }
public override void Perform() { MaterialWindow.ShowBuildMaterialWindow(build, pos, cost => { go.Upgrade(build.id, cost); }); OnMapUI.Get().UpdatePanel(pos); }
public IMapUI UI() { if (IsBuilding()) { return(OnMapUI.Get().buildingUI); } return(OnMapUI.Get().unitUI); }
public override void Add(Info noti) { base.Add(noti); //Debug.Log(player+" "+noti.title); if (player != null && player == S.ActPlayer()) { OnMapUI.Get().InfoUi.AddInfoButton(noti); } }
private bool Check(int level) { if (level < 0 || level >= _map.levels.Count) { OnMapUI.Get().ShowPanelMessageError("This level does not exist."); return(false); } return(true); }
public override void Perform() { UpdatePref("lastBuild"); ism.Close(); MaterialWindow.ShowBuildMaterialWindow(build, pos, cost => { GameMgmt.Get().building.Create(S.Towns().NearestTown(S.ActPlayer(), pos, false).id, build.id, pos, cost); OnMapUI.Get().UpdatePanel(pos); }); }
protected override SplitElement CreateSplitElement(DataUnit build, MapElementInfo info, NVector pos, ISplitManager ism) { return(new BaseSelectElementSplitElement <DataUnit>(id, build, info, pos, ism, (mei, position) => { MaterialWindow.ShowBuildMaterialWindow(build, pos, cost => { GameMgmt.Get().unit.Create(S.ActPlayerID(), build.id, pos, cost); OnMapUI.Get().UpdatePanel(pos); }); })); }
protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder) { //info.data.ap = 0; if (evt == ActionEvent.Direct) { info.SetRepeatAction(new ActionWaiting(holder, info.data.action, pos)); OnMapUI.Get().UpdatePanel(info.Pos()); } }
protected override SplitElement CreateSplitElement(DataBuilding build, MapElementInfo info, NVector pos, ISplitManager ism) { return(new BaseSelectElementSplitElement <DataBuilding>(id, build, info, pos, ism, (mei, position) => { MaterialWindow.ShowBuildMaterialWindow(build, pos, cost => { GameMgmt.Get().building.Create(S.Towns().NearestTown(S.ActPlayer(), pos, false).id, build.id, pos, cost); OnMapUI.Get().UpdatePanel(pos); }); })); }
protected override void ClickFirst() { //load spell Spell spell = L.b.spells[action.data["waiting"]]; String desc; var mei = S.MapElement(LastClickPos); desc = mei != null ? mei.data.name : S.Game().newMap.Terrain(LastClickPos).Name(); OnMapUI.Get().unitUI.ShowPanelMessage(S.T("spellField", spell.Name(), desc)); }
private void FoundTown(MapElementInfo info, NVector pos, string townName, string coat, bool kill) { if (kill) { info.Kill(); } int tid = S.Towns().Create(townName, pos); S.Town(tid).coat = coat; OnMapUI.Get().UpdatePanel(pos); S.ActPlayer().UpdateButtonMenu(); }
protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder) { DataTerrain terrain = GameMgmt.Get().newMap.Terrain(pos); //which is possible? List <(string key, string value)> opts = new List <(string key, string value)>(); int i = 0; while (holder.data.ContainsKey(i.ToString())) { var d = SplitHelper.Split(holder.data[i.ToString()]); if (terrain.id == d.key) { opts.Add(d); } i++; } //found it? if (opts.Count == 0) { OnMapUI.Get().unitUI.ShowPanelMessageError($"No terraform possible for {terrain.Name()}"); return; } Vector3Int v3 = new Vector3Int(pos.x, pos.y, 1); //TODO find right pos if (opts.Count == 1) { GameMgmt.Get().newMap.levels[pos.level] .SetTile(v3, opts[0].value == "remove" ? null : L.b.terrains[opts[0].value]); return; } //multiple? WindowPanelBuilder wpb = WindowPanelBuilder.Create($"Terraform {terrain.Name()}"); foreach (var opt in opts) { wpb.panel.AddImageTextButton(CreateTitle(opt), terrain.Sprite(), () => { GameMgmt.Get().newMap.levels[pos.level] .SetTile(v3, opt.value == "remove" ? null : L.b.terrains[opt.value]); wpb.Close(); }); } wpb.AddClose(); wpb.Finish(); }
private void MoveUnit(MapElementInfo info, NVector pos) { UnitInfo ui = (UnitInfo)info; int l = GameMgmt.Get().data.map.levels.Count; //TODO check if go up/down possible? //how many level i have? if (l == 1) { OnMapUI.Get().unitUI.ShowPanelMessageError($"{info.name} can not move between the levels, there is no second level"); return; } if (l == 2) { //switch it TryMoveUnit(ui, new NVector(pos.x, pos.y, (pos.level + 1) % 2)); return; } if (pos.level == 0) { //go up TryMoveUnit(ui, pos.DiffLevel(+1)); return; } if (pos.level + 1 == l) { //go down TryMoveUnit(ui, pos.DiffLevel(-1)); return; } //ask WindowPanelBuilder wpb = WindowPanelBuilder.Create("Where do you want to go?"); wpb.panel.AddButton($"Go up to {GameMgmt.Get().data.map.levels[pos.level + 1].name}", () => { TryMoveUnit(ui, pos.DiffLevel(+1)); wpb.Close(); }); wpb.panel.AddButton($"Go down to {GameMgmt.Get().data.map.levels[pos.level - 1].name}", () => { TryMoveUnit(ui, pos.DiffLevel(-1)); wpb.Close(); }); wpb.AddClose(); wpb.Finish(); }
/// <summary> /// Press the game button /// </summary> /// <param name="key"></param> private void PressGameButton(InputKey key) { GameButton gameButton = L.b.gameButtons[key.id]; //check if possible to call if (!gameButton.req.Check(ActPlayer())) { OnMapUI.Get().ShowPanelMessageError(gameButton.req.Desc(ActPlayer())); return; } //call it NAudio.Play(gameButton.Sound); gameButton.Call(ActPlayer()); }
protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder) { //get tilemap tileMap = GameMgmt.Get().newMap[pos.level].border.GetComponent <Tilemap>(); Points = new List <PPoint>(); //save caller this.player = player; mapElementInfo = info; this.initPos = pos; action = holder; //set as active action OnMapUI.Get().SetActiveAction(this, mapElementInfo.IsBuilding()); PreRun(); }
private void MoveBuilding(MapElementInfo info, NVector pos, ActionHolder holder) { BuildingInfo ui = (BuildingInfo)info; //check status if (!info.data.data.ContainsKey("level")) { //build stairs int l = GameMgmt.Get().data.map.levels.Count; //blocked by buildings? bool up = pos.level + 1 < l && S.Building().Free(pos.DiffLevel(1)); bool down = pos.level > 0 && S.Building().Free(pos.DiffLevel(-1)); if (!up && !down) { OnMapUI.Get().unitUI.ShowPanelMessageError($"{info.name} can not work between the levels, there is no second level or it is blocked."); return; } //ask? if (up && down) { WindowPanelBuilder wpb = WindowPanelBuilder.Create("Where do you want to build your stairs?"); wpb.panel.AddButton($"Build stairs up to {GameMgmt.Get().data.map.levels[pos.level + 1].name}", () => { Build(true, info, pos, holder); wpb.Close(); }); wpb.panel.AddButton($"Build stairs down to {GameMgmt.Get().data.map.levels[pos.level - 1].name}", () => { Build(false, info, pos, holder); wpb.Close(); }); wpb.AddClose(); wpb.Finish(); return; } Build(up, info, pos, holder); } //move unit int diff = ConvertHelper.Int(info.data.data["level"]); TryMoveUnit(S.Unit().At(pos), pos.DiffLevel(diff)); }
/// <summary> /// Show this unit /// </summary> /// <param name="building"></param> public override void UpdatePanel(BuildingInfo building) { S.InputAction().SetActive(building); active = building; OnMapUI.Get().InfoUi.UpdatePanel(); //no unit? if (building == null) { //hide it gameObject.SetActive(false); return; } UpdateInfoButton(active.Sprite()); AddButtons(); }
protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos, ActionHolder holder) { //info.data.ap = 0; if (evt == ActionEvent.Direct) { //is the townhall or unit? if (info.IsBuilding()) { //transform to the other unit? var unit = S.Unit(info.Pos()); var cost = ConvertHelper.Int(holder.data["cost"]); if (unit.data.ap < cost) { //clone action var ua = Create(holder.data["cost"]); CreateAddCount(ua, ActionEvent.Direct, "1", false); ua.cost = cost; ua.data["pos"] = unit.Pos().ToString(); unit.data.action.Add(ua); ActionHelper.WaitRound(unit.data.action, ua, unit, unit.Pos()); return; } info.SetRepeatAction(new ActionWaiting(holder, info.data.action, pos)); OnMapUI.Get().UpdatePanel(info.Pos()); return; } //moved? var opos = new NVector(holder.data["pos"]); if (!opos.Equals(info.Pos())) { OnMapUI.Get().unitUI.ShowPanelMessageError(S.T("occupyMoved")); return; } //transfer var build = S.Building(info.Pos()); build.Town().Transfer(info.data.playerId); OnMapUI.Get().UpdatePanel(info.Pos()); } }
/// <summary> /// Show this unit /// </summary> /// <param name="unit"></param> public override void UpdatePanel(UnitInfo unit) { S.InputAction().SetActive(unit); active = unit; OnMapUI.Get().InfoUi.UpdatePanel(); //no unit? if (unit == null) { //hide it gameObject.SetActive(false); return; } UpdateInfoButton(unit.dataUnit.AnimationSprite(UnitAnimatorType.Face)); AddButtons(); }
public override void ShowDetail(PanelBuilder panel) { base.ShowDetail(panel); panel.AddButton($"Show details for {town.name}", (() => town.ShowDetails())); panel.AddHeaderLabel("Buildings"); //add buildings foreach (BuildingInfo info in GameMgmt.Get().building.GetByTown(town.id)) { panel.AddImageTextButton(info.name, info.baseData.Sprite(), () => { S.CameraMove().MoveTo(info.Pos()); OnMapUI.Get().UpdatePanel(info.Pos()); b.CloseWindow(); }); } }
private void ShowTown() { //remove actions UIHelper.ClearChild(infoButtons); //has element? MapElementInfo mei = OnMapUI.Get().GetActive(); if (mei == null) { return; } Debug.Log("show town"); Debug.Log(mei); //has town? Town town = mei.Town(); if (town == null) { return; } //open town var button = UIElements.CreateImageButton(town.GetIcon(), infoButtons.transform, town.ShowDetails); button.transform.GetChild(0).GetComponent <Image>().color = town.Coat().color; UIHelper.HoverEnter(button, () => ShowPanelMessage(S.T("townDetails", mei.name, town.name)), () => ShowPanelMessage("")); //todo limit res int max = 10; // show res foreach (var r in L.b.res.Values()) { if (!town.KnowRes(r.id) || r.special) { continue; } int count = town.GetRes(r.id); var img = UIElements.CreateImageCounter(infoButtons.transform, count, r.Icon); UIHelper.HoverEnter(img, () => ShowPanelMessage(S.T("townRes", town.name, r.Text(count))), () => ShowPanelMessage("")); } }
public override void ShowDetail(PanelBuilder panel) { foreach (UnitInfo info in GameMgmt.Get().unit.GetByPlayer(S.ActPlayer().id)) { if (town != null && town.id != info.data.townId) { continue; } panel.AddImageTextButton(info.name, info.baseData.Sprite(), () => { S.CameraMove().MoveTo(info.Pos()); OnMapUI.Get().UpdatePanel(info.Pos()); b.CloseWindow(); info.ShowInfoWindow(); }); } }
void MoveCamera(int x, int y) { if (S.CameraMove().IsMoving()) { return; } //valid pos? if (!S.Valid((int)_trans.position.x + x, (int)_trans.position.y + y)) { OnMapUI.Get().ShowPanelMessageError("The camera position is to far outside of the map."); return; } S.CameraMove().MoveBy(x, y); }
public virtual void Perform(MapElementInfo self, MapElementInfo nonSelf) { // calc damage int damage = CalcDamage(self, nonSelf); string a = $"{self.name} ({self.Player().name})"; string d = $"{nonSelf.name} ({nonSelf.Player().name})"; Debug.LogError("Damage:" + damage); // check it if (damage == 0) { OnMapUI.Get().unitUI.ShowPanelMessage(S.T("attackDamEqual", self.name, d)); NAudio.Play("defend"); //inform another player nonSelf.AddNoti($"Defended against {a}", self.baseData.Icon); return; } // counter fight if (damage < 0) { Perform(nonSelf, self); OnMapUI.Get().unitUI.ShowPanelMessage($"{d} fight back."); return; } // win ShowUnitAttack(self, nonSelf); nonSelf.AddHp(-damage); L.b.animations.Hp(-damage, nonSelf.Pos(), nonSelf); OnMapUI.Get().unitUI.ShowPanelMessage($"You won. {d} lose {damage} HP."); nonSelf.AddNoti($"{a} attacked you. {nonSelf.name} lose {damage} HP.", self.baseData.Icon); //int oX = defensor.getX(); //int oY = defensor.getY(); //UiHelper.textAnimation("-" + damage + " hp", oX, oY, true, Color.SALMON); //TODO add animation //defensor.getActor().addAction(Actions.sequence(Actions.color(Color.RED, 1), Actions.color(Color.WHITE, 1))); //getActor().addAction(Actions.parallel(Actions.sequence(Actions.moveTo(oX * 32, oY * 32, 1), Actions.moveTo(x * 32, y * 32, 1)), // Actions.sequence(Actions.color(Color.BLACK, 1), Actions.color(Color.WHITE, 1)))); }
void ZoomCamera(float zoom) { //valide? if (Camera.main.orthographicSize + zoom < 1) { OnMapUI.Get().ShowPanelMessageError("The camera zoom is to minimal"); Camera.main.orthographicSize = 1; return; } //valide? if (Camera.main.orthographicSize + zoom > 20) { OnMapUI.Get().ShowPanelMessageError("The camera zoom is to maximal"); Camera.main.orthographicSize = 20; return; } Camera.main.orthographicSize += zoom; }
protected void AddButtons() { //remove actions UIHelper.ClearChild(actions); //has active action? if (ActiveAction != null) { ShowPanelMessage(ActiveAction.PanelMessage()); FDataAction action = ActiveAction.DataAction(); UIHelper.CreateImageTextButton(S.T("actionCancel", action.Name()), action.Sprite(), actions.transform, () => { OnMapUI.Get().SetActiveAction(null, active.GetComponent <BuildingInfo>() != null); }, "cancel"); return; } //has waiting action? if (active.data.waiting != null) { //can perform? if (active.data.waiting.needPerform) { active.PerformWaitingAction(); return; } ActionHolder a = active.data.action.actions[active.data.waiting.actionPos]; UIHelper.CreateImageTextButton(S.T("actionWaitingCancel"), a.DataAction().Sprite(), actions.transform, () => { active.data.ap = Math.Max(0, Math.Min(active.data.waiting.ap, active.data.apMax)); active.SetWaitingAction(null); OnMapUI.Get().UpdatePanel(active.Pos()); }, "cancel"); return; } AddAllActionButtons(); }