Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for image markup in localized books
Using a TextLabel override called ImageLabel to draw an image in place of a label inside book reader. This allows image to be treated like a label in terms of size and layout. Does not seek mods yet. Images must be in StreamingAssets/Text/Books/BookImages. Image not currently scissored to book reader interior. Will add this soon.
- Loading branch information
1 parent
60ed3b1
commit 38e4f68
Showing
8 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Project: Daggerfall Unity | ||
// Copyright: Copyright (C) 2009-2022 Daggerfall Workshop | ||
// Web Site: http://www.dfworkshop.net | ||
// License: MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
// Source Code: https://github.com/Interkarma/daggerfall-unity | ||
// Original Author: Gavin Clayton (interkarma@dfworkshop.net) | ||
// Contributors: | ||
// | ||
// Notes: | ||
// | ||
|
||
using UnityEngine; | ||
|
||
namespace DaggerfallWorkshop.Game.UserInterface | ||
{ | ||
/// <summary> | ||
/// Renders an image in place of a text label in book reader UI. | ||
/// </summary> | ||
public class ImageLabel : TextLabel | ||
{ | ||
Texture2D image; | ||
float imageWidth; | ||
float imageHeight; | ||
float scaleFactor; | ||
|
||
public Texture2D Image | ||
{ | ||
get { return image; } | ||
set { image = value; RefreshLayout(); } | ||
} | ||
|
||
public override void Draw() | ||
{ | ||
if (image == null || image.width == 0 || image.height == 0) | ||
return; | ||
|
||
// Image position is always centred to page | ||
RefreshLayout(); | ||
Rect totalRect = Rectangle; | ||
Rect rect = new Rect(totalRect.x + imageWidth / 2, totalRect.y, imageWidth, imageHeight); | ||
Size = new Vector2(imageWidth, imageHeight); | ||
DaggerfallUI.DrawTexture(rect, image, ScaleMode.StretchToFill); | ||
} | ||
|
||
public override void RefreshLayout() | ||
{ | ||
if (image == null || image.width == 0 || image.height == 0) | ||
return; | ||
|
||
// Image size is always half width of page area | ||
base.RefreshLayout(); | ||
imageWidth = (float)MaxWidth * LocalScale.x / 2f; | ||
scaleFactor = (float)MaxWidth / (float)image.width; | ||
imageHeight = (float)image.height * scaleFactor * LocalScale.y / 2f; | ||
Size = new Vector2(imageWidth, imageHeight); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Place images into this folder for use by localized books. | ||
Insert image into book using the markup [/image=filename] in book text. | ||
Accepts PNG and JPG images. | ||
|
||
For example: | ||
|
||
[/image=lakecastle.png] | ||
|
||
Will attempt to insert the image "lakecastle.png" from BookImages. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.