ios: add flags in servers list

This commit is contained in:
UnknownShadow200 2022-04-13 23:27:35 +10:00
parent c891f8d656
commit cfaa57ade8
7 changed files with 44 additions and 17 deletions

View File

@ -553,6 +553,11 @@ void LBackend_TableReposition(struct LTable* w) {
LTable_ClampTopRow(w);
}
void LBackend_TableFlagAdded(struct LTable* w) {
/* TODO: Only redraw flags */
LWidget_Draw(w);
}
/* Draws background behind column headers */
static void LTable_DrawHeaderBackground(struct LTable* w) {
BitmapCol gridColor = BitmapCol_Make(20, 20, 10, 255);

View File

@ -48,8 +48,9 @@ void LBackend_SliderDraw(struct LSlider* w);
void LBackend_TableInit(struct LTable* w);
void LBackend_TableUpdate(struct LTable* w);
void LBackend_TableDraw(struct LTable* w);
void LBackend_TableReposition(struct LTable* w);
void LBackend_TableFlagAdded(struct LTable* w);
void LBackend_TableDraw(struct LTable* w);
void LBackend_TableMouseDown(struct LTable* w, int idx);
void LBackend_TableMouseUp(struct LTable* w, int idx);

View File

@ -1401,8 +1401,7 @@ static void ServersScreen_Tick(struct LScreen* s_) {
count = FetchFlagsTask.count;
LWebTask_Tick(&FetchFlagsTask.Base);
/* TODO: Only redraw flags */
if (count != FetchFlagsTask.count) LWidget_Draw(&s->table);
if (count != FetchFlagsTask.count) LBackend_TableFlagAdded(&s->table);
if (!FetchServersTask.Base.working) return;
LWebTask_Tick(&FetchServersTask.Base);

View File

@ -569,10 +569,6 @@ void FetchUpdateTask_Run(cc_bool release, int buildIndex) {
struct FetchFlagsData FetchFlagsTask;
static int flagsCount, flagsCapacity;
struct Flag {
struct Bitmap bmp;
char country[2];
};
static struct Flag* flags;
/* Scales up flag bitmap if necessary */
@ -595,14 +591,16 @@ static void FetchFlagsTask_Scale(struct Bitmap* bmp) {
static void FetchFlagsTask_DownloadNext(void);
static void FetchFlagsTask_Handle(cc_uint8* data, cc_uint32 len) {
struct Flag* flag = &flags[FetchFlagsTask.count];
struct Stream s;
cc_result res;
Stream_ReadonlyMemory(&s, data, len);
res = Png_Decode(&flags[FetchFlagsTask.count].bmp, &s);
res = Png_Decode(&flag->bmp, &s);
if (res) Logger_SysWarn(res, "decoding flag");
flag->meta = NULL;
FetchFlagsTask_Scale(&flags[FetchFlagsTask.count].bmp);
FetchFlagsTask_Scale(&flag->bmp);
FetchFlagsTask.count++;
FetchFlagsTask_DownloadNext();
}
@ -651,12 +649,12 @@ void FetchFlagsTask_Add(const struct ServerInfo* server) {
FetchFlagsTask_DownloadNext();
}
struct Bitmap* Flags_Get(const struct ServerInfo* server) {
struct Flag* Flags_Get(const struct ServerInfo* server) {
int i;
for (i = 0; i < FetchFlagsTask.count; i++) {
if (flags[i].country[0] != server->country[0]) continue;
if (flags[i].country[1] != server->country[1]) continue;
return &flags[i].bmp;
return &flags[i];
}
return NULL;
}

View File

@ -1,6 +1,7 @@
#ifndef CC_LWEB_H
#define CC_LWEB_H
#include "Http.h"
#include "Bitmap.h"
/* Implements asynchronous web tasks for the launcher.
Copyright 2014-2021 ClassiCube | Licensed under BSD-3
*/
@ -41,6 +42,13 @@ struct ServerInfo {
char _softBuffer[STRING_SIZE];
};
/* Represents a country flag */
struct Flag {
struct Bitmap bmp;
char country[2]; /* ISO 3166-1 alpha-2 */
void* meta; /* Backend specific meta */
};
struct LWebTask {
cc_bool completed; /* Whether the task has finished executing. */
cc_bool working; /* Whether the task is currently in progress, or is scheduled to be. */
@ -115,10 +123,11 @@ extern struct FetchFlagsData {
/* Number of flags downloaded. */
int count;
} FetchFlagsTask;
/* Asynchronously downloads the flag associated with the given server's country. */
void FetchFlagsTask_Add(const struct ServerInfo* server);
/* Gets the bitmap for the flag associated with the given server's country. */
struct Bitmap* Flags_Get(const struct ServerInfo* server);
/* Gets the country flag associated with the given server's country. */
struct Flag* Flags_Get(const struct ServerInfo* server);
/* Frees all flag bitmaps. */
void Flags_Free(void);

View File

@ -467,9 +467,9 @@ void LSlider_SetProgress(struct LSlider* w, int progress) {
*------------------------------------------------------TableWidget--------------------------------------------------------*
*#########################################################################################################################*/
static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell) {
struct Bitmap* bmp = Flags_Get(row);
if (!bmp) return;
Drawer2D_BmpCopy(&Launcher_Framebuffer, cell->x + flagXOffset, cell->y + flagYOffset, bmp);
struct Flag* flag = Flags_Get(row);
if (!flag) return;
Drawer2D_BmpCopy(&Launcher_Framebuffer, cell->x + flagXOffset, cell->y + flagYOffset, &flag->bmp);
}
static void NameColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell) {

View File

@ -655,12 +655,21 @@ static NSString* cellID = @"CC_Cell";
}
struct ServerInfo* server = Servers_Get([indexPath row]);
struct Flag* flag = Flags_Get(server);
char descBuffer[128];
cc_string desc = String_FromArray(descBuffer);
String_Format2(&desc, "%i/%i players, up for ", &server->players, &server->maxPlayers);
LTable_FormatUptime(&desc, server->uptime);
cell.textLabel.text = ToNSString(&server->name);
if (flag && !flag->meta && flag->bmp.scan0) {
UIImage* img = ToUIImage(&flag->bmp);
flag->meta = CFBridgingRetain(img);
}
if (flag && flag->meta)
cell.imageView.image = (__bridge UIImage*)flag->meta;
cell.textLabel.text = ToNSString(&server->name);
cell.detailTextLabel.text = ToNSString(&desc);//[ToNSString(&desc) stringByAppendingString:@"\nLine2"];
return cell;
}
@ -855,6 +864,12 @@ void LBackend_TableUpdate(struct LTable* w) {
[tbl reloadData];
}
// TODO only redraw flags
void LBackend_TableFlagAdded(struct LTable* w) {
UITableView* tbl = (__bridge UITableView*)w->meta;
[tbl reloadData];
}
void LBackend_TableDraw(struct LTable* w) { }
void LBackend_TableReposition(struct LTable* w) { }