<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Making tooltips shown after pressed until another marker is pressed.]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=301&amp;type=atom" />
	<updated>2016-10-17T14:14:01Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=301</id>
		<entry>
			<title type="html"><![CDATA[Re: Making tooltips shown after pressed until another marker is pressed.]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1368#p1368" />
			<content type="html"><![CDATA[<p>This is the default behavior of tooltips, but you can easily override this:<br /></p><div class="codebox"><pre><code>using System;
using UnityEngine;

public class ShowMarkersOnPressExample:MonoBehaviour
{
    private OnlineMapsMarkerBase activeMarker;
    private OnlineMaps map;
    private GUIStyle tooltipStyle;

    private void Start()
    {
        map = OnlineMaps.instance;
        map.showMarkerTooltip = OnlineMapsShowMarkerTooltip.onPress;

        // Add an event to the markers created by the inspector
        foreach (OnlineMapsMarker marker in map.markers) marker.OnPress += OnMarkerPress;

        // Add an event to a new dynamic marker
        map.AddMarker(map.position, &quot;Dynamic marker&quot;).OnPress += OnMarkerPress;

        // Subscribe to OnUpdateAfter
        OnlineMapsControlBase.instance.OnUpdateAfter += OnUpdateAfter;

        // Intercepts tooltip style.
        map.OnPrepareTooltipStyle += OnPrepareTooltipStyle;

        // Intercepts drawing tooltips.
        OnlineMapsMarkerBase.OnMarkerDrawTooltip += OnMarkerDrawTooltip;
    }

    private void OnPrepareTooltipStyle(ref GUIStyle style)
    {
        tooltipStyle = style;
    }

    private void OnMarkerDrawTooltip(OnlineMapsMarkerBase marker)
    {
        // Get screen position of marker
        Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(marker.position);

        // Calculate the size
        GUIContent tip = new GUIContent(marker.label);
        Vector2 size = tooltipStyle.CalcSize(tip);

        // Draw the tooltip
        GUI.Label(new Rect(screenPosition.x - size.x / 2 - 5, Screen.height - screenPosition.y - size.y - 20, size.x + 10, size.y + 5), marker.label, tooltipStyle);
    }

    /// &lt;summary&gt;
    /// This event occurs at end Update
    /// &lt;/summary&gt;
    private void OnUpdateAfter()
    {
        // If activeMarker exists, restore tootip
        if (activeMarker != null)
        {
            map.tooltipMarker = activeMarker;
            map.tooltip = activeMarker.label;
        }
    }

    /// &lt;summary&gt;
    /// This event occurs on marker press
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;marker&quot;&gt;Instance of marker&lt;/param&gt;
    private void OnMarkerPress(OnlineMapsMarkerBase marker)
    {
        // Change active marker
        activeMarker = marker;
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-10-17T14:14:01Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1368#p1368</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Making tooltips shown after pressed until another marker is pressed.]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1366#p1366" />
			<content type="html"><![CDATA[<p>Thanks. I just checked it out. </p><p>It shows the tooltip, after press/relase. but the tooltip follows around the mouse instead of stick with the marker it blongs to.<br />I am looking into the script see what&#039;s causing that.</p>]]></content>
			<author>
				<name><![CDATA[lengxin]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=274</uri>
			</author>
			<updated>2016-10-17T13:59:14Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1366#p1366</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Making tooltips shown after pressed until another marker is pressed.]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1364#p1364" />
			<content type="html"><![CDATA[<p>Hello.</p><p>You can do this without any code modification:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class ShowMarkersOnPressExample:MonoBehaviour
{
    private OnlineMapsMarkerBase activeMarker;
    private OnlineMaps map;

    private void Start()
    {
        map = OnlineMaps.instance;
        map.showMarkerTooltip = OnlineMapsShowMarkerTooltip.onPress;

        // Add an event to the markers created by the inspector
        foreach (OnlineMapsMarker marker in map.markers) marker.OnPress += OnMarkerPress;

        // Add an event to a new dynamic marker
        map.AddMarker(map.position, &quot;Dynamic marker&quot;).OnPress += OnMarkerPress;

        // Subscribe to OnUpdateAfter
        OnlineMapsControlBase.instance.OnUpdateAfter += OnUpdateAfter;
    }

    /// &lt;summary&gt;
    /// This event occurs at end Update
    /// &lt;/summary&gt;
    private void OnUpdateAfter()
    {
        // If activeMarker exists, restore tootip
        if (activeMarker != null)
        {
            map.tooltipMarker = activeMarker;
            map.tooltip = activeMarker.label;
        }
    }

    /// &lt;summary&gt;
    /// This event occurs on marker press
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;marker&quot;&gt;Instance of marker&lt;/param&gt;
    private void OnMarkerPress(OnlineMapsMarkerBase marker)
    {
        // Change active marker
        activeMarker = marker;
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-10-17T06:49:19Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1364#p1364</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Making tooltips shown after pressed until another marker is pressed.]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1363#p1363" />
			<content type="html"><![CDATA[<p>Managed to achieve this by comments the lines below out. </p><p><span style="color: blue"><br />&nbsp; &nbsp; &nbsp; &nbsp; if (api.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onPress &amp;&amp; (api.tooltipMarker != null || api.tooltipDrawingElement != null))<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Debug.Log(&quot;Marker released&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //api.tooltipMarker = null;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //api.tooltipDrawingElement = null;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //api.tooltip = null;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br /></span></p><p>Not sure if this goint to cause issues down the line thouse.</p>]]></content>
			<author>
				<name><![CDATA[lengxin]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=274</uri>
			</author>
			<updated>2016-10-16T22:20:50Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1363#p1363</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Making tooltips shown after pressed until another marker is pressed.]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1362#p1362" />
			<content type="html"><![CDATA[<p>When change &quot; Show marker tooltip &quot; to &quot;Pressed,&nbsp; the tooltips disappear after the press is released/mouse up ? How can I make it stay until next marker is pressed ? </p><p>Thanks.</p>]]></content>
			<author>
				<name><![CDATA[lengxin]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=274</uri>
			</author>
			<updated>2016-10-16T22:02:18Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1362#p1362</id>
		</entry>
</feed>
