Exemplo n.º 1
0
    //////////////////////////////////////////////////////////////////////////
    // The external interface methods for the GUI scripts.
    //

    /** Finds the network event of the specified type. */
    public TPTabletUIEvent FindNetworkEvent(string type)
    {
        //TPTabletUIManager mgr = TPTabletUIManager.GetInstance();
        //mgr.PutErrorMessage("FindNetworkEvent(" + type + ")");
        int i;

        for (i = 0; i < m_networkEvents.Count; i++)
        {
            TPTabletUIEvent ev = m_networkEvents[i] as TPTabletUIEvent;
            if (ev.GetEventType() == type)
            {
                return(ev);
            }
        }
        //mgr.PutErrorMessage("FindNetworkEvent(" + type + ") Failed to find event.");
        return(null);
    }
Exemplo n.º 2
0
        public bool Parse(ConfigElement ce)
        {
            TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

            m_textString = ce.GetAttribute("textString");
            string attrib = ce.GetAttribute("textColor");

            if (!string.IsNullOrEmpty(attrib))
            {
                string[] vec = attrib.Split(' ');
                if (vec.Length != 3)
                {
                    mgr.PutErrorMessage("Found an invalid textColor attribute (Button/Data : "
                                        + m_parent.GetName() + ").");
                    return(false);
                }
                float r, g, b;
                float.TryParse(vec[0], out r);
                float.TryParse(vec[1], out g);
                float.TryParse(vec[2], out b);
                m_textColor.r = r / 255.0f;
                m_textColor.g = g / 255.0f;
                m_textColor.b = b / 255.0f;
            }
            attrib = ce.GetAttribute("textSize");
            if (!string.IsNullOrEmpty(attrib))
            {
                int.TryParse(attrib, out m_textSize);
            }
            attrib = ce.GetAttribute("textAlignment");
            if (!string.IsNullOrEmpty(attrib))
            {
                if (attrib == "left" || attrib == "middle_left")
                {
                    m_textAlignment = TextAnchor.MiddleLeft;
                }
                else if (attrib == "celter" || attrib == "middle_center")
                {
                    m_textAlignment = TextAnchor.MiddleCenter;
                }
                else if (attrib == "right" || attrib == "middle_right")
                {
                    m_textAlignment = TextAnchor.MiddleRight;
                }
                else if (attrib == "upper_left")
                {
                    m_textAlignment = TextAnchor.UpperLeft;
                }
                else if (attrib == "upper_center")
                {
                    m_textAlignment = TextAnchor.UpperCenter;
                }
                else if (attrib == "upper_right")
                {
                    m_textAlignment = TextAnchor.UpperRight;
                }
                else if (attrib == "lower_left")
                {
                    m_textAlignment = TextAnchor.LowerLeft;
                }
                else if (attrib == "lower_center")
                {
                    m_textAlignment = TextAnchor.LowerCenter;
                }
                else if (attrib == "lower_right")
                {
                    m_textAlignment = TextAnchor.LowerRight;
                }
                else
                {
                    mgr.PutErrorMessage("Found an invalid textAlignment attribute (Button/Data : "
                                        + m_parent.GetName() + ") : " + attrib);
                    return(false);
                }
            }
            attrib = ce.GetAttribute("normalImage");
            if (!string.IsNullOrEmpty(attrib))
            {
                m_images[0] = mgr.GetImage(attrib);
                if (m_images[0] == null)
                {
                    mgr.PutErrorMessage("No such an image : " + attrib);
                    return(false);
                }
            }
            attrib = ce.GetAttribute("activeImage");
            if (!string.IsNullOrEmpty(attrib))
            {
                m_images[1] = mgr.GetImage(attrib);
                if (m_images[1] == null)
                {
                    mgr.PutErrorMessage("No such an image : " + attrib);
                    return(false);
                }
            }
            attrib = ce.GetAttribute("normalBgColor");
            if (!string.IsNullOrEmpty(attrib))
            {
                string[] vec = attrib.Split(' ');
                if (vec.Length != 3)
                {
                    mgr.PutErrorMessage("Found an invalid normalBgColor attribute (Button/Data : "
                                        + m_parent.GetName() + ").");
                    return(false);
                }
                float r, g, b;
                float.TryParse(vec[0], out r);
                float.TryParse(vec[1], out g);
                float.TryParse(vec[2], out b);
                m_bgColors[0].r = r / 255.0f;
                m_bgColors[0].g = g / 255.0f;
                m_bgColors[0].b = b / 255.0f;
                m_bgColors[0].a = 1.0f;                 // Indicates that the normalBgColor attribute has been specified.
            }
            attrib = ce.GetAttribute("activeBgColor");
            if (!string.IsNullOrEmpty(attrib))
            {
                string[] vec = attrib.Split(' ');
                if (vec.Length != 3)
                {
                    mgr.PutErrorMessage("Found an invalid activeBgColor attribute (Button/Data : "
                                        + m_parent.GetName() + ").");
                    return(false);
                }
                float r, g, b;
                float.TryParse(vec[0], out r);
                float.TryParse(vec[1], out g);
                float.TryParse(vec[2], out b);
                m_bgColors[1].r = r / 255.0f;
                m_bgColors[1].g = g / 255.0f;
                m_bgColors[1].b = b / 255.0f;
                m_bgColors[1].a = 1.0f;                 // Indicates that the activeBgColor attribute has been specified.
            }

            int i;

            for (i = 0; i < ce.GetNumChildren(); i++)
            {
                ConfigElement child = ce.GetChild(i);
                string        name  = child.GetName();
                if (name == "Event")
                {
                    TPTabletUIEvent buttonEvent = new TPTabletUIEvent();
                    if (buttonEvent.Parse(child))
                    {
                        m_events[buttonEvent.GetEventType()] = buttonEvent;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 3
0
    public bool Parse(byte[] bytes)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        ConfigFile cf = new ConfigFile();

        if (!cf.Parse(bytes))
        {
            return(false);
        }
        ConfigElement root = cf.GetRoot();

        if (root.GetName() != "TabletInterface")
        {
            mgr.PutErrorMessage("The configuration file is invalid.");
            return(false);
        }

        m_networkEvents = new ArrayList();
        m_rootGroups    = new ArrayList();

        int i;

        for (i = 0; i < root.GetNumChildren(); i++)
        {
            ConfigElement ce   = root.GetChild(i);
            string        name = ce.GetName();
            if (name == "NetworkEvent")
            {
                TPTabletUIEvent networkEvent = new TPTabletUIEvent();
                if (networkEvent.Parse(ce))
                {
                    m_networkEvents.Add(networkEvent);
                }
                else
                {
                    return(false);
                }
            }
            else if (name == "GUIDefinition")
            {
                ConfigElement guiDef = ce;
                string        attrib = ce.GetAttribute("orientation");
                if (!string.IsNullOrEmpty(attrib))
                {
                    if (attrib == "vertical")
                    {
                        m_orientation = ScreenOrientation.Portrait;
                    }
                    else if (attrib == "horizontal")
                    {
                        m_orientation = ScreenOrientation.LandscapeLeft;
                    }
                    else
                    {
                        mgr.PutErrorMessage("Found an invalid orientation attribute. (" + attrib + ")");
                        return(false);
                    }
                }
                int j;
                for (j = 0; j < guiDef.GetNumChildren(); j++)
                {
                    ce = guiDef.GetChild(j);
                    if (ce.GetName() == "Group")
                    {
                        TPTabletUIGroup rootGroup = CreateGroup();
                        if (rootGroup.Parse(ce))
                        {
                            m_rootGroups.Add(rootGroup);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
        }

        CalculateRect();

        return(true);
    }