mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Launcher: Split up ResourcesScreen into CheckResourcesScreen and FetchResourcesScreen
This commit is contained in:
parent
7af1a2b7c4
commit
251d531fb2
183
src/LScreens.c
183
src/LScreens.c
@ -981,34 +981,17 @@ void MainScreen_SetActive(void) {
|
|||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------ResourcesScreen---------------------------------------------------*
|
*----------------------------------------------------CheckResourcesScreen-------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static struct ResourcesScreen {
|
static struct CheckResourcesScreen {
|
||||||
LScreen_Layout
|
LScreen_Layout
|
||||||
struct LLabel lblLine1, lblLine2, lblStatus;
|
struct LLabel lblLine1, lblLine2, lblStatus;
|
||||||
struct LButton btnYes, btnNo, btnCancel;
|
struct LButton btnYes, btnNo;
|
||||||
struct LSlider sdrProgress;
|
struct LWidget* _widgets[5];
|
||||||
int statusYOffset; /* gets changed when downloading resources */
|
} CheckResourcesScreen_Instance;
|
||||||
struct LWidget* _widgets[7];
|
|
||||||
} ResourcesScreen_Instance;
|
|
||||||
|
|
||||||
static void ResourcesScreen_Download(void* w, int x, int y) {
|
static void CheckResourcesScreen_Yes(void* w, int x, int y) { FetchResourcesScreen_SetActive(); }
|
||||||
struct ResourcesScreen* s = &ResourcesScreen_Instance;
|
static void CheckResourcesScreen_Next(void* w, int x, int y) {
|
||||||
if (Fetcher_Working) return;
|
|
||||||
|
|
||||||
Fetcher_Run();
|
|
||||||
s->selectedWidget = NULL;
|
|
||||||
|
|
||||||
s->btnYes.hidden = true;
|
|
||||||
s->btnNo.hidden = true;
|
|
||||||
s->lblLine1.hidden = true;
|
|
||||||
s->lblLine2.hidden = true;
|
|
||||||
s->btnCancel.hidden = false;
|
|
||||||
s->sdrProgress.hidden = false;
|
|
||||||
s->Draw((struct LScreen*)s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ResourcesScreen_Next(void* w, int x, int y) {
|
|
||||||
static const cc_string optionsTxt = String_FromConst("options.txt");
|
static const cc_string optionsTxt = String_FromConst("options.txt");
|
||||||
Http_ClearPending();
|
Http_ClearPending();
|
||||||
|
|
||||||
@ -1019,98 +1002,121 @@ static void ResourcesScreen_Next(void* w, int x, int y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_Init(struct LScreen* s_) {
|
static void CheckResourcesScreen_Init(struct LScreen* s_) {
|
||||||
cc_string str; char buffer[STRING_SIZE];
|
cc_string str; char buffer[STRING_SIZE];
|
||||||
BitmapCol progressCol = BitmapCol_Make(0, 220, 0, 255);
|
struct CheckResourcesScreen* s = (struct CheckResourcesScreen*)s_;
|
||||||
struct ResourcesScreen* s = (struct ResourcesScreen*)s_;
|
|
||||||
float size;
|
float size;
|
||||||
|
|
||||||
s->statusYOffset = 10;
|
|
||||||
s->widgets = s->_widgets;
|
s->widgets = s->_widgets;
|
||||||
|
|
||||||
LLabel_Init(s_, &s->lblLine1, "Some required resources weren't found");
|
LLabel_Init(s_, &s->lblLine1, "Some required resources weren't found");
|
||||||
LLabel_Init(s_, &s->lblLine2, "Okay to download?");
|
LLabel_Init(s_, &s->lblLine2, "Okay to download?");
|
||||||
LLabel_Init(s_, &s->lblStatus, "");
|
|
||||||
|
|
||||||
LButton_Init(s_, &s->btnYes, 70, 35, "Yes");
|
|
||||||
LButton_Init(s_, &s->btnNo, 70, 35, "No");
|
|
||||||
|
|
||||||
LButton_Init(s_, &s->btnCancel, 120, 35, "Cancel");
|
|
||||||
LSlider_Init(s_, &s->sdrProgress, 200, 12, progressCol);
|
|
||||||
|
|
||||||
s->btnCancel.hidden = true;
|
|
||||||
s->sdrProgress.hidden = true;
|
|
||||||
|
|
||||||
/* TODO: Size 13 italic font?? does it matter?? */
|
|
||||||
String_InitArray(str, buffer);
|
String_InitArray(str, buffer);
|
||||||
size = Resources_Size / 1024.0f;
|
size = Resources_Size / 1024.0f;
|
||||||
|
|
||||||
s->lblStatus.font = &Launcher_HintFont;
|
LLabel_Init(s_, &s->lblStatus, "");
|
||||||
String_Format1(&str, "&eDownload size: %f2 megabytes", &size);
|
String_Format1(&str, "&eDownload size: %f2 megabytes", &size);
|
||||||
|
s->lblStatus.font = &Launcher_HintFont;
|
||||||
LLabel_SetText( &s->lblStatus, &str);
|
LLabel_SetText( &s->lblStatus, &str);
|
||||||
|
|
||||||
s->btnYes.OnClick = ResourcesScreen_Download;
|
LButton_Init(s_, &s->btnYes, 70, 35, "Yes");
|
||||||
s->btnNo.OnClick = ResourcesScreen_Next;
|
LButton_Init(s_, &s->btnNo, 70, 35, "No");
|
||||||
s->btnCancel.OnClick = ResourcesScreen_Next;
|
s->btnYes.OnClick = CheckResourcesScreen_Yes;
|
||||||
|
s->btnNo.OnClick = CheckResourcesScreen_Next;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_Show(struct LScreen* s_) {
|
static void CheckResourcesScreen_Layout(struct LScreen* s_) {
|
||||||
struct ResourcesScreen* s = (struct ResourcesScreen*)s_;
|
struct CheckResourcesScreen* s = (struct CheckResourcesScreen*)s_;
|
||||||
s->statusYOffset = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ResourcesScreen_Layout(struct LScreen* s_) {
|
|
||||||
struct ResourcesScreen* s = (struct ResourcesScreen*)s_;
|
|
||||||
|
|
||||||
LWidget_SetLocation(&s->lblLine1, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -50);
|
LWidget_SetLocation(&s->lblLine1, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -50);
|
||||||
LWidget_SetLocation(&s->lblLine2, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -30);
|
LWidget_SetLocation(&s->lblLine2, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -30);
|
||||||
LWidget_SetLocation(&s->lblStatus, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, s->statusYOffset);
|
LWidget_SetLocation(&s->lblStatus, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 10);
|
||||||
|
|
||||||
LWidget_SetLocation(&s->btnYes, ANCHOR_CENTRE, ANCHOR_CENTRE, -70, 45);
|
LWidget_SetLocation(&s->btnYes, ANCHOR_CENTRE, ANCHOR_CENTRE, -70, 45);
|
||||||
LWidget_SetLocation(&s->btnNo, ANCHOR_CENTRE, ANCHOR_CENTRE, 70, 45);
|
LWidget_SetLocation(&s->btnNo, ANCHOR_CENTRE, ANCHOR_CENTRE, 70, 45);
|
||||||
|
|
||||||
LWidget_SetLocation(&s->btnCancel, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 45);
|
|
||||||
LWidget_SetLocation(&s->sdrProgress, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CC_NOINLINE static void ResourcesScreen_ResetArea(int x, int y, int width, int height) {
|
CC_NOINLINE static void CheckResourcesScreen_ResetArea(int x, int y, int width, int height) {
|
||||||
BitmapCol boxCol = BitmapCol_Make(120, 85, 151, 255);
|
BitmapCol boxCol = BitmapCol_Make(120, 85, 151, 255);
|
||||||
Gradient_Noise(&Launcher_Framebuffer, boxCol, 4, x, y, width, height);
|
Gradient_Noise(&Launcher_Framebuffer, boxCol, 4, x, y, width, height);
|
||||||
Launcher_MarkDirty(x, y, width, height);
|
Launcher_MarkDirty(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_Draw(struct LScreen* s) {
|
CC_NOINLINE static void CheckResourcesScreen_DrawBase(void) {
|
||||||
BitmapCol backCol = BitmapCol_Make(12, 12, 12, 255);
|
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
|
Drawer2D_Clear(&Launcher_Framebuffer, BitmapCol_Make(12, 12, 12, 255),
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, backCol,
|
|
||||||
0, 0, WindowInfo.Width, WindowInfo.Height);
|
0, 0, WindowInfo.Width, WindowInfo.Height);
|
||||||
width = Display_ScaleX(380);
|
width = Display_ScaleX(380);
|
||||||
height = Display_ScaleY(140);
|
height = Display_ScaleY(140);
|
||||||
|
|
||||||
x = Gui_CalcPos(ANCHOR_CENTRE, 0, width, WindowInfo.Width);
|
x = Gui_CalcPos(ANCHOR_CENTRE, 0, width, WindowInfo.Width);
|
||||||
y = Gui_CalcPos(ANCHOR_CENTRE, 0, height, WindowInfo.Height);
|
y = Gui_CalcPos(ANCHOR_CENTRE, 0, height, WindowInfo.Height);
|
||||||
|
CheckResourcesScreen_ResetArea(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
ResourcesScreen_ResetArea(x, y, width, height);
|
static void CheckResourcesScreen_Draw(struct LScreen* s) {
|
||||||
|
CheckResourcesScreen_DrawBase();
|
||||||
LScreen_Draw(s);
|
LScreen_Draw(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_SetStatus(const cc_string* str) {
|
void CheckResourcesScreen_SetActive(void) {
|
||||||
struct LLabel* w = &ResourcesScreen_Instance.lblStatus;
|
struct CheckResourcesScreen* s = &CheckResourcesScreen_Instance;
|
||||||
ResourcesScreen_ResetArea(w->last.X, w->last.Y,
|
LScreen_Reset((struct LScreen*)s);
|
||||||
|
s->Init = CheckResourcesScreen_Init;
|
||||||
|
s->Draw = CheckResourcesScreen_Draw;
|
||||||
|
s->Layout = CheckResourcesScreen_Layout;
|
||||||
|
s->onEnterWidget = (struct LWidget*)&s->btnYes;
|
||||||
|
Launcher_SetScreen((struct LScreen*)s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*----------------------------------------------------FetchResourcesScreen-------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
static struct FetchResourcesScreen {
|
||||||
|
LScreen_Layout
|
||||||
|
struct LLabel lblStatus;
|
||||||
|
struct LButton btnCancel;
|
||||||
|
struct LSlider sdrProgress;
|
||||||
|
struct LWidget* _widgets[3];
|
||||||
|
} FetchResourcesScreen_Instance;
|
||||||
|
|
||||||
|
static void FetchResourcesScreen_Init(struct LScreen* s_) {
|
||||||
|
struct FetchResourcesScreen* s = (struct FetchResourcesScreen*)s_;
|
||||||
|
s->widgets = s->_widgets;
|
||||||
|
|
||||||
|
LLabel_Init(s_, &s->lblStatus, "");
|
||||||
|
LButton_Init(s_, &s->btnCancel, 120, 35, "Cancel");
|
||||||
|
LSlider_Init(s_, &s->sdrProgress, 200, 12, BitmapCol_Make(0, 220, 0, 255));
|
||||||
|
|
||||||
|
s->lblStatus.font = &Launcher_HintFont;
|
||||||
|
s->btnCancel.OnClick = CheckResourcesScreen_Next;
|
||||||
|
}
|
||||||
|
static void FetchResourcesScreen_Show(struct LScreen* s_) { if (!Fetcher_Working) Fetcher_Run(); }
|
||||||
|
|
||||||
|
static void FetchResourcesScreen_Layout(struct LScreen* s_) {
|
||||||
|
struct FetchResourcesScreen* s = (struct FetchResourcesScreen*)s_;
|
||||||
|
LWidget_SetLocation(&s->lblStatus, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -10);
|
||||||
|
LWidget_SetLocation(&s->btnCancel, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 45);
|
||||||
|
LWidget_SetLocation(&s->sdrProgress, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FetchResourcesScreen_Draw(struct LScreen* s) {
|
||||||
|
CheckResourcesScreen_DrawBase();
|
||||||
|
LScreen_Draw(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FetchResourcesScreen_SetStatus(const cc_string* str) {
|
||||||
|
struct LLabel* w = &FetchResourcesScreen_Instance.lblStatus;
|
||||||
|
CheckResourcesScreen_ResetArea(w->last.X, w->last.Y,
|
||||||
w->last.Width, w->last.Height);
|
w->last.Width, w->last.Height);
|
||||||
LLabel_SetText(w, str);
|
LLabel_SetText(w, str);
|
||||||
|
|
||||||
w->yOffset = -10;
|
|
||||||
ResourcesScreen_Instance.statusYOffset = w->yOffset;
|
|
||||||
LWidget_CalcPosition(w);
|
|
||||||
LWidget_Draw(w);
|
LWidget_Draw(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_UpdateStatus(int reqID) {
|
static void FetchResourcesScreen_UpdateStatus(int reqID) {
|
||||||
cc_string str; char strBuffer[STRING_SIZE];
|
cc_string str; char strBuffer[STRING_SIZE];
|
||||||
const char* name;
|
const char* name;
|
||||||
struct LLabel* w = &ResourcesScreen_Instance.lblStatus;
|
struct LLabel* w = &FetchResourcesScreen_Instance.lblStatus;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
name = Fetcher_RequestName(reqID);
|
name = Fetcher_RequestName(reqID);
|
||||||
@ -1121,14 +1127,14 @@ static void ResourcesScreen_UpdateStatus(int reqID) {
|
|||||||
String_Format3(&str, "&eFetching %c.. (%i/%i)", name, &count, &Resources_Count);
|
String_Format3(&str, "&eFetching %c.. (%i/%i)", name, &count, &Resources_Count);
|
||||||
|
|
||||||
if (String_Equals(&str, &w->text)) return;
|
if (String_Equals(&str, &w->text)) return;
|
||||||
ResourcesScreen_SetStatus(&str);
|
FetchResourcesScreen_SetStatus(&str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_UpdateProgress(struct ResourcesScreen* s) {
|
static void FetchResourcesScreen_UpdateProgress(struct FetchResourcesScreen* s) {
|
||||||
int reqID, progress;
|
int reqID, progress;
|
||||||
|
|
||||||
if (!Http_GetCurrent(&reqID, &progress)) return;
|
if (!Http_GetCurrent(&reqID, &progress)) return;
|
||||||
ResourcesScreen_UpdateStatus(reqID);
|
FetchResourcesScreen_UpdateStatus(reqID);
|
||||||
/* making request still, haven't started download yet */
|
/* making request still, haven't started download yet */
|
||||||
if (progress < 0 || progress > 100) return;
|
if (progress < 0 || progress > 100) return;
|
||||||
|
|
||||||
@ -1137,37 +1143,36 @@ static void ResourcesScreen_UpdateProgress(struct ResourcesScreen* s) {
|
|||||||
LWidget_Draw(&s->sdrProgress);
|
LWidget_Draw(&s->sdrProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_Error(struct ResourcesScreen* s) {
|
static void FetchResourcesScreen_Error(struct FetchResourcesScreen* s) {
|
||||||
cc_string str; char buffer[STRING_SIZE];
|
cc_string str; char buffer[STRING_SIZE];
|
||||||
String_InitArray(str, buffer);
|
String_InitArray(str, buffer);
|
||||||
|
|
||||||
Launcher_DisplayHttpError(Fetcher_Result, Fetcher_StatusCode, "downloading resources", &str);
|
Launcher_DisplayHttpError(Fetcher_Result, Fetcher_StatusCode, "downloading resources", &str);
|
||||||
ResourcesScreen_SetStatus(&str);
|
FetchResourcesScreen_SetStatus(&str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResourcesScreen_Tick(struct LScreen* s_) {
|
static void FetchResourcesScreen_Tick(struct LScreen* s_) {
|
||||||
struct ResourcesScreen* s = (struct ResourcesScreen*)s_;
|
struct FetchResourcesScreen* s = (struct FetchResourcesScreen*)s_;
|
||||||
if (!Fetcher_Working) return;
|
if (!Fetcher_Working) return;
|
||||||
|
|
||||||
ResourcesScreen_UpdateProgress(s);
|
FetchResourcesScreen_UpdateProgress(s);
|
||||||
Fetcher_Update();
|
Fetcher_Update();
|
||||||
|
|
||||||
if (!Fetcher_Completed) return;
|
if (!Fetcher_Completed) return;
|
||||||
if (Fetcher_Failed) { ResourcesScreen_Error(s); return; }
|
if (Fetcher_Failed) { FetchResourcesScreen_Error(s); return; }
|
||||||
|
|
||||||
Launcher_TryLoadTexturePack();
|
Launcher_TryLoadTexturePack();
|
||||||
ResourcesScreen_Next(NULL, 0, 0);
|
CheckResourcesScreen_Next(NULL, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcesScreen_SetActive(void) {
|
void FetchResourcesScreen_SetActive(void) {
|
||||||
struct ResourcesScreen* s = &ResourcesScreen_Instance;
|
struct FetchResourcesScreen* s = &FetchResourcesScreen_Instance;
|
||||||
LScreen_Reset((struct LScreen*)s);
|
LScreen_Reset((struct LScreen*)s);
|
||||||
s->Init = ResourcesScreen_Init;
|
s->Init = FetchResourcesScreen_Init;
|
||||||
s->Show = ResourcesScreen_Show;
|
s->Show = FetchResourcesScreen_Show;
|
||||||
s->Draw = ResourcesScreen_Draw;
|
s->Draw = FetchResourcesScreen_Draw;
|
||||||
s->Tick = ResourcesScreen_Tick;
|
s->Tick = FetchResourcesScreen_Tick;
|
||||||
s->Layout = ResourcesScreen_Layout;
|
s->Layout = FetchResourcesScreen_Layout;
|
||||||
s->onEnterWidget = (struct LWidget*)&s->btnYes;
|
|
||||||
Launcher_SetScreen((struct LScreen*)s);
|
Launcher_SetScreen((struct LScreen*)s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ void ColoursScreen_SetActive(void);
|
|||||||
void DirectConnectScreen_SetActive(void);
|
void DirectConnectScreen_SetActive(void);
|
||||||
void MFAScreen_SetActive(void);
|
void MFAScreen_SetActive(void);
|
||||||
void MainScreen_SetActive(void);
|
void MainScreen_SetActive(void);
|
||||||
void ResourcesScreen_SetActive(void);
|
void CheckResourcesScreen_SetActive(void);
|
||||||
|
void FetchResourcesScreen_SetActive(void);
|
||||||
void ServersScreen_SetActive(void);
|
void ServersScreen_SetActive(void);
|
||||||
void SettingsScreen_SetActive(void);
|
void SettingsScreen_SetActive(void);
|
||||||
void UpdatesScreen_SetActive(void);
|
void UpdatesScreen_SetActive(void);
|
||||||
|
@ -297,7 +297,7 @@ void Launcher_Run(void) {
|
|||||||
CheckUpdateTask_Run();
|
CheckUpdateTask_Run();
|
||||||
|
|
||||||
if (Resources_Count) {
|
if (Resources_Count) {
|
||||||
ResourcesScreen_SetActive();
|
CheckResourcesScreen_SetActive();
|
||||||
} else {
|
} else {
|
||||||
MainScreen_SetActive();
|
MainScreen_SetActive();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user