public void SetText(String text)
 {
     if (text != null && text.Length > 0)
     {
         if (label != null)
         {
             if (label.Parent() != this)
             {
                 AddView(label);
             }
             label.SetText(text);
         }
         else
         {
             label = new TextView(font, text);
             label.x = 0.5f * (width - label.width);
             label.y = 0.5f * (height - label.height);
             AddView(label);
         }
     }
     else
     {
         if (label != null)
         {
             RemoveView(label);
         }
     }
 }
        public DemoDebugView(Font font)
        {
            m_tickView = new TextView(font, "Tick: 9999999999");
            AddView(m_tickView);

            LayoutVer(0);
            ResizeToFitViews();
        }
        public MultiplayerLobbyScreen(ServerInfo serverInfo, ButtonDelegate buttonDelegate, bool isServer)
        {
            this.serverInfo = serverInfo;
            viewsLookup = new Dictionary<NetConnection, ClientInfoView>();

            View contentView = new View(512, 363);
            contentView.alignX = View.ALIGN_CENTER;
            contentView.x = 0.5f * width;
            contentView.y = 48;

            Font font = GetDefaultFont();

            contentView.AddView(new View(215, 145));

            TextView serverName = new TextView(font, serverInfo.name);
            serverName.alignX = View.ALIGN_CENTER;
            serverName.x = 113;
            serverName.y = 155;

            contentView.AddView(serverName);

            clientsView = new View(286, contentView.height);
            clientsView.alignX = View.ALIGN_MAX;
            clientsView.x = contentView.width;
            contentView.AddView(clientsView);

            AddView(contentView);

            View buttons = new View();
            buttons.x = 0.5f * width;
            buttons.y = 432;
            buttons.alignX = View.ALIGN_CENTER;
            buttons.alignY = View.ALIGN_MAX;

            Button button = new TempButton("BACK");
            button.buttonDelegate = buttonDelegate;
            button.id = (int)ButtonId.Back;
            buttons.AddView(button);
            SetCancelButton(button);

            String label = isServer ? "START" : "READY";
            ButtonId buttonId = isServer ? ButtonId.Start : ButtonId.Ready;

            button = new TempButton(label);
            button.buttonDelegate = buttonDelegate;
            button.id = (int)buttonId;
            buttons.AddView(button);

            buttons.LayoutHor(10);
            buttons.ResizeToFitViews();
            AddView(buttons);
        }
        public DialogPopup(DialogPopupDelegate popupDelegate, String title, String message, PopupButton cancelButton, params PopupButton[] buttons)
        {
            this.popupDelegate = popupDelegate;

            AddView(new RectView(0, 0, width, height, new Color(0.0f, 0.0f, 0.0f, 0.25f), Color.Black));

            RectView frameView = new RectView(0, 0, 0.75f * width, 0, new Color(0.0f, 0.0f, 0.0f, 0.75f), Color.Black);

            View content = new View();
            content.width = frameView.width - 2 * 50;
            content.alignX = content.alignY = View.ALIGN_CENTER;

            Font font = Helper.fontSystem;

            // title
            TextView titleView = new TextView(font, title);
            titleView.alignX = titleView.parentAlignX = View.ALIGN_CENTER;
            content.AddView(titleView);

            // message
            TextView messageView = new TextView(font, message, (int)content.width);
            messageView.alignX = messageView.parentAlignX = View.ALIGN_CENTER;
            content.AddView(messageView);

            // buttons
            Button button = new TempButton(cancelButton.title);
            button.id = (int)cancelButton.id;
            button.buttonDelegate = OnButtonPress;
            button.alignX = View.ALIGN_CENTER;
            button.parentAlignX = View.ALIGN_CENTER;
            SetCancelButton(button);

            content.AddView(button);

            content.LayoutVer(10);
            content.ResizeToFitViewsVer();

            frameView.AddView(content);

            frameView.ResizeToFitViewsVer(20, 20);
            frameView.alignX = frameView.alignY = frameView.parentAlignX = frameView.parentAlignY = View.ALIGN_CENTER;
            AddView(frameView);

            content.x = 0.5f * frameView.width;
            content.y = 0.5f * frameView.height;
        }
        public SchemeView(Scheme scheme, Style style)
        {
            FieldData data = scheme.GetFieldData();
            Font nameFont;
            float dvy = 0.0f;
            FieldDataView.Style dataStyle;

            if (style == Style.Small)
            {
                SetSize(153, 143);
                AddView(new RectView(0, 0, width, height, COLOR_BACK, Color.Black));
                nameFont = Helper.fontSystem;
                dvy = 13.0f;
                dataStyle.width = 127;
                dataStyle.height = 86;
                dataStyle.iw = 119;
                dataStyle.ih = 79;
            }
            else if (style == Style.Large)
            {
                SetSize(215, 176);
                nameFont = Helper.fontSystem;
                dataStyle.width = 215;
                dataStyle.height = 145;
                dataStyle.iw = 201;
                dataStyle.ih = 132;
            }
            else
            {
                throw new ArgumentException("Unknown style: " + style);
            }

            FieldDataView dataView = new FieldDataView(data, dataStyle);
            dataView.x = 0.5f * width;
            dataView.y = dvy;
            dataView.alignX = View.ALIGN_CENTER;
            AddView(dataView);

            TextView nameView = new TextView(nameFont, scheme.GetName(), (int)width);
            nameView.x = 0.5f * width;
            nameView.y = 0.5f * (height + (dataView.y + dataView.height));
            nameView.alignX = nameView.alignY = View.ALIGN_CENTER;
            AddView(nameView);
        }
        public GameResultScreen(Game game, ButtonDelegate buttonDelegate)
        {
            Font font = Helper.fontButton;
            TextView text = new TextView(font, "GAME ENDED");
            text.alignX = View.ALIGN_CENTER;
            text.alignY = View.ALIGN_CENTER;
            text.x = 0.5f * width;
            text.y = 0.5f * height;

            Button button = new TempButton("EXIT");
            button.alignX = View.ALIGN_CENTER;
            button.buttonDelegate = buttonDelegate;
            button.id = (int)ButtonId.Exit;
            button.x = 0.5f * width;
            button.y = text.y + 50;
            AddView(button);

            SetCancelButton(button);
        }
        public InputTypeView(int index, InputType inputType, Font font, float width, float height)
            : base(width, height)
        {
            this.index = index;
            this.inputType = inputType;

            focusable = true;

            View leftArrowView = new TextView(font, "<");
            AddView(leftArrowView);

            View rightArrowView = new TextView(font, ">");
            rightArrowView.x = width - rightArrowView.width;
            AddView(rightArrowView);

            typeView = new TextView(font, ToString(inputType));
            typeView.alignX = View.ALIGN_CENTER;
            typeView.x = 0.5f * width;
            AddView(typeView);
        }
        public NetworkConnectionScreen(String message = "Connecting...")
        {
            Font font = Helper.fontButton;

            statusTextView = new TextView(font, message);
            statusTextView.alignX = statusTextView.alignY = View.ALIGN_CENTER;
            statusTextView.x = 0.5f * width;
            statusTextView.y = 0.5f * height;

            AddView(statusTextView);

            Button cancelButton = new TempButton("Cancel");
            cancelButton.buttonDelegate = OnButtonPress;
            cancelButton.id = (int)ButtonId.Cancel;

            cancelButton.alignX = View.ALIGN_CENTER;
            cancelButton.x = 0.5f * width;
            cancelButton.y = statusTextView.y + 1.5f * statusTextView.height + 10;
            SetCancelButton(cancelButton);

            AddView(cancelButton);
        }
        public RoundResultScreen(Game game, ButtonDelegate buttonDelegate)
        {
            View contentView = new View(64, 48, 512, 384);

            // table
            View tableView = new View(0, 25, contentView.width, 330);

            float nameColWidth = 320;
            float winsColWidth = 0.5f * (tableView.width - nameColWidth);
            float suicidesColWidth = winsColWidth;

            Font font = Helper.fontButton;

            TextView textView = new TextView(font, "PLAYER");
            textView.alignX = View.ALIGN_CENTER;
            textView.x = 0.5f * nameColWidth;
            tableView.AddView(textView);

            textView = new TextView(font, "WINS");
            textView.alignX = View.ALIGN_CENTER;
            textView.x = nameColWidth + 0.5f * winsColWidth;
            tableView.AddView(textView);

            textView = new TextView(font, "SUICIDES");
            textView.alignX = View.ALIGN_CENTER;
            textView.x = nameColWidth + winsColWidth + 0.5f * suicidesColWidth;
            tableView.AddView(textView);

            List<Player> players = game.GetPlayersList();
            float px = 0.5f * nameColWidth;
            float py = textView.y + textView.height + 10;
            for (int i = 0; i < players.Count; ++i)
            {
                PlayerResultView pv = new PlayerResultView(players[i]);
                pv.alignX = View.ALIGN_CENTER;
                pv.x = px;
                pv.y = py;

                tableView.AddView(pv);

                py += pv.height + 10;
            }

            contentView.AddView(tableView);

            // buttons
            View buttons = new View(0.5f * contentView.width, contentView.height, 0, 0);
            buttons.alignX = View.ALIGN_CENTER;
            buttons.alignY = View.ALIGN_MAX;

            Button button = new TempButton("EXIT");
            button.id = (int)ButtonId.Exit;
            button.buttonDelegate = buttonDelegate;
            SetCancelButton(button);
            buttons.AddView(button);

            button = new TempButton("START!");
            button.id = (int)ButtonId.Continue; ;
            button.buttonDelegate = buttonDelegate;
            FocusView(button);

            SetConfirmButton(button);
            buttons.AddView(button);

            buttons.LayoutHor(20);
            buttons.ResizeToFitViews();
            contentView.AddView(buttons);

            AddView(contentView);
        }
        public ClientInfoView(String name, NetConnection connection)
        {
            Font font = Helper.fontButton;

            TextView textView = new TextView(font, connection.RemoteEndPoint + ": " + name);
            AddView(textView);

            ResizeToFitViews();
        }
 private TextView AddTextView()
 {
     TextView view = new TextView(Helper.fontSystem, null);
     AddView(view);
     return view;
 }
            public NetworkTraceView(NetConnection connection)
            {
                m_connection = connection;

                m_roundTripView = AddTextView();
                m_remoteTimeOffsetView = AddTextView();
                m_sentPacketsView = AddTextView();
                m_receivedPacketsView = AddTextView();
                m_sentBytesView = AddTextView();
                m_receivedBytesView = AddTextView();

                LayoutVer(0);
                ResizeToFitViews();
            }
 private TextView AddTextView(String text = null)
 {
     TextView view = new TextView(Helper.fontSystem, text);
     AddView(view);
     return view;
 }
            public LocalPlayerView(Player player)
            {
                m_player = player;

                m_packetDiffView = AddTextView();
                m_cordErrView = AddTextView("px: 0\npy: 0"); // HACK: need to adjust height
                LayoutVer(0);
                ResizeToFitViews();
            }
        public ListItem(Font font, String text, int width, int height)
            : base(width, height)
        {
            this.text = text;

            backView = new RectView(0, 0, width, height, Color.Black, Color.Black);
            backView.visible = false;
            AddView(backView);

            textView = new TextView(font, text);
            textView.alignX = View.ALIGN_CENTER;
            textView.x = 0.5f * width;
            AddView(textView);
        }
        public MultiplayerScreen(ButtonDelegate buttonDelegate)
        {
            this.buttonDelegate = buttonDelegate;

            Font font = Helper.fontButton;

            TextView headerText = new TextView(font, "LOCAL SERVERS");
            headerText.alignX = View.ALIGN_CENTER;
            headerText.x = 0.5f * width;
            headerText.y = 31;
            AddView(headerText);

            contentView = new View(467, 333);
            contentView.alignX = View.ALIGN_CENTER;
            contentView.x = 0.5f * width;
            contentView.y = 73;
            contentView.visible = false;
            AddView(contentView);

            busyView = new View(467, 333);
            busyView.alignX = View.ALIGN_CENTER;
            busyView.x = 0.5f * width;
            busyView.y = 73;

            TextView busyText = new TextView(font, "Searching for local servers...");
            busyText.alignX = busyText.alignY = View.ALIGN_CENTER;
            busyText.x = 0.5f * busyView.width;
            busyText.y = 0.5f * busyView.height;
            busyView.AddView(busyText);

            AddView(busyView);

            View buttonGroup = new View();

            Button button = new TempButton("BACK");
            button.buttonDelegate = buttonDelegate;
            button.id = (int)ButtonId.Back;
            buttonGroup.AddView(button);
            SetCancelButton(button);

            button = new TempButton("REFRESH");
            button.buttonDelegate = buttonDelegate;
            button.id = (int)ButtonId.Refresh;
            buttonGroup.AddView(button);

            button = new TempButton("CREATE");
            button.buttonDelegate = buttonDelegate;
            button.id = (int)ButtonId.Create;
            buttonGroup.AddView(button);

            buttonGroup.LayoutHor(10);
            buttonGroup.ResizeToFitViews();

            buttonGroup.alignX = View.ALIGN_CENTER;
            buttonGroup.alignY = View.ALIGN_MAX;

            buttonGroup.x = 0.5f * width;
            buttonGroup.y = 432;

            AddView(buttonGroup);
        }
        public ServerView(ServerInfo server)
            : base(154, 143)
        {
            Font font = Helper.fontButton;

            nameView = new TextView(font, server.name);
            nameView.alignX = View.ALIGN_CENTER;
            nameView.x = 0.5f * width;
            nameView.y = 104;
            AddView(nameView);
        }
        public void SetServers(List<ServerInfo> servers)
        {
            busyView.visible = false;
            contentView.visible = true;

            contentView.RemoveViews();

            if (servers.Count > 0)
            {
                for (int i = 0; i < servers.Count; ++i)
                {
                    ServerInfo serverInfo = servers[i];
                    ServerView view = new ServerView(serverInfo);
                    view.buttonDelegate = buttonDelegate;
                    view.id = (int)ButtonId.Join;
                    view.data = serverInfo;
                    contentView.AddView(view);
                }
            }
            else
            {
                Font font = Helper.fontButton;

                TextView text = new TextView(font, "No servers found.");
                text.alignX = text.alignY = View.ALIGN_CENTER;
                text.x = 0.5f * contentView.width;
                text.y = 0.5f * contentView.height;
                contentView.AddView(text);
            }
        }
            public NetworkControllerDebugView(GameControllerNetwork controller)
            {
                m_controller = controller;

                m_textView = new TextView(Helper.fontSystem, null);
                UpdateState();

                AddView(m_textView);
                ResizeToFitViews();

                height = 100;
            }
        public PlayerResultView(Player player)
        {
            m_player = player;

            Font font = Helper.fontButton;

            m_readyTextView = new TextView(font, "Not Ready");
            m_winsView = new TextView(font, "99");
            m_suicidesView = new TextView(font, "99");

            UpdateState();
            AddView(m_readyTextView);
            AddView(m_winsView);
            AddView(m_suicidesView);

            LayoutHor(10);
            ResizeToFitViews();
        }
        protected override void OnStart()
        {
            if (mode == Mode.Client)
            {
                RegisterNotification(NetworkNotifications.ConnectedToServer, ConnectedToServerNotification);
                StartDiscovery();
            }
            else if (mode == Mode.Server)
            {
                RegisterNotification(NetworkNotifications.ClientConnected, ClientConnectedNotification);
                RegisterNotification(NetworkNotifications.LocalClientDiscovered, LocalClientDiscoveredNotification);
                StartServer();
            }

            Screen screen = new Screen();
            Button button = new TempButton("Cancel");
            button.id = (int)ButtonId.Cancel;
            button.buttonDelegate = OnCancelButtonPressed;
            button.alignX = button.alignY = button.parentAlignX = button.parentAlignY = View.ALIGN_CENTER;
            screen.AddView(button);
            screen.SetCancelButton(button);

            Font font = Helper.fontSystem;
            TextView textView = new TextView(font, mode.ToString());
            textView.alignX = View.ALIGN_CENTER;
            textView.x = 0.5f * screen.width;
            textView.y = 10;
            screen.AddView(textView);

            StartScreen(screen);
        }