예제 #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a LoadingBar section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public LoadingBar(string configFileFilename)
        {
            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "LoadingBar");

            // Find the folder that contains the config file
            string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "backimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_M);
                    m_SplitImage = false;
                }
                else if (configFile.Properties[i] == "frontimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_M);
                }
                else if (configFile.Properties[i] == "backimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_L);
                }
                else if (configFile.Properties[i] == "backimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_M);
                    m_SplitImage = true;
                }
                else if (configFile.Properties[i] == "backimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_R);
                }
                else if (configFile.Properties[i] == "frontimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_L);
                }
                else if (configFile.Properties[i] == "frontimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_M);
                }
                else if (configFile.Properties[i] == "frontimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_R);
                }
                else if (configFile.Properties [i] == "textcolor")
                {
                    TextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties [i] == "textsize")
                {
                    TextSize = Convert.ToUInt32(configFile.Values [i]);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section LoadingBar in " + m_LoadedConfigFile + ".");
                }
            }

            // Check if the image is split
            if (m_SplitImage)
            {
                // Make sure the required textures were loaded
                if ((m_TextureBack_L.texture != null) && (m_TextureBack_M.texture != null) && (m_TextureBack_R.texture != null) &&
                    (m_TextureFront_L.texture != null) && (m_TextureFront_M.texture != null) && (m_TextureFront_R.texture != null))
                {
                    m_Size.X = (float)(m_TextureBack_L.Size.X + m_TextureBack_M.Size.X + m_TextureBack_R.Size.X);
                    m_Size.Y = (float)(m_TextureBack_M.Size.Y);

                    m_TextureBack_M.texture.texture.Repeated  = true;
                    m_TextureFront_M.texture.texture.Repeated = true;
                }
                else
                {
                    throw new Exception("Not all needed images were loaded for the loading bar. Is the LoadingBar section in " + m_LoadedConfigFile + " complete?");
                }
            }
            else // The image isn't split
            {
                // Make sure the required textures were loaded
                if ((m_TextureBack_M.texture != null) && (m_TextureFront_M.texture != null))
                {
                    m_Size = new Vector2f(m_TextureBack_M.Size.X, m_TextureBack_M.Size.Y);
                }
                else
                {
                    throw new Exception("TGUI error: Not all needed images were loaded for the loading bar. Is the LoadingBar section in " + m_LoadedConfigFile + " complete?");
                }
            }

            // Calculate the size of the front image (the size of the part that will be drawn)
            RecalculateSize();
        }