Implement NetStartWindow
# Conflicts: # src/p_setup.cpp
This commit is contained in:
parent
da83b546ad
commit
16e578a0f8
5 changed files with 182 additions and 6 deletions
|
|
@ -1,12 +1,118 @@
|
|||
|
||||
#include "netstartwindow.h"
|
||||
#include "version.h"
|
||||
#include <zwidget/core/timer.h>
|
||||
#include <zwidget/widgets/textlabel/textlabel.h>
|
||||
#include <zwidget/widgets/pushbutton/pushbutton.h>
|
||||
|
||||
NetStartWindow::NetStartWindow() : Widget(nullptr, WidgetType::Window)
|
||||
NetStartWindow* NetStartWindow::Instance = nullptr;
|
||||
|
||||
void NetStartWindow::ShowNetStartPane(const char* message, int maxpos)
|
||||
{
|
||||
HideNetStartPane();
|
||||
|
||||
Size screenSize = GetScreenSize();
|
||||
double windowWidth = 300.0;
|
||||
double windowHeight = 150.0;
|
||||
|
||||
Instance = new NetStartWindow(message, maxpos);
|
||||
Instance->SetFrameGeometry((screenSize.width - windowWidth) * 0.5, (screenSize.height - windowHeight) * 0.5, windowWidth, windowHeight);
|
||||
Instance->Show();
|
||||
}
|
||||
|
||||
void NetStartWindow::HideNetStartPane()
|
||||
{
|
||||
delete Instance;
|
||||
Instance = nullptr;
|
||||
}
|
||||
|
||||
void NetStartWindow::SetNetStartProgress(int pos)
|
||||
{
|
||||
if (Instance)
|
||||
Instance->SetProgress(pos);
|
||||
}
|
||||
|
||||
bool NetStartWindow::RunMessageLoop(bool (*newtimer_callback)(void*), void* newuserdata)
|
||||
{
|
||||
if (!Instance)
|
||||
return false;
|
||||
|
||||
Instance->timer_callback = newtimer_callback;
|
||||
Instance->userdata = newuserdata;
|
||||
|
||||
DisplayWindow::RunLoop();
|
||||
|
||||
Instance->timer_callback = nullptr;
|
||||
Instance->userdata = nullptr;
|
||||
|
||||
return Instance->exitreason;
|
||||
}
|
||||
|
||||
NetStartWindow::NetStartWindow(const std::string& message, int maxpos) : Widget(nullptr, WidgetType::Window)
|
||||
{
|
||||
SetWindowBackground(Colorf::fromRgba8(51, 51, 51));
|
||||
SetWindowBorderColor(Colorf::fromRgba8(51, 51, 51));
|
||||
SetWindowCaptionColor(Colorf::fromRgba8(33, 33, 33));
|
||||
SetWindowCaptionTextColor(Colorf::fromRgba8(226, 223, 219));
|
||||
SetWindowTitle(GAMENAME);
|
||||
|
||||
MessageLabel = new TextLabel(this);
|
||||
ProgressLabel = new TextLabel(this);
|
||||
AbortButton = new PushButton(this);
|
||||
|
||||
MessageLabel->SetTextAlignment(TextLabelAlignment::Center);
|
||||
ProgressLabel->SetTextAlignment(TextLabelAlignment::Center);
|
||||
|
||||
AbortButton->OnClick = [=]() { OnClose(); };
|
||||
|
||||
AbortButton->SetText("Abort Network Game");
|
||||
MessageLabel->SetText(message);
|
||||
|
||||
CallbackTimer = new Timer(this);
|
||||
CallbackTimer->FuncExpired = [=]() { OnCallbackTimerExpired(); };
|
||||
CallbackTimer->Start(500);
|
||||
}
|
||||
|
||||
void NetStartWindow::SetProgress(int newpos)
|
||||
{
|
||||
if (pos != newpos)
|
||||
{
|
||||
pos = newpos;
|
||||
FString message;
|
||||
message.Format("%d/%d", pos, maxpos);
|
||||
ProgressLabel->SetText(message.GetChars());
|
||||
}
|
||||
}
|
||||
|
||||
void NetStartWindow::OnClose()
|
||||
{
|
||||
exitreason = false;
|
||||
DisplayWindow::ExitLoop();
|
||||
}
|
||||
|
||||
void NetStartWindow::OnGeometryChanged()
|
||||
{
|
||||
double w = GetWidth();
|
||||
double h = GetHeight();
|
||||
|
||||
double y = 15.0;
|
||||
double labelheight = MessageLabel->GetPreferredHeight();
|
||||
MessageLabel->SetFrameGeometry(Rect::xywh(5.0, y, w - 10.0, labelheight));
|
||||
y += labelheight;
|
||||
|
||||
labelheight = ProgressLabel->GetPreferredHeight();
|
||||
ProgressLabel->SetFrameGeometry(Rect::xywh(5.0, y, w - 10.0, labelheight));
|
||||
y += labelheight;
|
||||
|
||||
y = GetHeight() - 15.0 - AbortButton->GetPreferredHeight();
|
||||
AbortButton->SetFrameGeometry((w - 200.0) * 0.5, y, 200.0, AbortButton->GetPreferredHeight());
|
||||
}
|
||||
|
||||
void NetStartWindow::OnCallbackTimerExpired()
|
||||
{
|
||||
if (timer_callback && timer_callback(userdata))
|
||||
{
|
||||
exitreason = true;
|
||||
DisplayWindow::ExitLoop();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue