public void SetText(params string[] rows)
        {
            // Tokenize rows
            List<TextFile.Token> tokenList = new List<TextFile.Token>();
            TextFile.Token textToken = new TextFile.Token();
            TextFile.Token newLineToken = new TextFile.Token();
            for (int i = 0; i < rows.Length; i++)
            {
                textToken.formatting = TextFile.Formatting.Text;
                textToken.text = rows[i];
                tokenList.Add(textToken);
                if (i < rows.Length - 1)
                {
                    newLineToken.formatting = TextFile.Formatting.NewLine;
                    tokenList.Add(newLineToken);
                }
            }

            // Set tokens
            SetTextTokens(tokenList.ToArray());
        }
Example #2
0
        public List <string> GenerateBackstory(int classIndex)
        {
            const int tokensStart = 4116;

            #region Parse answer tokens
            List <int>[] tokenLists = new List <int> [questionCount * 2];
            tokenLists[0]  = Q1Tokens;
            tokenLists[1]  = Q2Tokens;
            tokenLists[2]  = Q3Tokens;
            tokenLists[3]  = Q4Tokens;
            tokenLists[4]  = Q5Tokens;
            tokenLists[5]  = Q6Tokens;
            tokenLists[6]  = Q7Tokens;
            tokenLists[7]  = Q8Tokens;
            tokenLists[8]  = Q9Tokens;
            tokenLists[9]  = Q10Tokens;
            tokenLists[10] = Q11Tokens;
            tokenLists[11] = Q12Tokens;

            // Setup tokens for macro handler
            foreach (string effect in answerEffects)
            {
                char prefix = effect[0];

                if (prefix == '#' || prefix == '!' || prefix == '?')
                {
                    int      questionInd;
                    string[] effectSplit = effect.Split(' ');
                    string   command     = effectSplit[0];
                    string   index       = effectSplit[1];
                    if (!int.TryParse(index, out questionInd))
                    {
                        Debug.LogError("GenerateBackstory: Invalid question index.");
                        continue;
                    }

                    string[] splitStr = command.Split(prefix);
                    if (splitStr.Length > 1)
                    {
                        tokenLists[questionInd].Add(int.Parse(splitStr[1]));
                    }
                }
            }
            #endregion

            TextFile.Token lastToken = new TextFile.Token();
            GameManager.Instance.PlayerEntity.BirthRaceTemplate = characterDocument.raceTemplate; // Need correct race set when parsing %ra macro
            List <string>    backStory = new List <string>();
            TextFile.Token[] tokens    = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(tokensStart + classIndex);
            MacroHelper.ExpandMacros(ref tokens, (IMacroContextProvider)this);
            foreach (TextFile.Token token in tokens)
            {
                if (token.formatting == TextFile.Formatting.Text)
                {
                    backStory.Add(token.text);
                }
                else if (token.formatting == TextFile.Formatting.JustifyLeft)
                {
                    if (lastToken.formatting == TextFile.Formatting.JustifyLeft)
                    {
                        backStory.Add("\n");
                    }
                }
                lastToken = token;
            }

            return(backStory);
        }
        // Creates formatting tokens for skill popups
        TextFile.Token[] CreateSkillTokens(DFCareer.Skills skill)
        {
            List<TextFile.Token> tokens = new List<TextFile.Token>();

            TextFile.Token skillNameToken = new TextFile.Token();
            skillNameToken.text = DaggerfallUnity.Instance.TextProvider.GetSkillName(skill);
            skillNameToken.formatting = TextFile.Formatting.Text;

            TextFile.Token skillValueToken = new TextFile.Token();
            skillValueToken.text = string.Format("{0}%", playerEntity.Skills.GetSkillValue(skill));
            skillValueToken.formatting = TextFile.Formatting.Text;

            DFCareer.Stats primaryStat = DaggerfallSkills.GetPrimaryStat(skill);
            TextFile.Token skillPrimaryStatToken = new TextFile.Token();
            skillPrimaryStatToken.text = DaggerfallUnity.Instance.TextProvider.GetAbbreviatedStatName(primaryStat);
            skillPrimaryStatToken.formatting = TextFile.Formatting.Text;

            TextFile.Token spacesToken = new TextFile.Token();
            spacesToken.formatting = TextFile.Formatting.Text;
            spacesToken.text = "  ";

            TextFile.Token tabToken = new TextFile.Token();
            tabToken.formatting = TextFile.Formatting.PositionPrefix;

            // Add tokens in order
            tokens.Add(skillNameToken);
            tokens.Add(tabToken);
            tokens.Add(tabToken);
            tokens.Add(skillValueToken);
            tokens.Add(spacesToken);
            tokens.Add(skillPrimaryStatToken);

            return tokens.ToArray();
        }
        void LayoutTextElements(TextFile.Token[] tokens)
        {
            labels.Clear();
            totalWidth = 0;
            totalHeight = 0;
            cursorX = 0;
            cursorY = 0;

            TextFile.Token token = new TextFile.Token();
            TextFile.Token nextToken = new TextFile.Token();
            for (int i = 0; i < tokens.Length; i++)
            {
                token = tokens[i];
                nextToken.formatting = TextFile.Formatting.Nothing;
                if (i < tokens.Length - 1)
                    nextToken = tokens[i + 1];

                // Still working out rules for justify logic
                // This will adapt over time as required
                switch (token.formatting)
                {
                    case TextFile.Formatting.NewLine:
                        NewLine();
                        break;
                    case TextFile.Formatting.JustifyLeft:
                        NewLine();
                        break;
                    case TextFile.Formatting.JustifyCenter:
                        if (lastLabel != null)
                            lastLabel.HorizontalAlignment = HorizontalAlignment.Center;
                        NewLine();
                        break;
                    case TextFile.Formatting.PositionPrefix:
                        if (token.x != 0)
                        {
                            // Tab by specific number of pixels
                            cursorX += token.x;
                        }
                        else
                        {
                            // Tab to next tab stop
                            tabStop++;
                            cursorX = tabStop * tabWidth;
                        }
                        break;
                    case TextFile.Formatting.Text:
                        TextLabel label = AddTextLabel(font, new Vector2(cursorX, cursorY), token.text);
                        label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor;
                        label.ShadowColor = DaggerfallUI.DaggerfallDefaultShadowColor;
                        label.ShadowPosition = DaggerfallUI.DaggerfallDefaultShadowPos;
                        labels.Add(label);
                        lastLabel = label;
                        cursorX += label.TextWidth;
                        break;
                    default:
                        Debug.Log("MultilineTextLabel: Unknown formatting token: " + (int)token.formatting);
                        break;
                }

                if (lastLabel != null)
                {
                    int rowWidth = (int)lastLabel.Position.x + lastLabel.TextWidth;
                    if (rowWidth > totalWidth)
                        totalWidth = rowWidth;
                }
            }

            Size = new Vector2(totalWidth, totalHeight);
        }
        void CreateConfirmationPopUp()
        {
            if (!locationSelected)
                return;

            TextFile.Token[] textTokens = new TextFile.Token[2];
            //int index = currentRegion.MapIdLookup[locationSummary.MapIndex];
            textTokens[0].text = string.Format("Travel to  {0} : {1} ?", currentDFRegion.Name, currentDFRegion.MapNames[locationSummary.MapIndex]);
            textTokens[0].formatting = TextFile.Formatting.Text;
            textTokens[1].text = null;
            textTokens[1].formatting = TextFile.Formatting.NewLine;

            DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
            messageBox.SetTextTokens(textTokens);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
            messageBox.OnButtonClick += ConfirmTravelPopupButtonClick;
            uiManager.PushWindow(messageBox);
        }