Exemplo n.º 1
0
        //--------------------//

        #region Generate
        /// <summary>
        /// Generates a real dialog model from this XML-representation
        /// </summary>
        /// <param name="manager">The <see cref="DialogManager"/> instance that provides the resources for rendering of this dialog</param>
        /// <returns>The generated dialog model</returns>
        internal Render.Dialog GenerateRender(DialogManager manager)
        {
            // Load language XML
            string langName = (Resources.Culture == null) ? "English" : Resources.Culture.EnglishName.GetLeftPartAtFirstOccurrence(' ');

            _locale = LocaleFile.LoadLang(langName).ToDictionary();

            // Generate dialog model object
            DialogRender = TextureFileValid
                ? new Render.Dialog(manager, ColorText.ToColorValue(), _textureFile, _fontName, (uint)(_fontSize * EffectiveScale))
                : new Render.Dialog(manager, ColorText.ToColorValue());

            // Set dialog properites
            DialogRender.SetCaptionText(GetLocalized(_captionText));
            DialogRender.CaptionHeight = _captionHeight;
            UpdateColors();

            // Load custom button styles
            foreach (ButtonStyle style in ButtonStyles)
            {
                style.Parent = this;
                style.Generate();
            }

            // Generate control models from their view counterparts
            foreach (Control control in Controls)
            {
                control.Parent = this;
                control.Generate();
            }

            // Update control positions
            DialogRender.Resize += delegate
            {
                foreach (Control control in Controls)
                {
                    control.UpdateLayout();
                }
            };

            NeedsUpdate = false;
            return(DialogRender);
        }
Exemplo n.º 2
0
        public DialogRenderer(GuiManager manager, Dialog dialog, Point location = new Point(), Lua lua = null)
        {
            _manager     = manager;
            DialogModel  = dialog;
            DialogRender = dialog.GenerateRender(_manager.DialogManager);
            _location    = location;
            _lua         = lua;

            LayoutHelper();
            _manager.DialogManager.Engine.DeviceReset += LayoutHelper;

            if (lua != null)
            {
                #region Register Lua variables and functions
                // Register all controls as direct variables when possible
                foreach (var control in dialog.Controls)
                {
                    if (!string.IsNullOrEmpty(control.Name))
                    {
                        try
                        {
                            _lua[control.Name] = control;
                        }
                        catch (LuaException)
                        {}
                    }
                }

                _lua["Me"] = this;

                LuaRegistrationHelper.Enumeration <Render.MsgBoxType>(_lua);
                LuaRegistrationHelper.Enumeration <Render.MsgBoxResult>(_lua);
                #endregion

                dialog.ScriptFired += LuaExecute;
            }
        }