Пример #1
0
        public void Initialize()
        {
            widgets.Clear();
            worldbuttons.Clear();
            menu.AddBackground(widgets);
            menu.AddCaption(this, "Select world");
            string[] w = new List<string>(game.GetWorlds()).ToArray();
            for (int i = 0; i < w.Length; i++)
            {
                if (string.IsNullOrEmpty(w[i]))
                {
                    w[i] = "Empty";
                }
            }
            for (int i = 0; i < 8; i++)
            {
                int ii = i;//closure
                var widget = new Widget()
                {
                    BackgroundImage = menu.button4,
                    BackgroundImageSelected = menu.button4sel,
                    Rect = new RectangleF(350 + (i % 2) * 500, 300 + (i / 2) * 150, 400, 128),
                    Text = w[i],
                    Click = delegate { selectedWorld = ii; },
                    selected = selectedWorld == i,
                };
                worldbuttons.Add(widget);
                widgets.Add(widget);
            }

            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(650, 900, 300, 90),//500
                Text = "Delete",
                Click = delegate
                {
                    string name = game.GetWorlds()[selectedWorld.Value];
                    if(!string.IsNullOrEmpty(name))
                    {
                        menu.MessageBoxYesNo(string.Format("Are you sure you want to delete world \"{0}\"?", name)
                            , delegate { game.DeleteWorld(selectedWorld.Value); Initialize(); }, delegate { });
                    }
                },
                FontSize = 20,
            });/*
            widgets.Add(new Widget()
            {
                BackgroundImage = "button4.png",
                BackgroundImageSelected = "button4_sel.png",
                Rect = new RectangleF(800, 900, 300, 90),
                Text = "Options",
                Click = delegate { },
                FontSize = 20,
            });*/

            menu.AddOkCancel(this, delegate { menu.afterSelectWorld(); }, delegate { menu.FormMainMenu(); });
        }
Пример #2
0
 public void Initialize()
 {
     widgets.Clear();
     menu.AddBackground(this.widgets);
     menu.AddCaption(this, "New world");
     /*
     widgets.Add(new Widget()
     {
         BackgroundImage = null,
         BackgroundImageSelected = null,
         Rect = new RectangleF(200, 200, 400, 90),
         Text = "World: " + (selectedWorld == null ? "none" : game.GetWorlds()[selectedWorld.Value]),
         Click = delegate { afterSelectWorld = FormStartMultiplayerServer; FormSelectWorld(); },
         FontSize = 20,
     });
     widgets.Add(new Widget()
     {
         BackgroundImage = "button4.png",
         BackgroundImageSelected = "button4_sel.png",
         Rect = new RectangleF(500, 200, 300, 90),
         Text = "Select",
         Click = delegate { afterSelectWorld = FormStartMultiplayerServer; FormSelectWorld(); },
         FontSize = 20,
     });
     */
     widgets.Add(new Widget()
     {
         BackgroundImage = null,
         BackgroundImageSelected = null,
         Rect = new RectangleF(200, 300, 400, 90),
         Text = "World name: ",
         Click = delegate { },
         FontSize = 20,
     });
     string name = game.GetWorlds()[worldId];
     if (string.IsNullOrEmpty(name))
     {
         name = "World " + (worldId + 1);
     }
     var nameTextbox = new Widget()
     {
         BackgroundImage = menu.button4,
         BackgroundImageSelected = menu.button4sel,
         Rect = new RectangleF(500, 300, 600, 90),
         Text = name,
         Click = delegate { }, //todo textbox
         FontSize = 20,
         IsTextbox = true,
     };
     widgets.Add(nameTextbox);
     menu.AddOkCancel(this, delegate { game.SetWorldOptions(worldId, nameTextbox.Text); menu.afterWorldOptions(); }, delegate { menu.currentForm = menu.d_FormSelectWorld; });
 }
Пример #3
0
        private void InitializeWidgets()
        {
            widgets.Clear();
            menu.AddBackground(widgets);
            int[] columnWidths = new int[] { 600, 130, 100, 250, 200};
            AddListboxRow(new[] { "Name", "Players", "Max", "Ip", "Version" }, 50, 290, columnWidths, -1, Color.White);
            if (servers != null && scrollbar != null)
            {
                for (int i = 0; i < serversPerScreen; i++)
                {
                    int serverid = scrollbar.ScrollbarValue * serversPerScreen + i;
                    if (serverid >= servers.Length)
                    {
                        break;
                    }
                    var s = servers[serverid];
                    AddListboxRow(new string[] { Trim(s.Name, 36), s.Users.ToString(), s.Max.ToString(), s.Ip, Trim(s.Version, 18) },
                        50, 350 + i * 100, columnWidths, serverid, Color.White);
                    AddListboxRow(new string[] { Trim(s.Players, 70) },
                        50, 350 + i * 100 + 50, columnWidths, serverid, Color.Gray);
                }
            }
            menu.AddCaption(this, "Multiplayer");
            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(1050, 50, 400, 128),
                Text = "Playing as: " + (game.IsLoggedIn ? game.LoginName : "~" + game.LoginName),
                Click = delegate { },
                selected = false,
                FontSize = 24,
            });
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(100, 150, 300, 128),
                Text = "Refresh",
                Click = delegate { serverlisterror = false; StartRefreshing(); },
                selected = false,
                FontSize = 24,
            });
            refreshingLabel = new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(400, 150, 300, 128),
                Text = "Refreshing...",
                Click = delegate { StartRefreshing(); },
                selected = false,
                FontSize = 24,
            };
            widgets.Add(refreshingLabel);
            serverListErrorWidget = new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(400, 150, 300, 128),
                Text = "Can't connect to server list.",
                Click = delegate { StartRefreshing(); },
                selected = false,
                FontSize = 24,
                Visible = serverlisterror,
                TextColor = Color.Red,
            };
            widgets.Add(serverListErrorWidget);
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(1100, 150, 300, 128),
                Text = "Login",
                Click = delegate { menu.FormLogin(); },
                selected = false,
                FontSize = 24,
            });
            if (servers != null)
            {
                int screensCount = (int)Math.Ceiling((float)servers.Length / serversPerScreen);

                //scrollbar
                if (scrollbar == null)
                {
                    scrollbar = new Widget()
                    {
                        //BackgroundImage = menu.button4,
                        //BackgroundImageSelected = menu.button4sel,
                        Rect = new RectangleF(1400, 350, 40, 600),
                        Click = delegate { },
                        selected = false,
                        IsScrollbar = true,

                    };
                }
                scrollbar.ScrollbarMax = screensCount - 1;
            }
            if (scrollbar != null)
            {
                widgets.Add(scrollbar);
            }

            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(200, 1000, 400, 128),
                Text = "Connect",
                //todo: hash should be enough
                Click = delegate { game.JoinMultiplayer(servers[selectedServer].Hash);
                },
            });
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(600, 1000, 400, 128),
                Text = "Connect to IP",
                Click = menu.FormConnectToIp,
            });

            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(1000, 1000, 400, 128),
                Text = "Cancel",
                Click = menu.FormMainMenu,
            });
        }
Пример #4
0
 private void AddListboxRow(string[] text, int x, int y, int[] columnwidths, int id, Color color)
 {
     serverlistitems.Clear();
     for (int i = 0; i < text.Length; i++)
     {
         int id2 = id; //closure
         var b = new Widget()
         {
             BackgroundImage = null,
             BackgroundImageSelected = null,
             Rect = new RectangleF(x, y, 400, 90),
             Text = text[i],
             Click = delegate { if (id2 != -1) { selectedServer = id2; } },
             selected = selectedServer == id,
             FontSize = 20,
             TextColor = color,
         };
         serverlistitems.Add(b);
         Widgets.Add(b);
         x += columnwidths[i];
     }
 }
Пример #5
0
        public void Initialize()
        {
            widgets.Clear();
            menu.AddBackground(widgets);
            menu.AddCaption(this, "Start server");
            selectedWorldWidget = new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 200, 400, 90),
                Text = "",//Render()
                Click = delegate { menu.FormSelectWorld(menu.FormStartServer); },
                FontSize = 20,
            };
            widgets.Add(selectedWorldWidget);
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(500, 200, 300, 90),
                Text = "Select",
                Click = delegate { menu.FormSelectWorld(delegate { menu.FormStartServer(); }); },
                FontSize = 20,
            });

            //Connection options
            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 300, 400, 90),
                Text = "Server name: ",
                Click = delegate { },
                FontSize = 20,
            });
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(500, 300, 600, 90),
                IsTextbox = true,
                FontSize = 20,
                Text = "My server",
            });
            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 400, 400, 90),
                Text = "Max players: ",
                Click = delegate { },
                FontSize = 20,
            });
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(500, 400, 600, 90),
                IsTextbox = true,
                IsNumeric = true,
                FontSize = 20,
                Text = "16",
            });
            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 500, 400, 90),
                Text = "Password: "******"Public: ",
                Click = delegate { },
                FontSize = 20,
            });
            publicWidget = new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(500, 600, 200, 90),
                Text = "",//Render()
                Click = delegate { serverpublic = !serverpublic; },
                FontSize = 20,
            };
            widgets.Add(publicWidget);

            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(1200, 200, 300, 90),
                Text = "Show my IP",
                Click = delegate { },
                FontSize = 20,
            });

            //Bottom buttons
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(200, 1000, 400, 128),
                Text = serverstarted ? "Stop" : "Start",
                //Click = delegate { serverstarted = !serverstarted; FormStartMultiplayerServer(); },
                Click = delegate { game.StartAndJoinLocalServer(menu.d_FormSelectWorld.selectedWorld.Value); }
            });
            //widgets.Add(new Button()
            //{
            //    BackgroundImage = "button4.png",
            //    BackgroundImageSelected = "button4_sel.png",
            //    Rect = new RectangleF(600, 1000, 400, 128),
            //    Text = "Play",
            //    Click = delegate { FormGame(); },
            //});
            widgets.Add(new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(1000, 1000, 400, 128),
                Text = "Cancel",
                Click = delegate { menu.FormMainMenu(); }
            });
        }
Пример #6
0
        public void Initialize()
        {
            widgets.Clear();
            menu.AddBackground(this.widgets);
            menu.AddCaption(this, "Connect to IP");

            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 300, 400, 90),
                Text = "Hash/Url: ",
                Click = delegate { },
                FontSize = 20,
            });
            hashTextboxWidget = new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(500, 300, 650, 90),
                Text = gethashurl(),
                Click = delegate { },
                FontSize = 20,
                IsTextbox = true,
            };

            widgets.Add(hashTextboxWidget);
            /*
            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 450, 400, 90),
                Text = "Or",
                Click = delegate { },
                FontSize = 20,
            });
            */
            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 600, 400, 90),
                Text = "IP: ",
                Click = delegate { },
                FontSize = 20,
            });
            ipTextboxWidget = new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(500, 600, 600, 90),
                Text = getip(),
                Click = delegate { },
                FontSize = 20,
                IsTextbox = true,
            };
            widgets.Add(ipTextboxWidget);
            widgets.Add(new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(200, 700, 400, 90),
                Text = "Port: ",
                Click = delegate { },
                FontSize = 20,
            });
            portTextboxWidget = new Widget()
            {
                BackgroundImage = menu.button4,
                BackgroundImageSelected = menu.button4sel,
                Rect = new RectangleF(500, 700, 600, 90),
                Text = getport(),
                Click = delegate { },
                FontSize = 20,
                IsTextbox = true,
                IsNumeric = true,
            };
            widgets.Add(portTextboxWidget);
            invalidHashWidget = new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(1200, 300, 400, 90),
                Text = "Invalid address.",
                Click = delegate { },
                FontSize = 20,
                TextColor = Color.Red,
            };
            widgets.Add(invalidHashWidget);
            invalidHostWidget = new Widget()
            {
                BackgroundImage = null,
                BackgroundImageSelected = null,
                Rect = new RectangleF(1200, 600, 400, 90),
                Text = "Invalid address.",
                Click = delegate { },
                FontSize = 20,
                TextColor = Color.Red,
            };
            widgets.Add(invalidHostWidget);

            menu.AddOkCancel(this, delegate { Connect(); }, delegate { menu.currentForm = menu.d_FormJoinMultiplayer; });
        }