Browse Source

Merge pull request #136 from FungusGames/fit-storytext-to-image

Fit storytext to image
master
Chris Gregan 10 years ago
parent
commit
2b35dabd96
  1. 36
      Assets/Fungus/Narrative/Resources/SayDialog.prefab
  2. 5
      Assets/Fungus/Narrative/Scripts/Commands/Say.cs
  3. 53
      Assets/Fungus/Narrative/Scripts/SayDialog.cs
  4. 1423
      Assets/Tests/Narrative/NarrativeTests.unity

36
Assets/Fungus/Narrative/Resources/SayDialog.prefab

@ -451,6 +451,8 @@ MonoBehaviour:
nameText: {fileID: 11488900} nameText: {fileID: 11488900}
storyText: {fileID: 11488896} storyText: {fileID: 11488896}
characterImage: {fileID: 11448914} characterImage: {fileID: 11448914}
fitTextWithImage: 1
textWidthScale: .800000012
--- !u!114 &11488896 --- !u!114 &11488896
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
@ -630,12 +632,12 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 22443574} - {fileID: 22443574}
m_Father: {fileID: 22488900} m_Father: {fileID: 22488896}
m_RootOrder: 3 m_RootOrder: 1
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 1533.59998, y: 83.8300018} m_AnchoredPosition: {x: -38.9000244, y: 38.0749931}
m_SizeDelta: {x: 77.9000015, y: 77} m_SizeDelta: {x: 77.9000244, y: 77}
m_Pivot: {x: .5, y: .5} m_Pivot: {x: .5, y: .5}
--- !u!224 &22443574 --- !u!224 &22443574
RectTransform: RectTransform:
@ -665,11 +667,11 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 22488900} m_Father: {fileID: 22488900}
m_RootOrder: 1 m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 1435, y: 404} m_AnchoredPosition: {x: 1386, y: 263.130005}
m_SizeDelta: {x: 300, y: 300} m_SizeDelta: {x: 357, y: 435}
m_Pivot: {x: .5, y: .5} m_Pivot: {x: .5, y: .5}
--- !u!224 &22488894 --- !u!224 &22488894
RectTransform: RectTransform:
@ -681,11 +683,11 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 22488900} m_Father: {fileID: 22488896}
m_RootOrder: 0 m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 622.25, y: 281} m_AnchoredPosition: {x: 588.75, y: 235.37001}
m_SizeDelta: {x: 1178.5, y: 71} m_SizeDelta: {x: 1178.5, y: 71}
m_Pivot: {x: .5, y: .5} m_Pivot: {x: .5, y: .5}
--- !u!224 &22488896 --- !u!224 &22488896
@ -697,13 +699,15 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children:
- {fileID: 22488894}
- {fileID: 22433354}
m_Father: {fileID: 22488900} m_Father: {fileID: 22488900}
m_RootOrder: 2 m_RootOrder: 1
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 803, y: 145.630005} m_AnchoredPosition: {x: 799, y: 145.630005}
m_SizeDelta: {x: 1539, y: 199.75} m_SizeDelta: {x: 1531, y: 200}
m_Pivot: {x: .5, y: .5} m_Pivot: {x: .5, y: .5}
--- !u!224 &22488900 --- !u!224 &22488900
RectTransform: RectTransform:
@ -715,10 +719,8 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 22488894}
- {fileID: 22448914} - {fileID: 22448914}
- {fileID: 22488896} - {fileID: 22488896}
- {fileID: 22433354}
m_Father: {fileID: 22488902} m_Father: {fileID: 22488902}
m_RootOrder: 0 m_RootOrder: 0
m_AnchorMin: {x: .5, y: 0} m_AnchorMin: {x: .5, y: 0}

5
Assets/Fungus/Narrative/Scripts/Commands/Say.cs

@ -72,11 +72,12 @@ namespace Fungus
} }
Flowchart flowchart = GetFlowchart(); Flowchart flowchart = GetFlowchart();
sayDialog.SetCharacter(character, flowchart);
sayDialog.SetCharacterImage(portrait);
sayDialog.gameObject.SetActive(true); sayDialog.gameObject.SetActive(true);
sayDialog.SetCharacter(character, flowchart);
sayDialog.SetCharacterImage(portrait);
string displayText = storyText; string displayText = storyText;
foreach (CustomTag ct in CustomTag.activeCustomTags) foreach (CustomTag ct in CustomTag.activeCustomTags)

53
Assets/Fungus/Narrative/Scripts/SayDialog.cs

@ -23,6 +23,15 @@ namespace Fungus
public Text storyText; public Text storyText;
public Image characterImage; public Image characterImage;
[Tooltip("Adjust width of story text when Character Image is displayed (to avoid overlapping)")]
public bool fitTextWithImage = true;
[Tooltip("Scale factor to apply to story text width when Character Image is displayed")]
public float textWidthScale = 0.8f;
protected float startStoryTextWidth;
protected float startStoryTextInset;
protected WriterAudio writerAudio; protected WriterAudio writerAudio;
protected Writer writer; protected Writer writer;
protected CanvasGroup canvasGroup; protected CanvasGroup canvasGroup;
@ -184,6 +193,12 @@ namespace Fungus
float delta = (1f / fadeDuration) * Time.deltaTime; float delta = (1f / fadeDuration) * Time.deltaTime;
float alpha = Mathf.MoveTowards(canvasGroup.alpha, targetAlpha, delta); float alpha = Mathf.MoveTowards(canvasGroup.alpha, targetAlpha, delta);
canvasGroup.alpha = alpha; canvasGroup.alpha = alpha;
if (alpha <= 0f)
{
// Deactivate dialog object once invisible
gameObject.SetActive(false);
}
} }
} }
@ -247,16 +262,44 @@ namespace Fungus
public virtual void SetCharacterImage(Sprite image) public virtual void SetCharacterImage(Sprite image)
{ {
if (characterImage != null) if (characterImage == null)
{
return;
}
if (image != null)
{
characterImage.sprite = image;
characterImage.gameObject.SetActive(true);
}
else
{
characterImage.gameObject.SetActive(false);
}
// Adjust story text box to not overlap image rect
if (fitTextWithImage &&
storyText != null &&
characterImage.gameObject.activeSelf)
{ {
if (image != null) if (startStoryTextWidth == 0)
{ {
characterImage.sprite = image; startStoryTextWidth = storyText.rectTransform.rect.width;
characterImage.gameObject.SetActive(true); startStoryTextInset = storyText.rectTransform.offsetMin.x;
}
// Clamp story text to left or right depending on relative position of the character image
if (storyText.rectTransform.position.x < characterImage.rectTransform.position.x)
{
storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left,
startStoryTextInset,
startStoryTextWidth - characterImage.rectTransform.rect.width);
} }
else else
{ {
characterImage.gameObject.SetActive(false); storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right,
startStoryTextInset,
startStoryTextWidth - characterImage.rectTransform.rect.width);
} }
} }
} }

1423
Assets/Tests/Narrative/NarrativeTests.unity

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save