Ejemplo n.º 1
0
        private void ExecuteScript(object sender, UIEventArgs e)
        {
            if (e.keyboardState.IsKeyDown(Keys.Enter) && e.lastKeyboardState.IsKeyUp(Keys.Enter))
            {
                OnCommandSubmitted(this, e);
                //log.Add(inputbox.Text);
                //from Microsoft.Xna.Framework import *\n
                StringBuilder userCode = new StringBuilder();
                userCode.Append("import clr\nclr.AddReference('IronPython')\nclr.AddReference('MonoGame.Framework')\nclr.AddReference('OpenTK')\nfrom Microsoft.Xna.Framework import *\nfrom IronPython.Hosting import Python\nimport Wartorn\nfrom Wartorn import *\n");
                userCode.Append(inputbox.Text);
                inputbox.Clear();

                ScriptSource source = _engine.CreateScriptSourceFromString(userCode.ToString());
                CompiledCode code   = null;
                //catch compile error
                try
                {
                    code = source.Compile();
                }
                catch (Exception err)
                {
                    ExceptionOperations eo = _engine.GetService <ExceptionOperations>();
                    Utility.HelperFunction.Log(eo.FormatException(err) + '\n' + userCode.ToString());
                    log.Add("error when compile script");
                    return;
                }

                //catch runtim error
                try
                {
                    code.Execute(_scope);
                }
                catch (Exception err)
                {
                    ExceptionOperations eo = _engine.GetService <ExceptionOperations>();
                    Utility.HelperFunction.Log(eo.FormatException(err) + '\n' + userCode.ToString());
                    log.Add("error when execute script");
                }
            }
        }
Ejemplo n.º 2
0
 protected virtual void OnButtonPressed(object sender, UIEventArgs e)
 {
     ButtonPressed?.Invoke(sender, e);
 }
Ejemplo n.º 3
0
 protected virtual void OnCommandSubmitted(object sender, UIEventArgs e)
 {
     CommandSubmitted?.Invoke(sender, e);
 }
Ejemplo n.º 4
0
 protected virtual void OnLostFocus(object sender, UIEventArgs e)
 {
     LostFocus?.Invoke(sender, e);
 }
Ejemplo n.º 5
0
 protected virtual void OnKeyPress(object sender, UIEventArgs e)
 {
     KeyPress?.Invoke(sender, e);
 }
Ejemplo n.º 6
0
 protected virtual void OnMouseLeave(object sender, UIEventArgs e)
 {
     MouseLeave?.Invoke(sender, e);
 }
Ejemplo n.º 7
0
 protected virtual void OnMouseEnter(object sender, UIEventArgs e)
 {
     MouseEnter?.Invoke(sender, e);
 }
Ejemplo n.º 8
0
 protected virtual void OnMouseDown(object sender, UIEventArgs e)
 {
     MouseDown?.Invoke(sender, e);
 }
Ejemplo n.º 9
0
 protected virtual void OnMouseClick(object sender, UIEventArgs e)
 {
     MouseClick?.Invoke(sender, e);
 }
Ejemplo n.º 10
0
        public virtual void Update(InputState inputState, InputState lastInputState)
        {
            UIEventArgs arg = new UIEventArgs(inputState, lastInputState);

            //LostFocus
            if (!rect.Contains(inputState.mouseState.Position) && inputState.mouseState.LeftButton == ButtonState.Pressed)
            {
                isFocused = false;
                OnLostFocus(this, arg);
            }

            //GotFocus
            if (rect.Contains(inputState.mouseState.Position) && inputState.mouseState.LeftButton == ButtonState.Pressed)
            {
                isFocused = true;

                OnGotFocus(this, arg);
            }

            //MouseClick
            if (rect.Contains(inputState.mouseState.Position) &&
                (lastInputState.mouseState.LeftButton == ButtonState.Released &&
                 inputState.mouseState.LeftButton == ButtonState.Pressed))
            {
                OnMouseClick(this, arg);
            }

            //MouseDown
            if (rect.Contains(inputState.mouseState.Position) &&
                inputState.mouseState.LeftButton == ButtonState.Pressed)
            {
                OnMouseDown(this, arg);
            }

            //MouseUp
            if (rect.Contains(inputState.mouseState.Position) &&
                (lastInputState.mouseState.LeftButton == ButtonState.Pressed &&
                 inputState.mouseState.LeftButton == ButtonState.Released))
            {
                OnMouseUp(this, arg);
            }

            //MouseEnter
            if (rect.Contains(inputState.mouseState.Position) &&
                !rect.Contains(lastInputState.mouseState.Position))
            {
                OnMouseEnter(this, arg);
            }

            //MouseLeave
            if (!rect.Contains(inputState.mouseState.Position) &&
                rect.Contains(lastInputState.mouseState.Position))
            {
                OnMouseLeave(this, arg);
            }

            //MouseHover
            if (rect.Contains(inputState.mouseState.Position))
            {
                OnMouseHover(this, arg);
            }

            //KeyPress
            if (isFocused && inputState.keyboardState.GetPressedKeys().GetLength(0) > 0)
            {
                OnKeyPress(this, arg);
            }
        }