Difference between revisions of "Adding UI Hints"

From Second Life Wiki
Jump to navigation Jump to search
m (fixed syntax highlighting)
m (tags)
Line 2: Line 2:


'''Step 1: Make sure you have the necessary include file.'''
'''Step 1: Make sure you have the necessary include file.'''
<c>
<cpp>
#include "llnotifications.h"
#include "llnotifications.h"
</c>
</cpp>


'''Step 2: add a notification to notifications.xml using the following template.'''
'''Step 2: add a notification to notifications.xml using the following template.'''
Line 21: Line 21:
'''Step 3: Trigger the hint using the notifications system.'''
'''Step 3: Trigger the hint using the notifications system.'''


<c>
<cpp>
LLNotifications::instance().add(LLNotification::Params("HintName"));
LLNotifications::instance().add(LLNotification::Params("HintName"));
</c>
</cpp>


That handles the simple case.
That handles the simple case.
Line 33: Line 33:


'''Step 1: You can modify the hint parameters via the notification "payload".  The hint parameters can be found in llhint.h.'''
'''Step 1: You can modify the hint parameters via the notification "payload".  The hint parameters can be found in llhint.h.'''
<c>
<cpp>
LLSD hint_payload;
LLSD hint_payload;
hint_payload["fade_in_time"] = 2.f;
hint_payload["fade_in_time"] = 2.f;
hint_payload["fade_out_time"] = 1.f;
hint_payload["fade_out_time"] = 1.f;
</c>
</cpp>


'''Step 2: You can add string substitutions in the substitutions parameter.'''
'''Step 2: You can add string substitutions in the substitutions parameter.'''


<c>
<cpp>
LLSD substitutions;
LLSD substitutions;
substitutions["USER_NAME"] = "Richard Linden";
substitutions["USER_NAME"] = "Richard Linden";
</c>
</cpp>


'''Step 3: Then trigger the hint with the expanded add function.'''
'''Step 3: Then trigger the hint with the expanded add function.'''


<c>
<cpp>
LLNotifications::instance().add(LLNotification::Params().
LLNotifications::instance().add(LLNotification::Params().
   name("HintName").
   name("HintName").
   substitutions(string_substitutions).
   substitutions(string_substitutions).
   payload(hint_payload)));
   payload(hint_payload)));
</c>
</cpp>


== Attaching Hints ==
== Attaching Hints ==
Line 61: Line 61:
'''Step 1: Register the UI element with a unique name in the setup code associated with that particular UI.'''
'''Step 1: Register the UI element with a unique name in the setup code associated with that particular UI.'''


<c>
<cpp>
BOOL LLMyFloater::postBuild()
BOOL LLMyFloater::postBuild()
{
{
Line 67: Line 67:
   return TRUE;
   return TRUE;
}
}
</c>
</cpp>


'''Step 2: Trigger the notification with the target parameter set.'''
'''Step 2: Trigger the notification with the target parameter set.'''


<c>
<cpp>
LLSD hint_payload;
LLSD hint_payload;
hint_payload["target"] = "my_hint_target";
hint_payload["target"] = "my_hint_target";
Line 79: Line 79:
   ...
   ...
   payload(hint_payload)));
   payload(hint_payload)));
</c>
</cpp>


== First Use Only ==
== First Use Only ==
Line 103: Line 103:
'''Step 2: Add a method to LLFirstUse to trigger the hint.'''
'''Step 2: Add a method to LLFirstUse to trigger the hint.'''


<c>
<cpp>
void jumping(bool enable=true);
void jumping(bool enable=true);


Line 115: Line 115:
   firstUseNotification("FirstJump", enable, "HintJump", substitutions, hint_payload);
   firstUseNotification("FirstJump", enable, "HintJump", substitutions, hint_payload);
}
}
</c>
</cpp>


'''Step 3: Call the first use function when the behavior is triggered.'''
'''Step 3: Call the first use function when the behavior is triggered.'''


<c>
<cpp>
void LLAgent::jump()
void LLAgent::jump()
{
{
Line 125: Line 125:
   LLFirstUse::jumping(true);
   LLFirstUse::jumping(true);
}
}
</c>
</cpp>


'''Step 4: Call the first use function with false to immediately disable the hint.'''
'''Step 4: Call the first use function with false to immediately disable the hint.'''


<c>
<cpp>
// after 10 minutes, we assume you know how to jump
// after 10 minutes, we assume you know how to jump
LLFirstUse::jumping(false);
LLFirstUse::jumping(false);
</c>
</cpp>


That's it!
That's it!

Revision as of 07:33, 16 October 2013

Simple Hint

Step 1: Make sure you have the necessary include file. <cpp>

  1. include "llnotifications.h"

</cpp>

Step 2: add a notification to notifications.xml using the following template. <xml> <notification name="HintName" label="Hint text that appears on top" type="hint" unique="true">

 Hint contents here.

</notification> </xml>

unique="true" limits the number of instances of this hint to 1...if you want to spawn the same hint in multiple locations simultaneously, remove this line.

Step 3: Trigger the hint using the notifications system.

<cpp> LLNotifications::instance().add(LLNotification::Params("HintName")); </cpp>

That handles the simple case.

Customizing the Hint

If you want to customize the appearance/contents of the hint...

Step 1: You can modify the hint parameters via the notification "payload". The hint parameters can be found in llhint.h. <cpp> LLSD hint_payload; hint_payload["fade_in_time"] = 2.f; hint_payload["fade_out_time"] = 1.f; </cpp>

Step 2: You can add string substitutions in the substitutions parameter.

<cpp> LLSD substitutions; substitutions["USER_NAME"] = "Richard Linden"; </cpp>

Step 3: Then trigger the hint with the expanded add function.

<cpp> LLNotifications::instance().add(LLNotification::Params().

 name("HintName").
 substitutions(string_substitutions).
 payload(hint_payload)));

</cpp>

Attaching Hints

If you want to attach the hint to an existing UI element:

Step 1: Register the UI element with a unique name in the setup code associated with that particular UI.

<cpp> BOOL LLMyFloater::postBuild() {

 LLHints::registerHintTarget("my_hint_target", getChild<LLButton>("my_button")->getHandle());
 return TRUE;

} </cpp>

Step 2: Trigger the notification with the target parameter set.

<cpp> LLSD hint_payload; hint_payload["target"] = "my_hint_target"; hint_payload["direction"] = "left"; // hint will appear to the left of the target

LLNotifications::instance().add(

 ...
 payload(hint_payload)));

</cpp>

First Use Only

If you want to trigger the hint only the first time a certain condition is met, use LLFirstUse.

Step 1: Add a setting to ignorable_dialogs.xml so we can remember when a condition has already been triggered, like this:

<xml> <key>FirstJump</key> <map>

 <key>Comment</key>
 <string>Shows hint when resident jumps for the first time</string>
 <key>Persist</key>
 <integer>1</integer>
 <key>Type</key>
 <string>Boolean</string>
 <key>Value</key>
 <integer>1</integer>

</map> </xml>

Step 2: Add a method to LLFirstUse to trigger the hint.

<cpp> void jumping(bool enable=true);

// static void LLFirstUse::jumping(bool enable) {

 LLSD substitutions;
 ...
 LLSD hint_payload;
 ...
 firstUseNotification("FirstJump", enable, "HintJump", substitutions, hint_payload);

} </cpp>

Step 3: Call the first use function when the behavior is triggered.

<cpp> void LLAgent::jump() {

 ...
 LLFirstUse::jumping(true);

} </cpp>

Step 4: Call the first use function with false to immediately disable the hint.

<cpp> // after 10 minutes, we assume you know how to jump LLFirstUse::jumping(false); </cpp>

That's it!