Author Topic: Hoverable/clickable parts of the text  (Read 11468 times)

isperia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Hoverable/clickable parts of the text
« on: January 29, 2014, 11:00:26 AM »
Hello all!

I would like to grab some advices on the following issue:

I am developing collectible card game, and each card have some kind of layout; Example:
  1. [{"simpleText":"%t: Goblin gets +1"},{"ability":"1023123ff","params":{}}]

Card description consists of simple texts and some "links" to other abilities.
I want this content to be presented as a big text, with triggering hovers over "links" (so, the ability will be described in a tooltip text), and maybe clicks.

How can I do it within NGUI considering i'm using _not_ monospaced font?

Thanks in advance


Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #1 on: January 29, 2014, 11:29:37 AM »
Graphicstream Dev.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #2 on: January 29, 2014, 11:08:06 PM »
NGUI doesn't have any support for hyperlinks out of the box. Not yet anyway.

isperia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #3 on: January 30, 2014, 12:54:54 AM »
I think i will split text in words and make a lot of labels (one per word), placing them via measuring (since text should be some rows).

Each "Linked" word will have some behaviour of link attached, simple words will be as is

Do you think that will get high impact on performance?

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #4 on: January 30, 2014, 02:03:44 AM »
Splitting text into many labels is too much work, it must be done automatically.

Maybe look at the hyperlink here : http://www.tasharen.com/forum/index.php?topic=3695.0
Graphicstream Dev.

isperia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #5 on: January 30, 2014, 03:44:16 AM »
It is not that hard actualy, but I faced with one more problem:
I have some prefab "MarkupWord", that contains tooltip stuff to appear via behaviour:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class HoverTooltip : MonoBehaviour {
  5.  
  6.         public string tooltip;
  7.  
  8.         // Use this for initialization
  9.         void Start () {
  10.                
  11.         }
  12.        
  13.         // Update is called once per frame
  14.         void Update () {
  15.        
  16.         }
  17.  
  18.         void OnTooltip(bool show) {
  19.                 Debug.LogWarning("TOOLTIP : " + show);
  20.                 if (show) {
  21.                         UITooltip.ShowText(tooltip);
  22.                 } else {
  23.                         UITooltip.ShowText(null);
  24.                 }
  25.         }
  26.  
  27. }
  28.  

It has UILabel component attached.

If I add this to root scene, tooltip works ok, but i have a card object that is UISprite with Button component attached.
That card object has empty widget - container for my words.
When i add these objects to that widget, the tooltip is never triggered for them :(
  1. private void AddWord(string word) {
  2.                 GameObject markupObject = NGUITools.AddChild(textContainer.gameObject, prefabLabel);
  3.                 markupObject.transform.localScale = new Vector3(SCALE_CONTENT, SCALE_CONTENT, 1f);
  4.                 UILabel label = (UILabel) markupObject.GetComponent(typeof(UILabel));
  5.                 HoverMarkup markupHover = (HoverMarkup) markupObject.GetComponent(typeof(HoverMarkup));
  6.                 markupHover.tooltip = word + "%c%f%b";
  7.                 label.text = word;
  8.                 Debug.LogWarning("Added text: <" + word + "> " + label.width + "," + label.height);
  9.                 //caret new line
  10.                 if (mCursorWidth + label.width * SCALE_CONTENT > textContainer.width) {
  11.                         mCursorHeight -= label.height * SCALE_CONTENT;
  12.                         mCursorWidth = 0f;
  13.                 }
  14.                 markupObject.transform.localPosition = new Vector3(mCursorWidth, mCursorHeight, 0f);
  15.                 mCursorWidth += SCALE_CONTENT * label.width;
  16.         }
  17.  

Is that true, that parent object catches all mouse stuff and doesnt allow children to trigger tooltips?
What can I do about it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #6 on: January 30, 2014, 11:30:21 AM »
The hyperlink support is a planned feature, I would suggest you just wait. I should get around to implementing it within a week or two.

isperia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #7 on: January 30, 2014, 11:56:53 AM »
Ok, I will be glad if this feature is implemented soon, but the question is still up.

If I make a widget with button behaviour, and want to make child of this object tooltipable, child wont trigger. Looks like parent button intercepts mouse events. What workaround or solution should I use to reach this functionality?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #8 on: January 30, 2014, 12:17:19 PM »
You can't choose to catch only specific events in NGUI. A collider catches all of them. Instead, have some logic inside the button's OnTooltip function that will determine if you're over some child, and show the tooltip for that child instead.

isperia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #9 on: January 31, 2014, 01:27:39 AM »
But that OnTooltip would be incorrect for a part of the object (since mouse moved in long ago, but e.g. just entered the word i need to tooltip, and tooltip will appear unexpectedly fast).

That is not the main problem here.

Did I understand right, that the event system finds first legal target for applying event and stops? Why my children dont get these events?
I find it very inconvinient and incorrect to ray trace child objects for checking if mouse is over them during parent event instead of just delivering events to child. That is what event system should do, shouldn't it? :(

isperia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Hoverable/clickable parts of the text
« Reply #10 on: January 31, 2014, 03:54:26 AM »
Deleted last post due to found some good thing.

I get children trigger indeed if I setup box collider in right way (since i dynamically update label content that is freely resize, i need to setup box collider as I do it)
All I added is:

  1. BoxCollider collider = (BoxCollider) markupObject.GetComponent(typeof(BoxCollider));
  2.                 collider.size = new Vector3(label.width, label.height, 0f);
  3.                 collider.center = new Vector3(label.width/2, -label.height/2, 0f);

Now child gets the mouse event, but parent doesn't. Well, I can live with this