示例#1
0
        public virtual new void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            var mouseState = Mouse.GetState();
            var mousePoint = new Point(mouseState.X, mouseState.Y);
            var rectangle  = new Rectangle((int)base.Position.X, (int)base.Position.Y, (int)framesDimensions.X, (int)framesDimensions.Y);

            if (enabled)
            {
                if (rectangle.Contains(mousePoint))
                {
                    isClicked = mouseState.LeftButton == ButtonState.Pressed;
                }
                else
                {
                    isClicked = false;
                }

                if (isClicked)
                {
                    if (!t.Enabled)
                    {
                        clickAction.Invoke();
                        t.Enabled = true;
                    }
                }
            }
        }
示例#2
0
 // If //
 public static bool If(this bool condition, MyAction action)
 {
     if (condition)
     {
         action.Invoke();
     }
     return(condition);
 }
示例#3
0
        /// <summary>
        /// 调用委托的类
        /// </summary>
        public static void DelegateFun()
        {
            //声明一个委托
            MyAction ac1 = Fun2;

            ac1("ac1");//调用委托
            DelegateTest test    = new DelegateTest();
            MyAction     ac_fun1 = test.Fun1;

            ac_fun1.Invoke("hello world");//Invoke方法也可以调用委托
            return;

            //匿名委托
            MyAction2 ac2 = delegate(string str)
            {
                Console.WriteLine(str);
                return(1);
            };

            ac2("ac2");

            //使用lambda表达式
            MyAction2 ac3 = str => 1;

            Console.WriteLine(ac3("ac3"));

            // 使用泛型委托
            // Action是无返回值的泛型委托。它也是用:public delegate void Action<in T>(T obj);声明得到的
            // Action至少0个参数,至多16个参数,无返回值。
            Action <int, int> ac4 = (str, str2) => Console.WriteLine(str + str2);

            ac4(1, 2);

            // Func是有返回值的泛型委托。它是用:public delegate TResult Func<in T, out TResult>(T arg);声明得到的
            // Func至少0个参数,至多16个参数,根据返回值泛型返回。必须有返回值,不可void
            Func <int, int, bool> ac5 = (str, str2) =>
            {
                if (str > str2)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };

            Console.WriteLine(ac5(5, 3));

            //myCase:
            Predicate <int> ac6 = (str) =>
            {
                return(str % 2 == 0 ? true : false);
            };

            Console.WriteLine(ac6(0));
        }
示例#4
0
 private void ShowAuthor(object sender, EventArgs e)
 {
     Action.Tapped -= ShowAuthor;
     try
     {
         ShowAuthorPage?.Invoke(int.Parse(AuthorID.Text));
     }
     finally { }
     Action.Tapped += ShowAuthor;
 }
示例#5
0
        public void callDelegate()
        {
            MyDelegate?.Invoke(2, 3);

            var funcResult = MyFunc?.Invoke(4, 5);

            // Returns no result.
            MyAction?.Invoke(32, 44);

            MyEvent?.Invoke(this, new TwoNumbersEventArgs(44, 55));
        }
示例#6
0
 /// <summary> (array.Length).Loop(i => action(array[i], i)); </summary>
 public static T[] ForEach <T>(this T[] array, MyAction <T, int> action)
 {
     array.Length.Loop(i => action.Invoke(array[i], i), null);
     return(array);
 }
示例#7
0
 public void CancelItem()
 {
     delay.Start();
     close.Invoke();
     alive = false;
 }
示例#8
0
 public void PlaceItem()
 {
     delay.Start();
     place.Invoke();
 }
 public void PopPopup()
 {
     MyAction?.Invoke();
 }
示例#10
0
        public void Update(GameTime gameTime)
        {
            if (RetroEnvironment.GetLanguageManager() != null)
            {
                buttonName.SetText(RetroEnvironment.GetLanguageManager().TryGetValue(buttonName.GetOriginalText()));
            }
            buttonName.Update(gameTime);

            var mouseState = Mouse.GetState();
            var mousePoint = new Point(mouseState.X, mouseState.Y);

            if (area.Contains(mousePoint))
            {
                isHovered = true;
                isClicked = mouseState.LeftButton == ButtonState.Pressed;
            }
            else
            {
                isHovered = false;
                isClicked = false;
            }

            if (isHovered && !isClicked)
            {
                if (!t.Enabled)
                {
                    buttons.ForEach(s => s.loadFrame(2));
                    if (backdropB.GetColor() != colorsB[0])
                    {
                        backdropB.SetColor(colorsB[2]);
                    }
                    if (backdropT.GetColor() != colorsT[0])
                    {
                        backdropT.SetColor(colorsT[2]);
                    }
                }
            }
            else if (isClicked)
            {
                buttons.ForEach(s => s.loadFrame(1));
                if (backdropB.GetColor() != colorsB[1])
                {
                    backdropB.SetColor(colorsB[1]);
                }
                if (backdropT.GetColor() != colorsT[1])
                {
                    backdropT.SetColor(colorsT[1]);
                }
                if (!t.Enabled)
                {
                    clickAction.Invoke();
                    t.Enabled = true;
                }
            }
            else
            {
                if (!t.Enabled)
                {
                    buttons.ForEach(s => s.loadFrame(0));
                    if (backdropB.GetColor() != colorsB[0])
                    {
                        backdropB.SetColor(colorsB[0]);
                    }
                    if (backdropT.GetColor() != colorsT[0])
                    {
                        backdropT.SetColor(colorsT[0]);
                    }
                }
            }
        }