Add broken server refresh button to launcher

This commit is contained in:
UnknownShadow200 2017-04-29 23:30:40 +10:00
parent 8075786147
commit ef20661429
3 changed files with 53 additions and 6 deletions

View File

@ -102,6 +102,7 @@ namespace Launcher.Gui.Screens {
widgets[view.backIndex].OnClick =
(x, y) => game.SetScreen(new MainScreen(game));
widgets[view.connectIndex].OnClick = ConnectToServer;
widgets[view.refreshIndex].OnClick = RefreshList;
TableWidget widget = (TableWidget)widgets[view.tableIndex];
widget.NeedRedraw = MarkPendingRedraw;
@ -130,6 +131,16 @@ namespace Launcher.Gui.Screens {
game.ConnectToServer(table.servers, Get(view.hashIndex));
}
bool fetchingList = false;
void RefreshList(int mouseX, int mouseY) {
if (fetchingList) return;
fetchingList = true;
game.Session.FetchServersAsync();
view.RefreshText = "&eWorking..";
Resize();
}
protected override void MouseWheelChanged(object sender, MouseWheelEventArgs e) {
TableWidget table = (TableWidget)widgets[view.tableIndex];
table.CurrentIndex -= e.Delta;
@ -167,9 +178,18 @@ namespace Launcher.Gui.Screens {
view.RedrawTable();
game.Dirty = true;
}
if (fetchingList) CheckFetchStatus();
pendingRedraw = false;
}
void CheckFetchStatus() {
if (!game.Session.Done) return;
view.RefreshText = "Refresh";
Resize();
}
void MarkPendingRedraw() {
TableWidget table = (TableWidget)widgets[view.tableIndex];
table.ClampIndex();

View File

@ -9,13 +9,14 @@ using OpenTK.Input;
namespace Launcher.Gui.Views {
public sealed class ServersView : IView {
internal int searchIndex = 0, hashIndex = 1;
internal int searchIndex = 0, hashIndex = 1, refreshIndex = 5;
internal int backIndex = 2, connectIndex = 3, tableIndex = 4;
Font tableFont;
const int tableX = 10, tableY = 50;
public string RefreshText = "Refresh";
public ServersView(LauncherWindow game) : base(game) {
widgets = new Widget[5];
widgets = new Widget[6];
}
public override void Init() {
@ -35,16 +36,19 @@ namespace Launcher.Gui.Views {
protected override void MakeWidgets() {
widgetIndex = 0;
MakeInput(Get(0), 475, false, 32, "&gSearch servers..")
MakeInput(Get(0), 370, false, 32, "&gSearch servers..")
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 10, 10);
MakeInput(Get(1), 475, false, 32, "&gclassicube.net/server/play/...")
.SetLocation(Anchor.LeftOrTop, Anchor.BottomOrRight, 10, -10);
Makers.Button(this, "Back", 110, 30, titleFont)
.SetLocation(Anchor.BottomOrRight, Anchor.LeftOrTop, -20, 10);
.SetLocation(Anchor.BottomOrRight, Anchor.LeftOrTop, -10, 10);
Makers.Button(this, "Connect", 110, 30, titleFont)
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -20, -10);
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -10);
MakeTableWidget();
Makers.Button(this, RefreshText, 110, 30, titleFont)
.SetLocation(Anchor.BottomOrRight, Anchor.LeftOrTop, -135, 10);
}
string Get(int index) {

View File

@ -31,6 +31,16 @@ namespace Launcher.Web {
thread.Start(password);
}
public void FetchServersAsync() {
Working = true;
Done = false;
Exception = null;
Thread thread = new Thread(FetchServersWorker, 256 * 1024);
thread.Name = "Launcher.CCFetchAsync";
thread.Start();
}
void LoginWorker(object password) {
// Sign in to classicube.net
try {
@ -52,6 +62,19 @@ namespace Launcher.Web {
Finish(true, null, "&eSigned in");
}
void FetchServersWorker() {
// Retrieve list of public servers
Status = "&eRetrieving public servers list..";
try {
Servers = GetPublicServers();
} catch (WebException ex) {
Servers = new List<ServerListEntry>();
Finish(false, ex, "retrieving servers list"); return;
}
Finish(true, null, "&eFetched list");
}
void Login(string user, string password) {
Username = user;
// Step 1: GET csrf token from login page.