/** Gets the text size of the i-th button data. */
    public int GetDataTextSize(int i)
    {
        TPTabletUIConfig cfg  = TPTabletUIManager.GetInstance().GetConfig();
        Data             data = m_data[i] as Data;

        return((int)((float)data.GetTextSize() * cfg.GetScale()));
    }
    /** Gets the bounding rectangle of the group (absolute position and size). */
    public Rect GetRect()
    {
        TPTabletUIConfig cfg   = TPTabletUIManager.GetInstance().GetConfig();
        float            scale = cfg.GetScale();

        return(new Rect(m_boundRect.x * scale, m_boundRect.y * scale,
                        m_boundRect.width * scale, m_boundRect.height * scale));
    }
示例#3
0
 void Update()
 {
     if (m_initProcStat != InitProcStat.InProgress)
     {
         return;
     }
     if (m_assetBundleLoadStat == AssetBundleLoadStat.None)
     {
         // Start loading the asset bundle.
         m_assetBundleLoadStat = AssetBundleLoadStat.InProgress;
         StartCoroutine(LoadAssetBundle());
     }
     else if (m_assetBundleLoadStat == AssetBundleLoadStat.Success)
     {
         // We've succeeded in loading the asset bundle.
         // Load the XML configuration file from the cache directory, and create the TPTabletUIConfig instance.
         string path = Path.Combine(Application.persistentDataPath, m_filenameXML);
         byte[] bytes;
         try {
             bytes = File.ReadAllBytes(path);
         }catch (Exception e) {
             PutErrorMessage("TPTabletUIManager::Update");
             PutErrorMessage(e.Message);
             m_initProcStat = InitProcStat.Fail;
             return;
         }
         m_config = new TPTabletUIConfig();
         if (!m_config.Parse(bytes))                 // All the GUI data files are loaded during parsing.
         {
             m_config       = null;
             m_initProcStat = InitProcStat.Fail;
             return;
         }
         m_initProcStat = InitProcStat.Success;              // The initialization procedure has successfully ended.
     }
     else if (m_assetBundleLoadStat == AssetBundleLoadStat.Fail)
     {
         // We've failed in loadind the asset bundle.
         m_initProcStat = InitProcStat.Fail;
         return;
     }
 }
    /** Gets the position of this group (relative to the parent group). */
    public Vector2 GetPosition()
    {
        TPTabletUIConfig cfg = TPTabletUIManager.GetInstance().GetConfig();

        return(m_position * cfg.GetScale());
    }
    public bool Parse(ConfigElement ce)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();
        TPTabletUIConfig  cfg = mgr.GetConfig();

        m_name = ce.GetAttribute("name");

        string attrib = ce.GetAttribute("position");

        if (string.IsNullOrEmpty(attrib))
        {
            mgr.PutErrorMessage("Found a Group element ("
                                + GetName() + ") which doesn't have the position attribute.");
            return(false);
        }
        else
        {
            string[] vec = attrib.Split(' ');
            if (vec.Length != 2)
            {
                mgr.PutErrorMessage("Found an invalid position attribute (Group : "
                                    + GetName() + ").");
                return(false);
            }
            float.TryParse(vec[0], out m_position.x);
            float.TryParse(vec[1], out m_position.y);
        }

        attrib = ce.GetAttribute("mode");
        if (!string.IsNullOrEmpty(attrib))
        {
            if (attrib == "all")
            {
                m_mode = Mode.All;
            }
            else if (attrib == "selection")
            {
                m_mode = Mode.Selection;
            }
            else
            {
                mgr.PutErrorMessage("Found an invalid mode attribute (Group : "
                                    + GetName() + ") : " + attrib);
                return(false);
            }
        }

        int i;

        for (i = 0; i < ce.GetNumChildren(); i++)
        {
            ConfigElement child = ce.GetChild(i);
            string        name  = child.GetName();
            if (name == "Enable")
            {
                attrib = child.GetAttribute("value");
                if (!string.IsNullOrEmpty(attrib))
                {
                    if (attrib == "true")
                    {
                        m_enabled = true;
                    }
                    else if (attrib == "false")
                    {
                        m_enabled = false;
                    }
                    else
                    {
                        mgr.PutErrorMessage("Found an invalid value attribute (Group/Enable : "
                                            + GetName() + ") : " + attrib);
                        return(false);
                    }
                    m_orgEnabled = m_enabled;
                }
            }
            else if (name == "Selection")
            {
                attrib = child.GetAttribute("index");
                if (!string.IsNullOrEmpty(attrib))
                {
                    int.TryParse(attrib, out m_selection);
                    m_orgSelection = m_selection;
                }
            }
            else if (name == "Group")
            {
                TPTabletUIGroup grp = cfg.CreateGroup();
                if (grp.Parse(child))
                {
                    m_groups.Add(grp);
                }
                else
                {
                    return(false);
                }
            }
            else if (name == "Button")
            {
                TPTabletUIButton btn = cfg.CreateButton();
                if (btn.Parse(child))
                {
                    m_buttons.Add(btn);
                }
                else
                {
                    return(false);
                }
            }
        }

        return(true);
    }
    /** Gets the size of this button. */
    public Vector2 GetSize()
    {
        TPTabletUIConfig cfg = TPTabletUIManager.GetInstance().GetConfig();

        return(m_size * cfg.GetScale());
    }