mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-28 16:05:54 -04:00
Add broken server refresh button to launcher
This commit is contained in:
parent
8075786147
commit
ef20661429
@ -102,6 +102,7 @@ namespace Launcher.Gui.Screens {
|
|||||||
widgets[view.backIndex].OnClick =
|
widgets[view.backIndex].OnClick =
|
||||||
(x, y) => game.SetScreen(new MainScreen(game));
|
(x, y) => game.SetScreen(new MainScreen(game));
|
||||||
widgets[view.connectIndex].OnClick = ConnectToServer;
|
widgets[view.connectIndex].OnClick = ConnectToServer;
|
||||||
|
widgets[view.refreshIndex].OnClick = RefreshList;
|
||||||
|
|
||||||
TableWidget widget = (TableWidget)widgets[view.tableIndex];
|
TableWidget widget = (TableWidget)widgets[view.tableIndex];
|
||||||
widget.NeedRedraw = MarkPendingRedraw;
|
widget.NeedRedraw = MarkPendingRedraw;
|
||||||
@ -130,6 +131,16 @@ namespace Launcher.Gui.Screens {
|
|||||||
game.ConnectToServer(table.servers, Get(view.hashIndex));
|
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) {
|
protected override void MouseWheelChanged(object sender, MouseWheelEventArgs e) {
|
||||||
TableWidget table = (TableWidget)widgets[view.tableIndex];
|
TableWidget table = (TableWidget)widgets[view.tableIndex];
|
||||||
table.CurrentIndex -= e.Delta;
|
table.CurrentIndex -= e.Delta;
|
||||||
@ -167,9 +178,18 @@ namespace Launcher.Gui.Screens {
|
|||||||
view.RedrawTable();
|
view.RedrawTable();
|
||||||
game.Dirty = true;
|
game.Dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fetchingList) CheckFetchStatus();
|
||||||
pendingRedraw = false;
|
pendingRedraw = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckFetchStatus() {
|
||||||
|
if (!game.Session.Done) return;
|
||||||
|
|
||||||
|
view.RefreshText = "Refresh";
|
||||||
|
Resize();
|
||||||
|
}
|
||||||
|
|
||||||
void MarkPendingRedraw() {
|
void MarkPendingRedraw() {
|
||||||
TableWidget table = (TableWidget)widgets[view.tableIndex];
|
TableWidget table = (TableWidget)widgets[view.tableIndex];
|
||||||
table.ClampIndex();
|
table.ClampIndex();
|
||||||
|
@ -9,13 +9,14 @@ using OpenTK.Input;
|
|||||||
namespace Launcher.Gui.Views {
|
namespace Launcher.Gui.Views {
|
||||||
public sealed class ServersView : IView {
|
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;
|
internal int backIndex = 2, connectIndex = 3, tableIndex = 4;
|
||||||
Font tableFont;
|
Font tableFont;
|
||||||
const int tableX = 10, tableY = 50;
|
const int tableX = 10, tableY = 50;
|
||||||
|
public string RefreshText = "Refresh";
|
||||||
|
|
||||||
public ServersView(LauncherWindow game) : base(game) {
|
public ServersView(LauncherWindow game) : base(game) {
|
||||||
widgets = new Widget[5];
|
widgets = new Widget[6];
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
@ -35,16 +36,19 @@ namespace Launcher.Gui.Views {
|
|||||||
|
|
||||||
protected override void MakeWidgets() {
|
protected override void MakeWidgets() {
|
||||||
widgetIndex = 0;
|
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);
|
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 10, 10);
|
||||||
MakeInput(Get(1), 475, false, 32, "&gclassicube.net/server/play/...")
|
MakeInput(Get(1), 475, false, 32, "&gclassicube.net/server/play/...")
|
||||||
.SetLocation(Anchor.LeftOrTop, Anchor.BottomOrRight, 10, -10);
|
.SetLocation(Anchor.LeftOrTop, Anchor.BottomOrRight, 10, -10);
|
||||||
|
|
||||||
Makers.Button(this, "Back", 110, 30, titleFont)
|
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)
|
Makers.Button(this, "Connect", 110, 30, titleFont)
|
||||||
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -20, -10);
|
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -10);
|
||||||
|
|
||||||
MakeTableWidget();
|
MakeTableWidget();
|
||||||
|
Makers.Button(this, RefreshText, 110, 30, titleFont)
|
||||||
|
.SetLocation(Anchor.BottomOrRight, Anchor.LeftOrTop, -135, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
string Get(int index) {
|
string Get(int index) {
|
||||||
|
@ -31,6 +31,16 @@ namespace Launcher.Web {
|
|||||||
thread.Start(password);
|
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) {
|
void LoginWorker(object password) {
|
||||||
// Sign in to classicube.net
|
// Sign in to classicube.net
|
||||||
try {
|
try {
|
||||||
@ -52,6 +62,19 @@ namespace Launcher.Web {
|
|||||||
Finish(true, null, "&eSigned in");
|
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) {
|
void Login(string user, string password) {
|
||||||
Username = user;
|
Username = user;
|
||||||
// Step 1: GET csrf token from login page.
|
// Step 1: GET csrf token from login page.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user