예제 #1
0
    private void Start()
    {
        lifebar   = gameObject.GetComponentInChildren <LifeBarController>();
        lifebarRt = lifebar.GetComponent <RectTransform>();

        nameLevelTextManParent = GameObject.Find("NameLv");
        nameLevelTextManParent.transform.position = new Vector3(nameLevelTextManParent.transform.position.x, nameLevelTextManParent.transform.position.y - 1, nameLevelTextManParent.transform.position.z);
        hpTextManParent = GameObject.Find("HPTextParent");
        hpTextManParent.transform.position = new Vector3(hpTextManParent.transform.position.x, hpTextManParent.transform.position.y - 1, hpTextManParent.transform.position.z);

        nameLevelTextMan = nameLevelTextManParent.AddComponent <TextManager>();
        hpTextMan        = hpTextManParent.AddComponent <TextManager>();
        hpRect           = GameObject.Find("HPRect");

        hpTextMan.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_SMALLTEXT_NAME));
        initialized = true;
        setMaxHP();
        setPlayerInfo(PlayerCharacter.instance.Name, PlayerCharacter.instance.LV);
    }
예제 #2
0
    private void Start()
    {
        GameObject statsObj = GameObject.Find("Stats");

        lifebar   = statsObj.GetComponentInChildren <LifeBarController>();
        lifebarRt = lifebar.GetComponent <RectTransform>();

        nameLevelTextManParent = GameObject.Find("NameLv");
        hpTextManParent        = GameObject.Find("HPTextParent");

        nameLevelTextMan = nameLevelTextManParent.AddComponent <TextManager>();
        hpTextMan        = hpTextManParent.AddComponent <TextManager>();

        hpTextMan.setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_SMALLTEXT_NAME));
        initialized = true;
        setMaxHP();
        setHP(hpCurrent);
        setPlayerInfo(nameCurrent, lvCurrent);
    }
예제 #3
0
    public void SwitchState(UIState state)
    {
        //Pre-state
        if (parentStateCall)
        {
            parentStateCall = false;
            encounter.script.Call("EnteringState", new DynValue[] { DynValue.NewString(state.ToString()), DynValue.NewString(this.state.ToString()) });
            parentStateCall = true;

            if (childStateCalled)
            {
                childStateCalled = false;
                return;
            }
        }
        else
        {
            childStateCalled = true;
        }

        // TODO Quick and dirty addition to add some humor to the Run away command.
        // Will be removed without question.
        if (musicPausedFromRunning)
        {
            Camera.main.GetComponent <AudioSource>().UnPause();
            musicPausedFromRunning = false;
        }
        // END DEBUG

        // below: actions based on ending a previous state, or actions that affect multiple states
        if (this.state == UIState.DEFENDING && state != UIState.DEFENDING)
        {
            encounter.endWave();
        }

        if (state != UIState.ENEMYDIALOGUE && state != UIState.DEFENDING)
        {
            ArenaSizer.instance.Resize(ArenaSizer.UIWidth, ArenaSizer.UIHeight);
            PlayerController.instance.invulTimer = 0.0f;
            PlayerController.instance.setControlOverride(true);
        }

        if (this.state == UIState.ENEMYSELECT && action == Actions.FIGHT)
        {
            foreach (LifeBarController lbc in arenaParent.GetComponentsInChildren <LifeBarController>())
            {
                Destroy(lbc.gameObject);
            }
        }

        if (state == UIState.DEFENDING || state == UIState.ENEMYDIALOGUE)
        {
            textmgr.destroyText();
            PlayerController.instance.SetPosition(320, 160, false);
            PlayerController.instance.GetComponent <Image>().enabled = true;
            fightBtn.overrideSprite = null;
            actBtn.overrideSprite   = null;
            itemBtn.overrideSprite  = null;
            mercyBtn.overrideSprite = null;
            textmgr.setPause(true);
        }

        if (this.state == UIState.ENEMYDIALOGUE)
        {
            TextManager[] textmen = FindObjectsOfType <TextManager>();
            foreach (TextManager textman in textmen)
            {
                if (textman.gameObject.name.StartsWith("DialogBubble")) // game object name is hardcoded as it won't change
                {
                    Destroy(textman.gameObject);
                }
            }
        }

        this.state = state;
        switch (state)
        {
        case UIState.ATTACKING:
            textmgr.destroyText();
            PlayerController.instance.GetComponent <Image>().enabled = false;
            fightUI.Init(encounter.enabledEnemies[selectedEnemy]);
            break;

        case UIState.ACTIONSELECT:
            PlayerController.instance.setControlOverride(true);
            PlayerController.instance.GetComponent <Image>().enabled = true;
            setPlayerOnAction(action);
            textmgr.setPause(ArenaSizer.instance.isResizeInProgress());
            textmgr.setCaller(encounter.script);     // probably not necessary due to ActionDialogResult changes
            textmgr.setText(new RegularMessage(encounter.EncounterText));
            break;

        case UIState.ACTMENU:
            string[] actions = new string[encounter.enabledEnemies[selectedEnemy].ActCommands.Length];
            for (int i = 0; i < actions.Length; i++)
            {
                actions[i] = encounter.enabledEnemies[selectedEnemy].ActCommands[i];
            }

            selectedAction = 0;
            setPlayerOnSelection(selectedAction);
            textmgr.setText(new SelectMessage(actions, false));
            break;

        case UIState.ITEMMENU:
            string[] items = getInventoryPage(0);
            selectedItem = 0;
            setPlayerOnSelection(0);
            textmgr.setText(new SelectMessage(items, false));

            /*ActionDialogResult(new TextMessage[] {
             *  new TextMessage("Can't open inventory.\nClogged with pasta residue.", true, false),
             *  new TextMessage("Might also be a dog.\nIt's ambiguous.",true,false)
             * }, UIState.ENEMYDIALOG);*/
            break;

        case UIState.MERCYMENU:
            selectedMercy = 0;
            string[] mercyopts = new string[1 + (encounter.CanRun ? 1 : 0)];
            mercyopts[0] = "Spare";
            foreach (EnemyController enemy in encounter.enabledEnemies)
            {
                if (enemy.CanSpare)
                {
                    mercyopts[0] = "[starcolor:ffff00][color:ffff00]" + mercyopts[0] + "[color:ffffff]";
                    break;
                }
            }
            if (encounter.CanRun)
            {
                mercyopts[1] = "Flee";
            }
            setPlayerOnSelection(0);
            textmgr.setText(new SelectMessage(mercyopts, true));
            break;

        case UIState.ENEMYSELECT:
            string[] names         = new string[encounter.enabledEnemies.Length];
            string[] colorPrefixes = new string[names.Length];
            for (int i = 0; i < encounter.enabledEnemies.Length; i++)
            {
                names[i] = encounter.enabledEnemies[i].Name;
                if (encounter.enabledEnemies[i].CanSpare)
                {
                    colorPrefixes[i] = "[color:ffff00]";
                }
            }

            textmgr.setText(new SelectMessage(names, true, colorPrefixes));
            if (action == Actions.FIGHT)
            {
                int maxWidth = (int)initialHealthPos.x;
                for (int i = 0; i < encounter.enabledEnemies.Length; i++)
                {
                    int mNameWidth = UnitaleUtil.fontStringWidth(textmgr.Charset, "* " + encounter.enabledEnemies[i].Name) + 50;
                    if (mNameWidth > maxWidth)
                    {
                        maxWidth = mNameWidth;
                    }
                }
                for (int i = 0; i < encounter.enabledEnemies.Length; i++)
                {
                    LifeBarController lifebar = Instantiate(Resources.Load <LifeBarController>("Prefabs/HPBar"));
                    lifebar.transform.SetParent(textmgr.transform);
                    RectTransform lifebarRt = lifebar.GetComponent <RectTransform>();
                    lifebarRt.anchoredPosition = new Vector2(maxWidth, initialHealthPos.y - i * textmgr.Charset.LineSpacing);
                    lifebarRt.sizeDelta        = new Vector2(90, lifebarRt.sizeDelta.y);
                    lifebar.setFillColor(Color.green);
                    float hpFrac = (float)encounter.enabledEnemies[i].HP / (float)encounter.enabledEnemies[i].getMaxHP();
                    lifebar.setInstant(hpFrac);
                }
            }

            if (selectedEnemy >= encounter.enabledEnemies.Length)
            {
                selectedEnemy = 0;
            }
            setPlayerOnSelection(selectedEnemy * 2);     // single list so skip right row by multiplying x2
            break;

        case UIState.DEFENDING:
            ArenaSizer.instance.Resize((int)encounter.ArenaSize.x, (int)encounter.ArenaSize.y);
            PlayerController.instance.setControlOverride(false);
            encounter.nextWave();
            // ActionDialogResult(new TextMessage("This is where you'd\rdefend yourself.\nBut the code was spaghetti.", true, false), UIState.ACTIONSELECT);
            break;

        case UIState.DIALOGRESULT:
            PlayerController.instance.GetComponent <Image>().enabled = false;
            break;

        case UIState.ENEMYDIALOGUE:
            PlayerController.instance.GetComponent <Image>().enabled = true;
            ArenaSizer.instance.Resize(155, 130);
            encounter.CallOnSelfOrChildren("EnemyDialogueStarting");
            monDialogues = new TextManager[encounter.enabledEnemies.Length];
            for (int i = 0; i < encounter.enabledEnemies.Length; i++)
            {
                string[] msgs = encounter.enabledEnemies[i].GetDefenseDialog();
                if (msgs == null)
                {
                    UserDebugger.warn("Entered ENEMYDIALOGUE, but no current/random dialogue was set for " + encounter.enabledEnemies[i].Name);
                    SwitchState(UIState.DEFENDING);
                    break;
                }
                GameObject    speechBub = Instantiate(SpriteFontRegistry.BUBBLE_OBJECT);
                RectTransform enemyRt   = encounter.enabledEnemies[i].GetComponent <RectTransform>();
                TextManager   sbTextMan = speechBub.GetComponent <TextManager>();
                monDialogues[i] = sbTextMan;
                sbTextMan.setCaller(encounter.enabledEnemies[i].script);
                Image speechBubImg = speechBub.GetComponent <Image>();
                SpriteUtil.SwapSpriteFromFile(speechBubImg, encounter.enabledEnemies[i].DialogBubble);
                Sprite speechBubSpr = speechBubImg.sprite;
                // TODO improve position setting/remove hardcoding of position setting
                speechBub.transform.SetParent(encounter.enabledEnemies[i].transform);
                speechBub.GetComponent <RectTransform>().anchoredPosition = encounter.enabledEnemies[i].DialogBubblePosition;
                sbTextMan.setOffset(speechBubSpr.border.x, -speechBubSpr.border.w);
                sbTextMan.setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_MONSTERTEXT_NAME));
                sbTextMan.setEffect(new RotatingEffect(sbTextMan));

                MonsterMessage[] monMsgs = new MonsterMessage[msgs.Length];
                for (int j = 0; j < monMsgs.Length; j++)
                {
                    monMsgs[j] = new MonsterMessage(msgs[j]);
                }

                sbTextMan.setTextQueue(monMsgs);
                speechBub.GetComponent <Image>().enabled = true;
            }
            break;

        case UIState.DONE:
            StaticInits.Reset();
            Application.LoadLevel("ModSelect");
            break;
        }
    }
예제 #4
0
    // Update is called once per frame
    private void Update()
    {
        // do not update the attack UI if the ATTACKING state is frozen
        if (UIController.instance.frozenState != UIController.UIState.PAUSE)
        {
            return;
        }

        if (shakeInProgress)
        {
            int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);
            if (Damage > 0 && shakeIndex != shakeidx)
            {
                if (shakeIndex != shakeidx && shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                shakeIndex = shakeidx;
                Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake
                enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y);

                /*#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                 *  if (StaticInits.ENCOUNTER == "01 - Two monsters" && StaticInits.MODFOLDER == "Examples")
                 *      Misc.MoveWindow(shakeX[shakeIndex] * 2, 0);
                 #endif*/
            }
            if (shakeTimer < 1.5f)
            {
                damageTextRt.localPosition = new Vector2(damageTextRt.localPosition.x, enemy.offsets[2].y + 40 * (2 + Mathf.Sin(shakeTimer * Mathf.PI * 0.75f)));
            }
            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
            }
        }
        else if ((slice.animcomplete && !slice.img.GetComponent <KeyframeCollection>().enabled&& stopped && !showedup) || needAgain)
        {
            needAgain = true;
            if (!wait1frame)
            {
                wait1frame = true;
                slice.StopAnimation();
                slice.Set("empty");
                enemy.TryCall("BeforeDamageValues", new[] { DynValue.NewNumber(Damage) });
                if (Damage > 0)
                {
                    AudioSource aSrc = GetComponent <AudioSource>();
                    aSrc.clip = AudioClipRegistry.GetSound("hitsound");
                    aSrc.Play();
                }
                // set damage numbers and positioning
                string damageTextStr;
                if (Damage == 0)
                {
                    if (enemy.DefenseMissText == null)
                    {
                        damageTextStr = "[color:c0c0c0]MISS";
                    }
                    else
                    {
                        damageTextStr = "[color:c0c0c0]" + enemy.DefenseMissText;
                    }
                }
                else if (Damage > 0)
                {
                    damageTextStr = "[color:ff0000]" + Damage;
                }
                else
                {
                    damageTextStr = "[color:00ff00]" + Damage;
                }
                damageTextRt.localPosition = new Vector3(0, 0, 0);
                damageText.SetText(new TextMessage(damageTextStr, false, true));
                damageTextRt.localPosition = new Vector3(-UnitaleUtil.CalcTextWidth(damageText) / 2 + enemy.offsets[2].x, 40 + enemy.offsets[2].y);

                // initiate lifebar and set lerp to its new health value
                if (Damage != 0)
                {
                    int newHP = enemy.HP - Damage;
                    try {
                        lifeBar.GetComponent <RectTransform>().localPosition = new Vector2(enemy.offsets[2].x, 20 + enemy.offsets[2].y);
                        lifeBar.GetComponent <RectTransform>().sizeDelta     = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                        lifeBar.whenDamageValue = enemy.GetComponent <RectTransform>().rect.width;
                        lifeBar.setInstant(enemy.HP < 0 ? 0 : enemy.HP / (float)enemy.MaxHP);
                        lifeBar.setLerp(enemy.HP / (float)enemy.MaxHP, newHP / (float)enemy.MaxHP);
                        lifeBar.setVisible(true);
                        enemy.doDamage(Damage);
                    } catch { return; }
                }
                enemy.HandleAttack(Damage);
            }
            else
            {
                // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
                shakeInProgress = true;
                waitingToFade   = true;
                needAgain       = false;
                totalShakeTime  = shakeX.Length * (1.5f / 8.0f);
                showedup        = true;
            }
        }
        else if (!slice.animcomplete)
        {
            slice.img.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(slice.img.GetComponent <Image>().sprite.rect.width, slice.img.GetComponent <Image>().sprite.rect.height);
        }
    }
예제 #5
0
    // Update is called once per frame
    private void Update()
    {
        if (finishingFade)
        {
            float resizeProg = 1.0f - ArenaSizer.instance.getProgress();
            setAlpha(resizeProg);
            if (resizeProg == 0.0f)
            {
                damageText.destroyText();
                gameObject.SetActive(false);
            }
            return;
        }

        if (shakeInProgress)
        {
            int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);

            if (Damage > 0 && shakeIndex != shakeidx)
            {
                shakeIndex = shakeidx;
                if (shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake
                enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y);
            }

            damageTextRt.position = new Vector2(damageTextRt.position.x, 80 + enePos.y + 40 * Mathf.Sin(shakeTimer * Mathf.PI * 0.75f));

            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
                initFade();
            }
            return;
        }

        if (!shakeInProgress && slice.animcomplete)
        {
            slice.StopAnimation();
            if (Damage > 0)
            {
                AudioSource aSrc = GetComponent <AudioSource>();
                aSrc.clip = AudioClipRegistry.GetSound("hitsound");
                aSrc.Play();
            }
            // set damage numbers and positioning
            string damageTextStr = "";
            if (Damage <= 0)
            {
                damageTextStr = "[color:c0c0c0]MISS";
            }
            else
            {
                damageTextStr = "[color:ff0000]" + Damage;
            }
            // the -14 is to compensate for the 14 characters that [color:rrggbb] is worth until commands no longer count for text length. soon
            int damageTextWidth = (damageTextStr.Length - 14) * 29 + (damageTextStr.Length - 1 - 14) * 3; // lol hardcoded offsets
            foreach (char c in damageTextStr)
            {
                if (c == '1')
                {
                    damageTextWidth -= 12; // lol hardcoded offsets
                }
            }
            damageTextRt.position = new Vector2(enePos.x - 0.5f * damageTextWidth, 80 + enePos.y);
            damageText.setText(new TextMessage(damageTextStr, false, true));

            // initiate lifebar and set lerp to its new health value
            if (Damage > 0)
            {
                int newHP = enemy.HP - Damage;
                if (newHP < 0)
                {
                    newHP = 0;
                }
                lifeBar.GetComponent <RectTransform>().position  = new Vector2(enePos.x, enePos.y + 20);
                lifeBar.GetComponent <RectTransform>().sizeDelta = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                lifeBar.setInstant((float)enemy.HP / (float)enemy.getMaxHP());
                lifeBar.setLerp((float)enemy.HP / (float)enemy.getMaxHP(), (float)newHP / (float)enemy.getMaxHP());
                lifeBar.setVisible(true);
                enemy.doDamage(Damage);
            }

            // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
            shakeInProgress = true;
            enemy.HandleAttack(Damage);
        }

        if (stopped)
        {
            return;
        }
        float mv = xSpeed * Time.deltaTime;
        targetRt.anchoredPosition = new Vector2(targetRt.anchoredPosition.x + mv, 0);
        if (Finished()) // you didn't press Z or you wouldn't be here
        {
            enemy.HandleAttack(-1);
            StationaryMissScript smc = Resources.Load <StationaryMissScript>("Prefabs/StationaryMiss");
            smc = Instantiate(smc);
            smc.transform.SetParent(GameObject.Find("Canvas").transform);
            smc.setXPosition(320 - enePos.x);
            initFade();
        }
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (shakeInProgress)
        {
            int  shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);
            bool wentIn   = false;
            if (Damage > 0 && shakeIndex != shakeidx || wentIn)
            {
                if (shakeIndex != shakeidx && shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                shakeIndex = shakeidx;
                wentIn     = true;
                Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake
                enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y);

                /*#if UNITY_STANDALONE_WIN || UNITY_EDITOR
                 *  if (StaticInits.ENCOUNTER == "01 - Two monsters" && StaticInits.MODFOLDER == "Examples")
                 *      Misc.MoveWindow(shakeX[shakeIndex] * 2, 0);
                 #endif*/
            }
            if (shakeTimer < 1.5f)
            {
                damageTextRt.localPosition = new Vector2(damageTextRt.localPosition.x, enemy.offsets[2].y + 40 * (2 + Mathf.Sin(shakeTimer * Mathf.PI * 0.75f)));
            }
            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
            }
        }
        else if ((slice.animcomplete && !slice.img.GetComponent <KeyframeCollection>().enabled&& stopped && !showedup) || needAgain)
        {
            needAgain = true;
            if (!wait1frame)
            {
                wait1frame = true;
                slice.StopAnimation();
                slice.Set("empty");
                enemy.TryCall("BeforeDamageValues");
                if (Damage > 0)
                {
                    AudioSource aSrc = GetComponent <AudioSource>();
                    aSrc.clip = AudioClipRegistry.GetSound("hitsound");
                    aSrc.Play();
                }
                // set damage numbers and positioning
                string damageTextStr = "";
                if (Damage == 0)
                {
                    damageTextStr = "[color:c0c0c0]MISS";
                }
                else if (Damage > 0)
                {
                    damageTextStr = "[color:ff0000]" + Damage;
                }
                else
                {
                    damageTextStr = "[color:00ff00]" + Damage;
                }
                // the -14 is to compensate for the 14 characters that [color:rrggbb] is worth until commands no longer count for text length. soon
                int damageTextWidth = (damageTextStr.Length - 14) * 29 + (damageTextStr.Length - 1 - 14) * 3; // lol hardcoded offsets
                foreach (char c in damageTextStr)
                {
                    if (c == '1')
                    {
                        damageTextWidth -= 12; // lol hardcoded offsets
                    }
                }
                damageTextRt.localPosition = new Vector2(-0.5f * damageTextWidth + enemy.offsets[2].x, 40 + enemy.offsets[2].y);
                damageText.SetText(new TextMessage(damageTextStr, false, true));

                // initiate lifebar and set lerp to its new health value
                if (Damage != 0)
                {
                    int newHP = enemy.HP - Damage;
                    try {
                        lifeBar.GetComponent <RectTransform>().localPosition = new Vector2(enemy.offsets[2].x, 20 + enemy.offsets[2].y);
                        lifeBar.GetComponent <RectTransform>().sizeDelta     = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                        lifeBar.whenDamageValue = enemy.GetComponent <RectTransform>().rect.width;
                        lifeBar.setInstant(enemy.HP < 0 ? 0 : (float)enemy.HP / (float)enemy.MaxHP);
                        lifeBar.setLerp((float)enemy.HP / (float)enemy.MaxHP, (float)newHP / (float)enemy.MaxHP);
                        lifeBar.setVisible(true);
                        enemy.doDamage(Damage);
                    } catch { return; }
                }
                enemy.HandleAttack(Damage);
            }
            else
            {
                // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
                shakeInProgress = true;
                waitingToFade   = true;
                needAgain       = false;
                totalShakeTime  = shakeX.Length * (1.5f / 8.0f);
                showedup        = true;
            }
        }
        else if (!slice.animcomplete)
        {
            slice.img.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(slice.img.GetComponent <Image>().sprite.rect.width, slice.img.GetComponent <Image>().sprite.rect.height);
        }
    }