示例#1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a ChatBox section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public ChatBox(string configFileFilename)
        {
            m_DraggableWidget = true;

            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

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

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

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "backgroundcolor")
                {
                    BackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "bordercolor")
                {
                    BorderColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "borders")
                {
                    Borders borders;
                    if (Internal.ExtractBorders(configFile.Values [i], out borders))
                    {
                        Borders = borders;
                    }
                }
                else if (configFile.Properties[i] == "scrollbar")
                {
                    if ((configFile.Values[i].Length < 3) || (configFile.Values[i][0] != '"') || (configFile.Values[i][configFile.Values[i].Length - 1] != '"'))
                    {
                        throw new Exception("Failed to parse value for Scrollbar in section ChatBox in " + m_LoadedConfigFile + ".");
                    }

                    // load the scrollbar
                    m_Scroll = new Scrollbar(configFileFolder + (configFile.Values[i]).Substring(1, configFile.Values[i].Length - 2));
                    m_Scroll.VerticalScroll = true;
                    m_Scroll.Size           = new Vector2f(m_Scroll.Size.X, m_Panel.Size.Y);
                    m_Scroll.LowValue       = (int)(m_Panel.Size.Y);
                    m_Scroll.Maximum        = (int)m_FullTextHeight;
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section ChatBox in " + m_LoadedConfigFile + ".");
                }
            }
        }
示例#2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a ComboBox section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public ComboBox(string configFileFilename)
        {
            m_DraggableWidget = true;

            m_ListBox.Visible               = false;
            m_ListBox.Size                  = new Vector2f(50, 24);
            m_ListBox.ItemHeight            = 24;
            m_ListBox.ItemSelectedCallback += NewItemSelectedCallbackFunction;
            m_ListBox.UnfocusedCallback    += ListBoxUnfocusedCallbackFunction;

            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

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

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

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "separatehoverimage")
                {
                    m_SeparateHoverImage = configFile.ReadBool(i);
                }
                else if (configFile.Properties[i] == "backgroundcolor")
                {
                    BackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "textcolor")
                {
                    TextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "selectedbackgroundcolor")
                {
                    SelectedBackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "selectedtextcolor")
                {
                    SelectedTextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "bordercolor")
                {
                    BorderColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "arrowupnormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowUpNormal);
                }
                else if (configFile.Properties[i] == "arrowuphoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowUpHover);
                }
                else if (configFile.Properties[i] == "arrowdownnormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowDownNormal);
                }
                else if (configFile.Properties[i] == "arrowdownhoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowDownHover);
                }
                else if (configFile.Properties[i] == "borders")
                {
                    Borders borders;
                    if (Internal.ExtractBorders(configFile.Values [i], out borders))
                    {
                        Borders = borders;
                    }
                }
                else if (configFile.Properties[i] == "scrollbar")
                {
                    if ((configFile.Values[i].Length < 3) || (configFile.Values[i][0] != '"') || (configFile.Values[i][configFile.Values[i].Length - 1] != '"'))
                    {
                        throw new Exception("Failed to parse value for Scrollbar in section ChatBox in " + m_LoadedConfigFile + ".");
                    }

                    // load the scrollbar
                    m_ListBox.SetScrollbar(configFileFolder + (configFile.Values[i]).Substring(1, configFile.Values[i].Length - 2));
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section ComboBox in " + m_LoadedConfigFile + ".");
                }
            }

            // Make sure the required textures were loaded
            if ((m_TextureArrowUpNormal.texture == null) || (m_TextureArrowDownNormal.texture == null))
            {
                throw new Exception("Not all needed images were loaded for the combo box. Is the ComboBox section in " + m_LoadedConfigFile + " complete?");
            }

            // Check if optional textures were loaded
            if ((m_TextureArrowUpHover.texture != null) && (m_TextureArrowDownHover.texture != null))
            {
                m_WidgetPhase |= (byte)WidgetPhase.Hover;
            }
        }