public static void AddButtonSound(Button g, string sound) { if (sound != null) { g.onClick.AddListener(() => { NAudio.Play(sound); }); } }
public Toggle AddCheckbox(bool value, string title, UnityAction <bool> save, string audio = "checkBoxClick") { Toggle button = UIElements.CreateCheckBox(panel.transform, title, save).GetComponent <Toggle>(); button.isOn = value; button.onValueChanged.AddListener((pos) => { NAudio.Play(audio); }); return(button); }
public Button CreateImageTextButton(Transform transform, Player player) { Button button = UIHelper.CreateImageTextButton(LSys.tem.inputs.GameButtonName(this), LClass.s.Button(id).Sprite(player), transform, () => { NAudio.Play(Sound); Call(player); }); return(button); }
private void ShowDetail() { if (infoPanel.transform.childCount > 0) { UIHelper.ClearChild(infoPanel); } PanelBuilder p = PanelBuilder.Create(infoPanel.transform); selectedElement.ShowDetail(p); p.CalcSize(); NAudio.Play(selectedElement.audioSwitch); }
/// <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()); }
public void SetButtonText(string buttonText) { if (buttonText == null) { return; } selectButtonText = buttonText; selectButton = UIHelper.CreateButton("Select an element first", buttonPanel.transform, () => { NAudio.Play(selectedElement.audioPerform); selectedElement.Perform(); }, null).GetComponent <Button>(); selectButton.enabled = false; }
public InputField AddInputRandom(string title, string def, UnityAction <string> save, Func <string> random) { InputField input = Instantiate(UIElements.Get().inputRandom, panel.transform); input.transform.GetChild(0).GetComponent <Text>().text = $"Enter {title}..."; input.text = def; input.onValueChanged.AddListener(val => { save(val); }); Button button = input.transform.GetChild(2).GetComponent <Button>(); button.onClick.AddListener(() => { NAudio.Play("random"); }); button.onClick.AddListener(() => { input.text = random(); }); return(input); }
private void ShowDetail() { if (infoPanel.transform.childCount > 0) { foreach (Transform child in infoPanel.transform) { Destroy(child.gameObject); } ; } PanelBuilder p = PanelBuilder.Create(infoPanel.transform); selectedElement.ShowDetail(p); p.CalcSize(); NAudio.Play(selectedElement.audioSwitch); }
IEnumerator LoadGame() { yield return(load.ShowMessage("Loading " + startConfig["file"])); yield return(load.ShowSubMessage($"Loading library")); L.b = ES3.Load <L>("lib", startConfig["file"] + "lib.9n"); yield return(load.ShowSubMessage($"Loading file")); data = ES3.Load <GameData>("game", startConfig["file"] + "game.9n"); ConnectGameObjs(); //load Map yield return(newMap.LoadMap()); yield return(load.ShowSubMessage($"Loading players")); yield return(data.players.GameLoaded()); yield return(data.players.GameBegin()); //load buildings yield return(load.ShowSubMessage($"Loading Buildings")); foreach (BuildingUnitData bdata in data.buildings.ToArray()) { building.Load(bdata); } //load units yield return(load.ShowSubMessage($"Loading Units")); foreach (BuildingUnitData udata in data.units) { unit.Load(udata); } //init data gameRound.Load(); //init players S.ActPlayer().StartRound(); NAudio.Play("startgame"); load.FinishLoading(); }
public IEnumerator StartScenario(string id, string map) { //load Map data.map.id = map; data.name = LSys.tem.scenarios[id].Name(); yield return(newMap.CreateMap()); yield return(load.ShowSubMessage($"Loading players")); try { LClass.s.scenarioRuns[id].Run(); } catch (Exception e) { ExceptionHelper.ShowException(e); throw e; } //add modis foreach (var option in L.b.gameOptions.GetAllByCategory("modi")) { if (!startConfig.ContainsKey(option.id)) { continue; } var val = Convert.ToInt32(startConfig[option.id]); if (val == 0) { continue; } data.modi[option.id] = val + "%"; Debug.Log(option.id + ":" + val + "%"); } yield return(data.players.GameStart()); yield return(data.players.GameBegin()); yield return(data.players.NextPlayer()); NAudio.Play("startgame"); load.FinishLoading(); }
private void ClickButton(SplitElement ele) { //same element? if (ele.disabled == null && ele == selectedElement && selectButton != null) { NAudio.Play(selectedElement.audioPerform); selectedElement.Perform(); CloseWindow(); return; } //show infos selectedElement = ele; //create panel ShowDetail(); UpdateButton(); }
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)))); }
public void Create(string id, NVector pos) { NAnimation nAni = L.b.animations[id]; //create animation var ani = AnimationObject.Create(pos); ani.sprites = nAni.Sprites(); if (ani.sprites == null) { Debug.LogError(nAni.Icon + " is wrong formed"); return; } Debug.Log(nAni.Icon + " found animation " + ani.sprites.Count); //play sound? if (!string.IsNullOrEmpty(nAni.sound)) { NAudio.Play(nAni.sound); } ani.countMax = nAni.speed; }
private void ClickButton(SplitElement ele) { //disabled? if (ele.disabled != null) { //has a button? if (selectButton != null) { UIHelper.UpdateButtonText(selectButton, ele.disabled); selectButton.GetComponent <Button>().enabled = false; } selectedElement = ele; ShowDetail(); return; } //same element? if (ele == selectedElement && selectButton != null) { NAudio.Play(selectedElement.audioPerform); selectedElement.Perform(); return; } //show infos selectedElement = ele; if (selectButton != null) { selectButton.GetComponent <Button>().enabled = true; UIHelper.UpdateButtonText(selectButton, $"{selectButtonText} {ele.title}"); } //create panel ShowDetail(); }
public void DestroyWindow() { Destroy(gameObject); NAudio.Play("windowClose"); }
public void MoveBy(int x, int y) { //own unit? if (!Owner(S.ActPlayerID())) { OnMapUI.Get().unitUI.ShowPanelMessageError(S.T("unitMoveErrorBelong", name, Player().name)); return; } //own unit? if (IsUnderConstruction()) { OnMapUI.Get().unitUI.ShowPanelMessageError(S.T("unitMoveErrorConstruction", name)); return; } int dX = data.pos.x + x; int dY = data.pos.y + y; NVector dPos = new NVector(dX, dY, Pos().level); //can move their? string erg = Passable(dPos); if (erg != null) { OnMapUI.Get().unitUI.ShowPanelMessageError(erg); return; } //start animation var pPath = GameMgmt.Get().newMap.PathFinding(Pos().level).Path(Player(), dataUnit.movement, Pos(), dPos); //rebuild path Vector3[] path = new Vector3[pPath.Count]; for (int i = 0; i < pPath.Count; i++) { path[i] = new Vector2(pPath[i].x + 0.5f, pPath[i].y); } GetComponent <UnitAnimator>().MoveAnimationCalc((int)path[0].x - data.pos.x, (int)path[0].y - data.pos.y); // completion defaults to null if not passed in gameObject.transform.DOPath(path, pPath.Count, PathType.CatmullRom) .OnWaypointChange(value => { if (value >= path.Length) { return; } Clear(new NVector((int)path[value].x, (int)path[value].y, Pos().level)); if (value >= 1) { GetComponent <UnitAnimator>().MoveAnimationCalc((int)path[value].x - (int)path[value - 1].x, (int)path[value].y - (int)path[value - 1].y); } }) .OnComplete(() => { GetComponent <UnitAnimator>().ResetRunning(); OnMapUI.Get().UpdatePanel(dPos); transform.position = new Vector2(Pos().x + 0.5f, Pos().y); }); data.ap -= GameMgmt.Get().newMap.PathFinding(Pos().level).Cost(Player(), dataUnit.movement, Pos(), dPos); data.pos.x += x; data.pos.y += y; S.CameraMove().MoveTo(dPos); NAudio.Play("moveUnit"); }
public void Perform(Player player, MapElementInfo mapElementInfo, NVector pos, bool ani) { //mapElementInfo.data.ap -= cost; var target = S.MapElement(pos); string msg = null; int ap = 0; int chance = mapElementInfo.data.spells.CalcChance(id); mapElementInfo.data.spells.Cast(id); target = (target != null) ? target : mapElementInfo; //can perform? if (chance > Random.Range(0, 100)) { //calc cost foreach (var ah in action.actions) { ap += ah.DataAction().cost; } mapElementInfo.data.ap += ap; //tmp for spell using msg = action.Performs(ActionEvent.All, player, target, pos); //success? if (String.IsNullOrEmpty(msg)) { if (ani && !String.IsNullOrEmpty(animation)) { L.b.animations.Create(animation, pos); NAudio.Play(Sound); if (!mapElementInfo.IsBuilding()) { ((UnitInfo)mapElementInfo).UnitAnimator().PlayIdleAnimation(UnitAnimatorType.Cast); } } mapElementInfo.AddNoti(S.T("spellSuccess", Name()), Icon); return; } } //falure //calc cost ap = 0; foreach (var ah in action.actions) { ap += ah.DataAction().cost; } mapElementInfo.data.ap += ap; //tmp for spell using var nmsg = actionFail.Performs(ActionEvent.All, player, target, pos); if (ani) { L.b.animations.Create("broken", pos); mapElementInfo.UI().ShowPanelMessageError(S.T("spellError", Name())); } msg = $"{msg} {nmsg}"; mapElementInfo.AddNoti(S.T("spellError", Name(), msg), Icon); }