public override string BookAuthor()
            {   // %ba
                BookFile bookFile = new BookFile();
                string   name     = BookFile.messageToBookFilename(parent.message);

                if (!BookReplacement.TryImportBook(name, bookFile))
                {
                    bookFile.OpenBook(DaggerfallUnity.Instance.Arena2Path, name);
                }
                return(bookFile.Author);
            }
        public virtual bool OpenBook(string name)
        {
            if (!BookReplacement.TryImportBook(name, bookFile) &&
                !bookFile.OpenBook(DaggerfallUnity.Instance.Arena2Path, name))
            {
                return(false);
            }

            isBookOpen  = true;
            currentPage = 0;

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new book from resource provided by classic game data or mods.
        /// </summary>
        /// <param name="id">The numeric id of book resource.</param>
        /// <returns>An instance of the book item or null.</returns>
        public static DaggerfallUnityItem CreateBook(int id)
        {
            var    bookFile = new BookFile();
            string name     = DaggerfallUnity.Instance.ItemHelper.GetBookFileNameByMessage(id);

            if (!BookReplacement.TryImportBook(name, bookFile) &&
                !bookFile.OpenBook(DaggerfallUnity.Instance.Arena2Path, name))
            {
                return(null);
            }

            return(new DaggerfallUnityItem(ItemGroups.Books, 0)
            {
                message = id,
                value = bookFile.Price
            });
        }
        /// <summary>
        /// Creates a new random book
        /// </summary>
        /// <returns>DaggerfallUnityItem.</returns>
        public static DaggerfallUnityItem CreateRandomBook()
        {
            Array enumArray          = DaggerfallUnity.Instance.ItemHelper.GetEnumArray(ItemGroups.Books);
            DaggerfallUnityItem book = new DaggerfallUnityItem(ItemGroups.Books, Array.IndexOf(enumArray, Books.Book0));

            book.message        = DaggerfallUnity.Instance.ItemHelper.GetRandomBookID();
            book.CurrentVariant = UnityEngine.Random.Range(0, book.TotalVariants);
            // Update item value for this book.
            BookFile bookFile = new BookFile();
            string   name     = GameManager.Instance.ItemHelper.GetBookFileName(book.message);

            if (!BookReplacement.TryImportBook(name, bookFile))
            {
                bookFile.OpenBook(DaggerfallUnity.Instance.Arena2Path, name);
            }
            book.value = bookFile.Price;
            return(book);
        }
            public override string BookAuthor()
            {   // %ba
                BookFile bookFile = new BookFile();

                string name = GameManager.Instance.ItemHelper.GetBookFileName(parent.message);

                if (name != null)
                {
                    if (!BookReplacement.TryImportBook(name, bookFile))
                    {
                        bookFile.OpenBook(DaggerfallUnity.Instance.Arena2Path, name);
                    }

                    if (bookFile.Author != null)
                    {
                        return(bookFile.Author);
                    }
                }

                return(TextManager.Instance.GetText("DaggerfallUI", "unknownAuthor"));
            }
Beispiel #6
0
        public bool ReformatBook(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(false);
            }

            // Try to open book
            BookFile book = new BookFile();

            if (!BookReplacement.TryImportBook(filename, book) &&
                !book.OpenBook(DaggerfallUnity.Instance.Arena2Path, filename))
            {
                return(false);
            }

            // Clear existing
            Clear();

            // Combine all tokens from all pages
            // The classic concept of pages becomes
            List <TextFile.Token> allPageTokens = new List <TextFile.Token>();

            for (int page = 0; page < book.PageCount; page++)
            {
                TextFile.Token[] tokens = book.GetPageTokens(page);
                foreach (TextFile.Token token in tokens)
                {
                    allPageTokens.Add(token);
                }
            }

            // Read all tokens and merge into text groups
            DaggerfallFont prevFont = DaggerfallUI.DefaultFont;

            TextFile.Token prevToken    = new TextFile.Token(TextFile.Formatting.Nothing);
            TextGroup      workingGroup = CreateEmptyTextGroup(prevFont);

            foreach (TextFile.Token token in allPageTokens)
            {
                switch (token.formatting)
                {
                // Set font on current group
                case TextFile.Formatting.FontPrefix:
                    workingGroup.font = prevFont = DaggerfallUI.Instance.GetFont(token.x);
                    break;

                // Text is added to working group
                case TextFile.Formatting.Text:
                    workingGroup.text += token.text;
                    break;

                // Newline becomes a space unless previous token was also newline
                // This will be treated as a paragraph break
                case TextFile.Formatting.NewLine:
                    if (prevToken.formatting == TextFile.Formatting.NewLine)
                    {
                        StoreGroup(workingGroup);
                        StoreLineBreakGroup();
                        workingGroup = CreateEmptyTextGroup(prevFont);
                    }
                    else
                    {
                        workingGroup.text += space;
                    }
                    break;

                // Set left justify on current group
                case TextFile.Formatting.JustifyLeft:
                    workingGroup.alignment = HorizontalAlignment.None;
                    break;

                // Set centre justify on current group
                case TextFile.Formatting.JustifyCenter:
                    workingGroup.alignment = HorizontalAlignment.Center;
                    break;
                }

                prevToken = token;
            }

            return(true);
        }