protected override void UpdateInternal(TimeSpan delta, bool updateInput)
        {
            base.UpdateInternal(delta, updateInput);
            if (Texts.Count > 0 && !Enabled)
            {
                Texts[0].Text          = Button.Text;
                Texts[0].ColorOverride = Color4.Gray;
            }
            if ((Animation != null && Animation.Running) || !Enabled)
            {
                return;
            }

            var h   = Scene.GHeight * Style.Size.Height;
            var w   = h * Style.Size.Ratio;
            var pos = CalculatePosition();
            var r   = new Rectangle((int)pos.X, (int)pos.Y, (int)w, (int)h);

            hoverStyle.Reset();
            if (updateInput && r.Contains(Scene.MouseX, Scene.MouseY))
            {
                if (!lastInside)
                {
                    if (!string.IsNullOrEmpty(Button.OnEnter))
                    {
                        Scene.Call(Button.OnEnter);
                    }
                }
                lastInside = true;
                if (!lastDown && Scene.MouseDown(MouseButtons.Left))
                {
                    if (!string.IsNullOrEmpty(Button.OnClick))
                    {
                        Scene.Call(Button.OnClick);
                    }
                }
                if (hoverChunk != null)
                {
                    LuaStyleEnvironment.Do(hoverChunk, hoverStyle, (float)Scene.Manager.Game.TotalTime);
                }
            }
            else
            {
                lastInside = false;
            }
            modelColor  = hoverStyle.ModelColor;
            modelRotate = hoverStyle.Rotation;
            if (Enabled && Texts.Count > 0 && hoverStyle.TextColor != null)
            {
                Texts[0].ColorOverride = hoverStyle.TextColor;
            }
            else if (Enabled && Texts.Count > 0)
            {
                Texts[0].ColorOverride = null;
            }
            lastDown = Scene.MouseDown(MouseButtons.Left);
        }
Beispiel #2
0
        void LoadScene(string id)
        {
            if (lua != null)
            {
                lua.Dispose();
            }
            Elements = new List <XmlUIElement>();
            lua      = new Lua();
            env      = lua.CreateEnvironment();
            env.DoChunk("events = {}", "$internal");
            env.Add(apiname, api);
            env.Add("dom", new LuaDom(this));
            env.Add("sound", new LuaSound(this));
            LuaStyleEnvironment.RegisterFuncs(env);
            _g = (dynamic)env;
            var scn = xml.Scenes.Where((x) => x.ID == id).First();

            if (scn.Scripts != null)
            {
                foreach (var script in scn.Scripts)
                {
                    env.DoChunk(script, "$xml");
                }
            }
            foreach (var item in scn.Items)
            {
                if (item is XInt.Button)
                {
                    var btn = (XInt.Button)item;
                    Elements.Add(new XmlUIButton(this, btn, styles.Where((x) => x.ID == btn.Style).First()));
                }
                else if (item is XInt.Image)
                {
                    Elements.Add(new XmlUIImage((XInt.Image)item, this));
                }
                else if (item is XInt.ServerList)
                {
                    var sl = (XInt.ServerList)item;
                    Elements.Add(new XmlUIServerList(sl, styles.Where((x) => x.ID == sl.Style).First(), this));
                }
                else if (item is XInt.Panel)
                {
                    var pnl = (XInt.Panel)item;
                    Elements.Add(new XmlUIPanel(pnl, styles.Where((x) => x.ID == pnl.Style).First(), this));
                }
                else if (item is XInt.ChatBox)
                {
                    var cb = (XInt.ChatBox)item;
                    Elements.Add(new XmlChatBox(cb, styles.Where((x) => x.ID == cb.Style).First(), this));
                }
            }
        }
        protected override void UpdateInternal(TimeSpan delta)
        {
            base.UpdateInternal(delta);
            if (Texts.Count > 0 && !Enabled)
            {
                Texts[0].Text          = Button.Text;
                Texts[0].ColorOverride = Color4.Gray;
            }
            if ((Animation != null && Animation.Running) || !Enabled)
            {
                return;
            }

            var h   = Manager.Game.Height * Style.Size.Height;
            var w   = h * Style.Size.Ratio;
            var pos = CalculatePosition();
            var r   = new Rectangle((int)pos.X, (int)pos.Y, (int)w, (int)h);

            hoverStyle.Reset();
            if (r.Contains(Manager.Game.Mouse.X, Manager.Game.Mouse.Y))
            {
                if (!lastDown && Manager.Game.Mouse.IsButtonDown(MouseButtons.Left))
                {
                    if (!string.IsNullOrEmpty(Button.OnClick))
                    {
                        Manager.Call(Button.OnClick);
                    }
                }
                if (hoverChunk != null)
                {
                    LuaStyleEnvironment.Do(hoverChunk, hoverStyle, (float)Manager.Game.TotalTime);
                }
            }
            modelColor  = hoverStyle.ModelColor;
            modelRotate = hoverStyle.Rotation;
            lastDown    = Manager.Game.Mouse.IsButtonDown(MouseButtons.Left);
            if (Texts.Count > 0)
            {
                Texts[0].Text          = Button.Text;
                Texts[0].ColorOverride = hoverStyle.TextColor;
            }
        }
Beispiel #4
0
        void LoadScene(string id)
        {
            stackChanged = true;
            var scene = new XmlUIScene(this);

            Scenes.Push(scene);
            scene.lua = new Lua();
            scene.env = scene.lua.CreateEnvironment();
            scene.env.DoChunk("events = {}", "$internal");
            scene.env.Add(apiname, api);
            scene.env.Add("dom", new LuaDom(this, scene));
            scene.env.Add("sound", new LuaSound(this));
            LuaStyleEnvironment.RegisterFuncs(scene.env);
            scene._g = (dynamic)scene.env;
            var scn = xml.Scenes.Where((x) => x.ID == id).First();

            if (scn.Scripts != null)
            {
                foreach (var script in scn.Scripts)
                {
                    scene.env.DoChunk(script, "$xml");
                }
            }
            foreach (var item in scn.Items)
            {
                if (item is XInt.Button)
                {
                    var btn = (XInt.Button)item;
                    Elements.Add(new XmlUIButton(scene, btn, styles.Where((x) => x.ID == btn.Style).First()));
                }
                else if (item is XInt.Image)
                {
                    Elements.Add(new XmlUIImage((XInt.Image)item, scene));
                }
                else if (item is XInt.ServerList)
                {
                    var sl = (XInt.ServerList)item;
                    Elements.Add(new XmlUIServerList(sl, styles.Where((x) => x.ID == sl.Style).First(), scene));
                }
                else if (item is XInt.CharacterList)
                {
                    var cl = (XInt.CharacterList)item;
                    Elements.Add(new XmlUICharacterList(cl, styles.Where(x => x.ID == cl.Style).First(), scene));
                }
                else if (item is XInt.TextBox)
                {
                    var tx = (XInt.TextBox)item;
                    Elements.Add(new XmlUITextBox(tx, styles.Where((x) => x.ID == tx.Style).First(), scene));
                }
                else if (item is XInt.ChatBox)
                {
                    var cb = (XInt.ChatBox)item;
                    Elements.Add(new XmlChatBox(cb, styles.Where((x) => x.ID == cb.Style).First(), scene));
                }
                else if (item is XInt.Panel)
                {
                    var pnl = (XInt.Panel)item;
                    Elements.Add(new XmlUIPanel(pnl, styles.Where((x) => x.ID == pnl.Style).First(), scene));
                }
            }
        }
        void LoadScene(string id)
        {
            stackChanged = true;
            var scene = new XmlUIScene(this);

            Scenes.Push(scene);
            scene.lua = new Lua();
            scene.env = scene.lua.CreateEnvironment();
            scene.env.DoChunk("events = {}", "$internal");
            if (apis != null)
            {
                foreach (var api in apis)
                {
                    scene.env.Add(api.ApiName, api.Api);
                }
            }

            scene.env.Add("dom", new LuaDom(this, scene));
            scene.env.Add("sound", new LuaSound(this));
            LuaStyleEnvironment.RegisterFuncs(scene.env);
            scene._g = (dynamic)scene.env;
            var scn = xml.Scenes.Where((x) => x.ID == id).First();

            if (scn.Scripts != null)
            {
                foreach (var script in scn.Scripts)
                {
                    try
                    {
                        scene.env.DoChunk(script, "$SCENE:" + scn.ID);
                    }
                    catch (LuaParseException e)
                    {
                        //Better exception message to the console when this crashes
                        throw new Exception(string.Format("Lua Error: {0} at {1}:{2}:{3}", e.Message, e.FileName, e.Line, e.Column));
                    }
                }
            }

            foreach (var item in scn.Items)
            {
                if (item is XInt.Button)
                {
                    var btn = (XInt.Button)item;
                    Elements.Add(new XmlUIButton(scene, btn, styles.Where((x) => x.ID == btn.Style).First()));
                }
                else if (item is XInt.Image)
                {
                    Elements.Add(new XmlUIImage((XInt.Image)item, scene));
                }
                else if (item is XInt.ServerList)
                {
                    var sl = (XInt.ServerList)item;
                    Elements.Add(new XmlUIServerList(sl, styles.Where((x) => x.ID == sl.Style).First(), scene));
                }
                else if (item is XInt.CharacterList)
                {
                    var cl = (XInt.CharacterList)item;
                    Elements.Add(new XmlUICharacterList(cl, styles.Where(x => x.ID == cl.Style).First(), scene));
                }
                else if (item is XInt.TextBox)
                {
                    var tx = (XInt.TextBox)item;
                    Elements.Add(new XmlUITextBox(tx, styles.Where((x) => x.ID == tx.Style).First(), scene));
                }
                else if (item is XInt.ChatBox)
                {
                    var cb = (XInt.ChatBox)item;
                    Elements.Add(new XmlChatBox(cb, styles.Where((x) => x.ID == cb.Style).First(), scene));
                }
                else if (item is XInt.Panel)
                {
                    var pnl = (XInt.Panel)item;
                    Elements.Add(new XmlUIPanel(pnl, styles.Where((x) => x.ID == pnl.Style).First(), scene));
                }
            }
        }