示例#1
0
    //
    // - - -  Export Story Module Data
    //

    /// <summary>
    /// generate a string containing all storyHelp data in an suitable format to export to a file
    /// </summary>
    /// <returns></returns>
    public string CreateStoryHelpExport()
    {
        StringBuilder builder = new StringBuilder();

        builder.AppendFormat("Story Help{0}", "\n");
        Dictionary <string, StoryHelp> dictOfStoryHelp = GameManager.i.dataScript.GetDictOfStoryHelp();

        if (dictOfStoryHelp != null)
        {
            List <string> tempList = dictOfStoryHelp.Keys.ToList();
            if (tempList != null)
            {
                tempList.Sort();
                for (int i = 0; i < tempList.Count; i++)
                {
                    StoryHelp help = GameManager.i.dataScript.GetStoryHelp(tempList[i]);
                    if (help != null)
                    {
                        builder.AppendFormat("{0}Name: {1}{2}", "\n", help.name, "\n");
                        builder.AppendFormat("Tag: {0}{1}", help.tag, "\n");
                        if (help.sprite != null)
                        {
                            builder.AppendFormat("Sprite: {0}{1}", help.sprite.name, "\n");
                        }
                        else
                        {
                            builder.AppendFormat("Sprite: default{0}", "\n");
                        }
                        builder.AppendFormat("{0}{1}{2}", "\n", help.textTop, "\n");
                        builder.AppendFormat("{0}{1}{2}", "\n", help.textMiddle, "\n");
                        builder.AppendFormat("{0}{1}{2}", "\n", help.textBottom, "\n");
                        builder.AppendLine();
                    }
                    else
                    {
                        Debug.LogWarningFormat("Invalid storyHelp (Null) for key \"{0}\"", tempList[i]);
                    }
                }
            }
            else
            {
                Debug.LogError("Invalid tempList (Null) for dictOfStoryHelp");
            }
        }
        else
        {
            Debug.LogError("Invalid dictOfStoryHelp (Null)");
        }
        return(builder.ToString());
    }
 /// <summary>
 /// Initialise tooltip info
 /// </summary>
 /// <param name="listOfHelpData"></param>
 /// <param name="x_offset"></param>
 /// <param name="y_offset"></param>
 public void SetHelpTooltip(StoryHelp storyHelpInput, int x_offset = 200, int y_offset = 0)
 {
     if (storyHelpInput != null)
     {
         storyHelp = storyHelpInput;
     }
     else
     {
         Debug.LogWarning("Invalid storyHelp parameter (Null)");
         //default data
         storyHelp = GameManager.i.dataScript.GetStoryHelp("default");
         if (storyHelp == null)
         {
             Debug.LogWarning("Invalid storyHelp (Null) as default help not found in dict");
         }
     }
     //offsets
     this.x_offset = x_offset;
     this.y_offset = y_offset;
 }
示例#3
0
    /// <summary>
    /// Initialise Help Tool tip. General Purpose. Can take one to four text topics and auto divides them as necessary. Topics are displayed in their list order
    /// Colours are set by the calling method
    /// </summary>
    public void SetTooltip(StoryHelp storyHelp, Vector3 screenPos)
    {
        //exit any tooltip that might be open
        GameManager.i.tooltipGenericScript.CloseTooltip("TooltipHelp.cs -> OnPointerEnter");
        if (storyHelp != null)
        {
            //set story help as known
            storyHelp.isKnown = true;
            //open panel at start
            storyCanvas.gameObject.SetActive(true);
            storyObject.SetActive(true);
            //populate texts if valid data present
            textHeader.text = GameManager.Formatt(storyHelp.tag, ColourType.salmonText);
            //top
            if (storyHelp.textTop != null && storyHelp.textTop.Length > 0)
            {
                textTop.gameObject.SetActive(true);
                textTop.text = GameManager.i.topicScript.CheckTopicText(storyHelp.textTop, false);
            }
            //middle
            if (storyHelp.textMiddle != null && storyHelp.textMiddle.Length > 0)
            {
                textMiddle.gameObject.SetActive(true);
                textMiddle.text = GameManager.i.topicScript.CheckTopicText(storyHelp.textMiddle, false);
            }
            //bottom
            if (storyHelp.textBottom != null && storyHelp.textBottom.Length > 0)
            {
                textBottom.gameObject.SetActive(true);
                textBottom.text = GameManager.i.topicScript.CheckTopicText(storyHelp.textBottom, false);
            }
            //sprite -> default 'Info' sprite if none present
            if (storyHelp.sprite != null)
            {
                storyImage.sprite = storyHelp.sprite;
            }
            else
            {
                storyImage.sprite = GameManager.i.spriteScript.infoSprite;
            }
            //update rectTransform to get a correct height as it changes every time with the dynamic menu resizing depending on number of buttons
            Canvas.ForceUpdateCanvases();
            rectTransform = storyObject.GetComponent <RectTransform>();
            //get dimensions of dynamic tooltip
            float width        = rectTransform.rect.width;
            float height       = rectTransform.rect.height;
            float halfWidth    = width * 0.5f;
            float halfHeight   = height * 0.5f;
            float difference_y = screenPos.y - halfHeight;
            //y pos (from top of screen)
            if (screenPos.y + halfHeight >= Screen.height)
            {
                screenPos.y -= (screenPos.y + halfHeight - Screen.height) - offset;
            }                                                                       //NOTE: change from '+' offset to '-' offset
            //y pos (from bottom of screen)
            else if (difference_y <= 0)
            {
                screenPos.y += difference_y * -1 + offset;
            }
            //x pos
            if (screenPos.x + width >= Screen.width)
            {
                screenPos.x -= (width * 2 + screenPos.x - Screen.width);
            }
            //minimum position of tooltip from Left Hand side is half width
            else if (screenPos.x <= halfWidth)
            {
                screenPos.x = halfWidth;
            }
            else
            {
                screenPos.x += width / 4;
            }                                  //never applies, dead code

            //set new position
            storyObject.transform.position = screenPos;
            Debug.LogFormat("[UI] TooltipStoryHelp.cs -> SetTooltip{0}", "\n");
        }
        else
        {
            Debug.LogWarning("Invalid storyHelp (Empty)");
        }
    }