public bool Parse(ConfigElement ce)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        m_type = ce.GetAttribute("type");
        if (string.IsNullOrEmpty(m_type))
        {
            mgr.PutErrorMessage("Found an Event/NetworkEvent element which doesn't have the type attribute.");
            return(false);
        }

        int i;

        for (i = 0; i < ce.GetNumChildren(); i++)
        {
            ConfigElement child = ce.GetChild(i);
            if (child.GetName() == "Action")
            {
                string command = child.GetAttribute("command");
                if (!string.IsNullOrEmpty(command))
                {
                    m_commands.Add(command);
                }
            }
        }
        return(true);
    }
    /** 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()));
    }
Exemple #3
0
    /** Parses the specified XML configuration file, and extracts all the elements. */
    public bool Parse(byte[] bytes)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        mgr.PutErrorMessage("ConfigFile::Parse");

        // Create the XmlReader instance for the specified file.
        XmlReaderSettings settings = new XmlReaderSettings();

        settings.ConformanceLevel = ConformanceLevel.Document;
        XmlReader reader = null;

        try {
            reader = XmlReader.Create(new MemoryStream(bytes), settings);
            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                if (reader.Depth == 0)
                {
                    // Detected the root element.
                    m_root = new ConfigElement();
                    m_root.Parse(reader, null);
                }
            }
        }catch (Exception e) {
            mgr.PutErrorMessage(e.Message);
            return(false);
        }
        return(true);
    }
    /** 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));
    }
Exemple #5
0
    /** Gets the only one TPTabletUIManager class instance. */
    public static TPTabletUIManager GetInstance()
    {
        // Get the reference to the TPTabletUIManager script component.
        GameObject go = GameObject.Find("TPTabletUIManager");

        if (go == null)
        {
            Debug.LogError("The TPTabletUIManager GameObject object is not found.");
            return(null);
        }
        TPTabletUIManager inst = go.GetComponent(typeof(TPTabletUIManager)) as TPTabletUIManager;

        if (inst == null)
        {
            Debug.LogError("The TPTabletUIManager script component is not found.");
        }
        return(inst);
    }
Exemple #6
0
    /** Initializes the instance. */
    public bool Initialize()
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        // Set up the data buffer.
        m_buffer = new byte [256];
        int i;

        for (i = 0; i < m_buffer.Length; i++)
        {
            m_buffer[i] = 0;
        }

        // Get the IP address and the port number from the Settings bundle.
        m_ipAddress = PlayerPrefs.GetString("ip_address");
        string portNumber = PlayerPrefs.GetString("port_number");

        if (m_ipAddress == "" || portNumber == "")
        {
            mgr.PutErrorMessage("Failed to get the IP address or the port number from Settings.bundle.");
            return(false);
        }
        m_port = int.Parse(portNumber);

        // Try to connect to the server.
        try {
            m_tcpClient = new TcpClient(m_ipAddress, m_port);
            //m_tcpClient = new TcpClient("10.120.64.108", m_port);
            m_tcpClient.NoDelay = true;                 // Disable buffering of the data.
            // Get the data stream.
            m_networkStream = m_tcpClient.GetStream();
        } catch (Exception e) {
            mgr.PutErrorMessage("Failed to connect to the server : " + e.Message);
            return(false);
        }

        return(true);
    }
        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);
        }
    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);
    }
    /** 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());
    }
    public bool Parse(ConfigElement ce)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        m_name = ce.GetAttribute("name");

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

        if (string.IsNullOrEmpty(attrib))
        {
            mgr.PutErrorMessage("Found a Button 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 (Button : "
                                    + GetName() + ").");
                return(false);
            }
            float.TryParse(vec[0], out m_position.x);
            float.TryParse(vec[1], out m_position.y);
        }

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

        int i;

        for (i = 0; i < ce.GetNumChildren(); i++)
        {
            ConfigElement child = ce.GetChild(i);
            string        name  = child.GetName();
            if (name == "Selection")
            {
                attrib = child.GetAttribute("index");
                if (!string.IsNullOrEmpty(attrib))
                {
                    int.TryParse(attrib, out m_selection);
                    m_orgSelection = m_selection;
                }
            }
            else if (name == "Data")
            {
                Data datum = new Data(this);
                if (datum.Parse(child))
                {
                    m_data.Add(datum);
                }
                else
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Exemple #13
0
    /** Sends a request for a GUI data file. */
    public byte[] RequestGUIFile(string file)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        mgr.PutErrorMessage("TPNetworkClient::RequestGUIFile");

        if (!Send("#requestguifile:" + file))
        {
            return(null);
        }

        // Receive the header part of the reply message.
        int dataLength = 0, bodyLength = 0;

        while (true)
        {
            try {
                if (m_networkStream.DataAvailable)
                {
                    byte[] buffer = CreateBuffer(8);
                    int    index  = 0;
                    while (true)
                    {
                        int nBytes = m_networkStream.Read(buffer, index, buffer.Length - index);
                        if (nBytes == 0)
                        {
                            // Although DataAvailable was true, we couldn't get anything from the stream.
                            // Some error seems to have occurred.
                            throw new Exception("Failed to receive a GUI file data (the header part).");
                        }
                        else if ((index + nBytes) == buffer.Length)
                        {
                            break;                              // Complete receiving a message.
                        }
                        else
                        {
                            index += nBytes;                            // Need to receive the rest of the message.
                        }
                    }
                    // Decompose the received message into two 32-bit integers.
                    dataLength = BitConverter.ToInt32(buffer, 0);
                    bodyLength = BitConverter.ToInt32(buffer, 4);
                    break;
                }
                else
                {
                    // NOTE : We need to see if this actually works as we expected.
                    Thread.Sleep(0);                            // To avoid a busy loop.
                }
            }catch (Exception e) {
                mgr.PutErrorMessage(e.Message);
                return(null);
            }
        }

        while (true)
        {
            try {
                if (m_networkStream.DataAvailable)
                {
                    byte[] buffer = CreateBuffer(bodyLength);
                    int    index  = 0;
                    while (true)
                    {
                        int nBytes = m_networkStream.Read(buffer, index, buffer.Length - index);
                        if (nBytes == 0)
                        {
                            // Although DataAvailable was true, we couldn't get anything from the stream.
                            // Some error seems to have occurred.
                            throw new Exception("Failed to receive the GUI file list (the body part).");
                        }
                        else if ((index + nBytes) == buffer.Length)
                        {
                            break;                              // Complete receiving a message.
                        }
                        else
                        {
                            index += nBytes;                            // Need to receive the rest of the message.
                        }
                    }
                    byte[] data = CreateBuffer(dataLength);
                    Buffer.BlockCopy(buffer, 0, data, 0, dataLength);
                    return(data);
                }
                else
                {
                    // NOTE : We need to see if this actually works as we expected.
                    Thread.Sleep(0);                            // To avoid a busy loop.
                }
            }catch (Exception e) {
                mgr.PutErrorMessage(e.Message);
                break;
            }
        }

        return(null);
    }
Exemple #14
0
    /** Sends a request for the list of files which are used for setting up the tablet's GUI. */
    public string[] RequestGUIFileList()
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        mgr.PutErrorMessage("TPNetworkClient::RequestGUIFileList");

        if (!Send("#requestguifilelist"))
        {
            return(null);
        }

        // Receive the header part of the reply message.
        int bodyLength = 0, nFiles = 0;

        while (true)
        {
            try {
                if (m_networkStream.DataAvailable)
                {
                    byte[] buffer = CreateBuffer(8);
                    int    index  = 0;
                    while (true)
                    {
                        int nBytes = m_networkStream.Read(buffer, index, buffer.Length - index);
                        if (nBytes == 0)
                        {
                            // Although DataAvailable was true, we couldn't get anything from the stream.
                            // Some error seems to have occurred.
                            throw new Exception("Failed to receive the GUI file list (the header part).");
                        }
                        else if ((index + nBytes) == buffer.Length)
                        {
                            break;                              // Complete receiving a message.
                        }
                        else
                        {
                            index += nBytes;                            // Need to receive the rest of the message.
                        }
                    }
                    // Decompose the received message into two 32-bit integers.
                    nFiles     = BitConverter.ToInt32(buffer, 0);
                    bodyLength = BitConverter.ToInt32(buffer, 4);
                    break;
                }
                else
                {
                    // NOTE : We need to see if this actually works as we expected.
                    Thread.Sleep(0);                            // To avoid a busy loop.
                }
            }catch (Exception e) {
                mgr.PutErrorMessage(e.Message);
                return(null);
            }
        }

        if (nFiles == 0)
        {
            mgr.PutErrorMessage("The GUI file list has no elements.");
            return(null);
        }

        // Receive the body part of the reply message.
        string files;           // A string which contains comma-separated file names.

        while (true)
        {
            try {
                if (m_networkStream.DataAvailable)
                {
                    byte[] buffer = CreateBuffer(bodyLength);
                    int    index  = 0;
                    while (true)
                    {
                        int nBytes = m_networkStream.Read(buffer, index, buffer.Length - index);
                        if (nBytes == 0)
                        {
                            // Although DataAvailable was true, we couldn't get anything from the stream.
                            // Some error seems to have occurred.
                            throw new Exception("Failed to receive the GUI file list (the body part).");
                        }
                        else if ((index + nBytes) == buffer.Length)
                        {
                            break;                              // Complete receiving a message.
                        }
                        else
                        {
                            index += nBytes;                            // Need to receive the rest of the message.
                        }
                    }
                    // Convert the received message into a string.
                    StringBuilder strBldr = new StringBuilder();
                    int           i;
                    for (i = 0; i < buffer.Length; i++)
                    {
                        if (buffer[i] == 0)
                        {
                            break;
                        }
                        strBldr.Append((char)buffer[i]);
                    }
                    files = strBldr.ToString();
                    break;
                }
                else
                {
                    // NOTE : We need to see if this actually works as we expected.
                    Thread.Sleep(0);                            // To avoid a busy loop.
                }
            }catch (Exception e) {
                mgr.PutErrorMessage(e.Message);
                return(null);
            }
        }

        string[] result = files.Split(',');
        if (result.Length != nFiles)
        {
            mgr.PutErrorMessage("The number of files in the received GUI file list is invalid.");
            return(null);
        }
        return(result);
    }