示例#1
0
    void Start()
    {
        TextManager mgr = GetComponent <TextManager>();

        mgr.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DAMAGETEXT_NAME));
        mgr.SetText(new TextMessage("[color:c0c0c0]MISS", false, true));
    }
示例#2
0
    public void initAll()
    {
        if (!Initialized)
        {
            Stopwatch sw = new Stopwatch(); //benchmarking terrible loading times
            sw.Start();
            ScriptRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Script registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            AudioClipRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Audio clip registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteFontRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite font registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();
        }
        LateUpdater.init(); // must be last; lateupdater's initialization is for classes that depend on the above registries
        MusicManager.src = Camera.main.GetComponent <AudioSource>();
    }
示例#3
0
    private void inUpdateControlCommand(string command)
    {
        string[] cmds = command.Split(':');
        string[] args = new string[0];
        if (cmds.Length == 2)
        {
            args    = cmds[1].Split(',');
            cmds[1] = args[0];
        }
        switch (cmds[0].ToLower())
        {
        case "w":
            letterTimer = timePerLetter - (singleFrameTiming * ParseUtil.getInt(cmds[1]));
            break;

        case "waitall":
            timePerLetter = singleFrameTiming * ParseUtil.getInt(cmds[1]);
            break;

        case "voice":
            if (cmds[1].ToLower() == "default")
            {
                letterSound.clip = SpriteFontRegistry.Get(SpriteFontRegistry.UI_DEFAULT_NAME).Sound;
            }
            else
            {
                letterSound.clip = AudioClipRegistry.GetVoice(cmds[1].ToLower());
            }
            break;

        case "font":
            letterSound.clip = SpriteFontRegistry.Get(cmds[1].ToLower()).Sound;
            break;

        case "novoice":
            letterSound.clip = null;
            break;

        case "next":
            autoSkip = true;
            break;

        case "func":
            if (caller == null)
            {
                UnitaleUtil.displayLuaError("???", "Func called but no script to reference. This is the engine's fault, not yours.");
            }
            if (args.Length > 1)
            {
                caller.Call(args[0], DynValue.NewString(args[1]));
            }
            else
            {
                caller.Call(cmds[1]);
            }
            break;
        }
    }
示例#4
0
 public void resetFont()
 {
     if (Charset == null || default_charset == null)
     {
         setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DEFAULT_NAME));
     }
     Charset          = default_charset;
     letterSound.clip = default_charset.Sound;
 }
    // Use this for initialization
    private void Start()
    {
        SpriteFontRegistry.Init();
        TextManager tm = FindObjectOfType <TextManager>();

        tm.SetFont(SpriteFontRegistry.Get("wingdings"));
        //tm.setText(new TextMessage("the quick brown fox jumps over\rthe lazy dog.\nTHE QUICK BROWN FOX JUMPS OVER\rTHE LAZY DOG.\nJerry.", true, false));
        //tm.setText(new RegularMessage("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG?\nTEST! TEST? TEST:TEST, TEST/TEST. TEST\\TEST\n0123456789"));
        tm.SetText(new RegularMessage("THE QUICK BROWN\rFOX JUMPS OVER\rTHE LAZY DOG\nthe quick brown\rfox jumps over\rthe lazy dog\n0123456789"));
    }
示例#6
0
 public void setPlayerInfo(string name, int lv)
 {
     nameCurrent = name;
     lvCurrent   = lv;
     if (initialized)
     {
         nameLevelTextMan.enabled = true;
         nameLevelTextMan.setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_SMALLTEXT_NAME));
         nameLevelTextMan.setText(new TextMessage(name.ToUpper() + "  LV " + lv, false, true));
         nameLevelTextMan.enabled = false;
     }
 }
示例#7
0
    public void setPlayerInfo(string newName, int newLv)
    {
        if (!initialized)
        {
            return;
        }
        nameLevelTextMan.enabled = true;
        nameLevelTextMan.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_SMALLTEXT_NAME));
        nameLevelTextMan.SetText(new TextMessage(newName.ToUpper() + "  LV " + newLv, false, true));
        hpRect.transform.position = new Vector3(hpRect.transform.parent.position.x + (PlayerCharacter.instance.Name.Length > 6 ? 286.1f : 215.1f), hpRect.transform.position.y, hpRect.transform.position.z);

        nameLevelTextMan.enabled = false;
    }
示例#8
0
    public void SetFont(string fontName, bool firstTime = false)
    {
        UnderFont uf = SpriteFontRegistry.Get(fontName);

        if (uf == null)
        {
            throw new CYFException("The font \"" + fontName + "\" doesn't exist.\nYou should check if you haven't made a typo or if the font really is in your mod.");
        }
        SetFont(uf, firstTime);
        //if (forced)
        //    default_charset = uf;
        containerBubble.GetComponent <RectTransform>().localPosition = new Vector2(-12, 24);
        GetComponent <RectTransform>().localPosition = new Vector2(0, 16);
    }
示例#9
0
    public static void InitAll(bool shaders = false)
    {
        if (!Initialized && (!GlobalControls.isInFight || GlobalControls.modDev))
        {
            //UnitaleUtil.createFile();
            Stopwatch sw = new Stopwatch(); //benchmarking terrible loading times
            sw.Start();
            ScriptRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Script registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            AudioClipRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Audio clip registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteFontRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite font registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            if (shaders)
            {
                sw.Start();
                ShaderRegistry.Init();
                sw.Stop();
                UnityEngine.Debug.Log("Shader registry loading time: " + sw.ElapsedMilliseconds + "ms");
                sw.Reset();
            }
        }
        else
        {
            Initialized = true;
        }
        LateUpdater.Init(); // must be last; lateupdater's initialization is for classes that depend on the above registries
        MusicManager.src = Camera.main.GetComponent <AudioSource>();
        SendLoaded();
        //CurrENCOUNTER = ENCOUNTER;
        //CurrMODFOLDER = MODFOLDER;
    }
示例#10
0
 // Use this for initialization
 void Start()
 {
     if (!SaveLoad.started)
     {
         StaticInits.Start();
         SaveLoad.Start();
         new ControlPanel();
         new PlayerCharacter();
         #if UNITY_STANDALONE_WIN || UNITY_EDITOR
         if (GlobalControls.crate)
         {
             Misc.WindowName = ControlPanel.instance.WinodwBsaisNmae;
         }
         else
         {
             Misc.WindowName = ControlPanel.instance.WindowBasisName;
         }
         #endif
         SaveLoad.LoadAlMighty();
         LuaScriptBinder.Set(null, "ModFolder", MoonSharp.Interpreter.DynValue.NewString("Title"));
         UnitaleUtil.AddKeysToMapCorrespondanceList();
     }
     GameObject firstCamera = GameObject.Find("Main Camera");
     firstCamera.SetActive(false);
     if (GameObject.Find("Main Camera"))
     {
         GameObject.Destroy(firstCamera);
     }
     else
     {
         firstCamera.SetActive(true);
     }
     tmName = GameObject.Find("TextManagerResetName").GetComponent <TextManager>();
     tmName.SetHorizontalSpacing(2);
     tmName.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DEFAULT_NAME));
     diff    = calcTotalLength(tmName);
     actualX = tmName.transform.localPosition.x;
     actualY = tmName.transform.localPosition.y;
     if (GlobalControls.crate)
     {
         GameObject.Find("Title").GetComponent <SpriteRenderer>().enabled     = false;
         GameObject.Find("Title (1)").GetComponent <SpriteRenderer>().enabled = true;
     }
     GameObject.DontDestroyOnLoad(Camera.main.gameObject);
     StartCoroutine(TitlePhase1());
 }
示例#11
0
 public static void Start()
 {
     if (!firstInit)
     {
         firstInit = true;
         SpriteRegistry.Start();
         AudioClipRegistry.Start();
         SpriteFontRegistry.Start();
     }
     if (MODFOLDER == null || MODFOLDER == "")
     {
         MODFOLDER = EDITOR_MODFOLDER;
     }
     //if (CurrMODFOLDER != MODFOLDER || CurrENCOUNTER != ENCOUNTER)
     InitAll();
     Initialized = true;
 }
示例#12
0
 public static void Start()
 {
     if (!firstInit)
     {
         firstInit = true;
         SpriteRegistry.Start();
         AudioClipRegistry.Start();
         SpriteFontRegistry.Start();
         ShaderRegistry.Start();
     }
     if (string.IsNullOrEmpty(MODFOLDER))
     {
         MODFOLDER = EDITOR_MODFOLDER;
     }
     //if (CurrMODFOLDER != MODFOLDER || CurrENCOUNTER != ENCOUNTER)
     InitAll();
     Initialized = true;
 }
示例#13
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);
    }
示例#14
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);
    }
示例#15
0
    public void SetFont(string fontName, bool firstTime = false)
    {
        if (fontName == null)
        {
            throw new CYFException("Text.SetFont: The first argument (the font name) is nil.\n\nSee the documentation for proper usage.");
        }
        CheckExists();
        UnderFont uf = SpriteFontRegistry.Get(fontName);

        if (uf == null)
        {
            throw new CYFException("The font \"" + fontName + "\" doesn't exist.\nYou should check if you made a typo, or if the font really is in your mod.");
        }
        SetFont(uf, firstTime);
        //if (forced)
        //    default_charset = uf;
        containerBubble.GetComponent <RectTransform>().localPosition = new Vector2(-12, 24);
        // GetComponent<RectTransform>().localPosition = new Vector2(0, 16);
        GetComponent <RectTransform>().localPosition = new Vector2(0, 0);
    }
示例#16
0
    public void SetFont(string fontName, bool firstTime = false)
    {
        if (fontName == null)
        {
            throw new CYFException("Text.SetFont: The first argument (the font name) is nil.\n\nSee the documentation for proper usage.");
        }
        CheckExists();
        UnderFont uf = SpriteFontRegistry.Get(fontName);

        if (uf == null)
        {
            throw new CYFException("The font \"" + fontName + "\" doesn't exist.\nYou should check if you made a typo, or if the font really is in your mod.");
        }
        SetFont(uf, firstTime);
        if (!firstTime)
        {
            default_charset = uf;
        }
        UpdateBubble();
    }
示例#17
0
    public void setPlayerInfo(string name, int lv)
    {
        if (initialized)
        {
            nameLevelTextMan.enabled = true;
            nameLevelTextMan.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_SMALLTEXT_NAME));
            nameLevelTextMan.SetText(new TextMessage(name.ToUpper() + "  LV " + lv, false, true));
            if (PlayerCharacter.instance.Name.Length > 6)
            {
                GameObject.Find("HPRect").transform.position = new Vector3(GameObject.Find("HPRect").transform.parent.position.x + 286.1f,
                                                                           GameObject.Find("HPRect").transform.position.y, GameObject.Find("HPRect").transform.position.z);
            }
            else
            {
                GameObject.Find("HPRect").transform.position = new Vector3(GameObject.Find("HPRect").transform.parent.position.x + 215.1f,
                                                                           GameObject.Find("HPRect").transform.position.y, GameObject.Find("HPRect").transform.position.z);
            }

            nameLevelTextMan.enabled = false;
        }
    }
示例#18
0
    public void Start()
    {
        foreach (RectTransform child in transform)
        {
            switch (child.name)
            {
            case "SliceAnim": slice = new LuaSpriteController(child.GetComponent <Image>()); break;

            case "HPBar":    lifeBar = child.GetComponent <LifeBarController>(); break;

            case "DamageNumber":
                damageText   = child.GetComponent <TextManager>();
                damageTextRt = child.GetComponent <RectTransform>();
                break;
            }
        }
        sliceAnim          = UIController.instance.fightUI.sliceAnim;
        sliceAnimFrequency = UIController.instance.fightUI.sliceAnimFrequency;
        shakeX             = UIController.instance.fightUI.shakeX;
        damageText.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DAMAGETEXT_NAME));
        damageText.SetMute(true);
    }
示例#19
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;
        }
    }
示例#20
0
    public static LuaTextManager CreateText(Script scr, DynValue text, DynValue position, int textWidth, string layer = "BelowPlayer", int bubbleHeight = -1)
    {
        // Check if the arguments are what they should be
        if (text == null || (text.Type != DataType.Table && text.Type != DataType.String))
        {
            throw new CYFException("CreateText: The text argument must be a non-empty table of strings or a simple string.");
        }
        if (position == null || position.Type != DataType.Table || position.Table.Get(1).Type != DataType.Number || position.Table.Get(2).Type != DataType.Number)
        {
            throw new CYFException("CreateText: The position argument must be a non-empty table of two numbers.");
        }

        GameObject     go    = UnityEngine.Object.Instantiate(Resources.Load <GameObject>("Prefabs/CstmTxtContainer"));
        LuaTextManager luatm = go.GetComponentInChildren <LuaTextManager>();

        go.GetComponent <RectTransform>().position = new Vector2((float)position.Table.Get(1).Number, (float)position.Table.Get(2).Number);

        UnitaleUtil.GetChildPerName(go.transform, "BubbleContainer").GetComponent <RectTransform>().pivot         = new Vector2(0, 1);
        UnitaleUtil.GetChildPerName(go.transform, "BubbleContainer").GetComponent <RectTransform>().localPosition = new Vector2(-12, 8);
        UnitaleUtil.GetChildPerName(go.transform, "BubbleContainer").GetComponent <RectTransform>().sizeDelta     = new Vector2(textWidth + 20, 100);          //Used to set the borders
        UnitaleUtil.GetChildPerName(go.transform, "BackHorz").GetComponent <RectTransform>().sizeDelta            = new Vector2(textWidth + 20, 100 - 20 * 2); //BackHorz
        UnitaleUtil.GetChildPerName(go.transform, "BackVert").GetComponent <RectTransform>().sizeDelta            = new Vector2(textWidth - 20, 100);          //BackVert
        UnitaleUtil.GetChildPerName(go.transform, "CenterHorz").GetComponent <RectTransform>().sizeDelta          = new Vector2(textWidth + 16, 96 - 16 * 2);  //CenterHorz
        UnitaleUtil.GetChildPerName(go.transform, "CenterVert").GetComponent <RectTransform>().sizeDelta          = new Vector2(textWidth - 16, 96);           //CenterVert
        foreach (ScriptWrapper scrWrap in ScriptWrapper.instances)
        {
            if (scrWrap.script == scr)
            {
                luatm.SetCaller(scrWrap);
                break;
            }
        }
        // Layers don't exist in the overworld, so we don't set it
        if (!UnitaleUtil.IsOverworld || GlobalControls.isInShop)
        {
            luatm.layer = layer;
        }
        else
        {
            luatm.layer = (layer == "BelowPlayer" ? "Default" : layer);
        }
        luatm.textMaxWidth = textWidth;
        luatm.bubbleHeight = bubbleHeight;
        luatm.ShowBubble();

        // Converts the text argument into a table if it's a simple string
        text = text.Type == DataType.String ? DynValue.NewTable(scr, new DynValue[1] {
            text
        }) : text;

        if (text.Table.Length == 0)
        {
            text = null;
        }

        //////////////////////////////////////////
        ///////////  LATE START SETTER  //////////
        //////////////////////////////////////////

        // Text objects' Late Start will be disabled if the first line of text contains [instant] before any regular characters
        bool enableLateStart = true;

        // if we've made it this far, then the text is valid.

        // so, let's scan the first line of text for [instant]
        string firstLine = text.Table.Get(1).String;

        // if [instant] or [instant:allowcommand] is found, check for the earliest match, and whether it is at the beginning
        if (firstLine.IndexOf("[instant]") > -1 || firstLine.IndexOf("[instant:allowcommand]") > -1)
        {
            // determine whether [instant] or [instant:allowcommand] is first
            string testFor = "[instant]";
            if (firstLine.IndexOf("[instant:allowcommand]") > -1 &&
                ((firstLine.IndexOf("[instant]") > -1 && firstLine.IndexOf("[instant:allowcommand]") < firstLine.IndexOf("[instant]")) ||
                 firstLine.IndexOf("[instant]") == -1))
            {
                testFor = "[instant:allowcommand]";
            }

            // grab all of the text that comes before the matched command
            string precedingText = firstLine.Substring(0, firstLine.IndexOf(testFor));

            // remove all commands other than the matched command from this variable
            while (precedingText.IndexOf('[') > -1)
            {
                int i = 0;
                if (UnitaleUtil.ParseCommandInline(precedingText, ref i) == null)
                {
                    break;
                }
                else
                {
                    precedingText = precedingText.Replace(precedingText.Substring(0, i + 1), "");
                }
            }

            // if the length of the remaining string is 0, then disable late start!
            if (precedingText.Length == 0)
            {
                enableLateStart = false;
            }
        }

        //////////////////////////////////////////
        /////////// INITIAL FONT SETTER //////////
        //////////////////////////////////////////

        // If the first line of text has [font] at the beginning, use it initially!
        if (firstLine.IndexOf("[font:") > -1 && firstLine.Substring(firstLine.IndexOf("[font:")).IndexOf(']') > -1)
        {
            // grab all of the text that comes before the matched command
            string precedingText = firstLine.Substring(0, firstLine.IndexOf("[font:"));

            // remove all commands other than the matched command from this variable
            while (precedingText.IndexOf('[') > -1)
            {
                int i = 0;
                if (UnitaleUtil.ParseCommandInline(precedingText, ref i) == null)
                {
                    break;
                }
                else
                {
                    precedingText = precedingText.Replace(precedingText.Substring(0, i + 1), "");
                }
            }

            // if the length of the remaining string is 0, then set the font!
            if (precedingText.Length == 0)
            {
                int    startCommand = firstLine.IndexOf("[font:");
                string command      = UnitaleUtil.ParseCommandInline(precedingText, ref startCommand);
                if (command != null)
                {
                    string    fontPartOne = command.Substring(6);
                    string    fontPartTwo = fontPartOne.Substring(0, fontPartOne.IndexOf("]"));
                    UnderFont font        = SpriteFontRegistry.Get(fontPartTwo);
                    if (font == null)
                    {
                        throw new CYFException("The font \"" + fontPartTwo + "\" doesn't exist.\nYou should check if you made a typo, or if the font really is in your mod.");
                    }
                    luatm.SetFont(font, true);
                    luatm.UpdateBubble();
                }
                else
                {
                    luatm.ResetFont();
                }
            }
            else
            {
                luatm.ResetFont();
            }
        }
        else
        {
            luatm.ResetFont();
        }

        if (enableLateStart)
        {
            luatm.lateStartWaiting = true;
        }
        luatm.SetText(text);
        if (enableLateStart)
        {
            luatm.DestroyChars();
            luatm.LateStart();
        }
        return(luatm);
    }
示例#21
0
    private void preCreateControlCommand(string command)
    {
        string[] cmds = command.Split(':');
        string[] args = new string[0];
        if (cmds.Length == 2)
        {
            args    = cmds[1].Split(',');
            cmds[1] = args[0];
        }
        switch (cmds[0].ToLower())
        {
        case "noskip":
            currentSkippable = false;
            break;

        case "instant":
            this.displayImmediate = true;
            break;

        case "color":
            currentColor = ParseUtil.getColor(cmds[1]);
            break;

        case "starcolor":
            Color starColor = ParseUtil.getColor(cmds[1]);
            if (textQueue[currentLine].Text[0] == '*')
            {
                letterReferences[0].color = starColor;
            }
            if (textQueue[currentLine] is SelectMessage)
            {
                int indexOfStar = textQueue[currentLine].Text.IndexOf('*');     // HACK oh my god lol
                if (indexOfStar > -1)
                {
                    letterReferences[indexOfStar].color = starColor;
                }
            }
            break;

        case "font":
            AudioClip oldClip = letterSound.clip;
            setFont(SpriteFontRegistry.Get(cmds[1]));
            letterSound.clip = oldClip;
            break;

        case "effect":
            switch (cmds[1].ToUpper())
            {
            case "NONE":
                textEffect = null;
                break;

            case "TWITCH":
                if (args.Length > 1)
                {
                    textEffect = new TwitchEffect(this, ParseUtil.getFloat(args[1]));
                }
                else
                {
                    textEffect = new TwitchEffect(this);
                }
                break;

            case "SHAKE":
                if (args.Length > 1)
                {
                    textEffect = new ShakeEffect(this, ParseUtil.getFloat(args[1]));
                }
                else
                {
                    textEffect = new ShakeEffect(this);
                }
                break;

            case "ROTATE":
                if (args.Length > 1)
                {
                    textEffect = new RotatingEffect(this, ParseUtil.getFloat(args[1]));
                }
                else
                {
                    textEffect = new RotatingEffect(this);
                }
                break;
            }
            break;
        }
    }
示例#22
0
 private void Start()
 {
     damageText.setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DAMAGETEXT_NAME));
     damageText.setMute(true);
     line.Set("UI/Battle/spr_targetchoice_0");
 }