コード例 #1
0
        public override bool OnMouseUp(Widget w, MouseInput mi)
        {
            // Main Menu root
            if (w.Id == "MAINMENU_BUTTON_JOIN")
            {
                var bg = Game.chrome.rootWidget.ShowMenu("JOINSERVER_BG");

                int height = 50;
                int width = 300;
                int i = 0;
                GameList = MasterServerQuery.GetGameList(Game.Settings.MasterServer).ToArray();

                bg.Children.RemoveAll(a => GameButtons.Contains(a));
                GameButtons.Clear();

                foreach (var game in GameList)
                {
                    ButtonWidget b = new ButtonWidget();
                    b.Bounds = new Rectangle(bg.Bounds.X + 20, bg.Bounds.Y + height, width, 25);
                    b.GetType().GetField("Id").SetValue(b, "JOIN_GAME_{0}".F(i));
                    b.GetType().GetField("Text").SetValue(b, "{0} ({1})".F(game.Name, game.Address));
                    b.GetType().GetField("Delegate").SetValue(b, "ServerBrowserDelegate");

                    bg.AddChild(b);
                    GameButtons.Add(b);

                    height += 35;
                }

                return true;
            }

            if (w.Id == "JOINSERVER_BUTTON_DIRECTCONNECT")
            {
                Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
                Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort);
                return true;
            }

            if (w.Id.Substring(0, 10) == "JOIN_GAME_")
            {
                Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
                int index = int.Parse(w.Id.Substring(10));
                var game = GameList[index];
                Game.JoinServer(game.Address.Split(':')[0], int.Parse(game.Address.Split(':')[1]));
                return true;
            }

            if (w.Id == "JOINSERVER_BUTTON_CANCEL")
            {
                Game.chrome.rootWidget.ShowMenu("MAINMENU_BG");
                return true;
            }

            return false;
        }