From 8c6375b462e7b99fe799b13b2c787463d243755a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 14 Apr 2022 23:44:14 +1000 Subject: [PATCH] ios: support joining servers through list by clicking, fix status text not disappearing after leaving main menu --- src/LBackend.c | 13 +------------ src/LScreens.c | 2 +- src/LWidgets.c | 14 ++++++++++++++ src/LWidgets.h | 1 + src/TexturePack.c | 22 +++++++--------------- src/interop_ios.m | 13 ++++++++++++- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/LBackend.c b/src/LBackend.c index 68fa43ffc..020b69bac 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -730,18 +730,7 @@ void LBackend_TableDraw(struct LTable* w) { static void LTable_RowsClick(struct LTable* w, int idx) { int mouseY = Pointers[idx].y - w->rowsBegY; int row = w->topRow + mouseY / w->rowHeight; - cc_uint64 now; - - LTable_SetSelectedTo(w, row); - now = Stopwatch_Measure(); - - /* double click on row to join */ - if (Stopwatch_ElapsedMS(w->_lastClick, now) < 1000 && row == w->_lastRow) { - Launcher_ConnectToServer(<able_Get(row)->hash); - } - - w->_lastRow = LTable_GetSelectedIndex(w); - w->_lastClick = now; + LTable_RowClick(w, row); } /* Handles clicking on column headers (either resizes a column or sort rows) */ diff --git a/src/LScreens.c b/src/LScreens.c index 8447ad184..87a980aba 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -931,7 +931,7 @@ static void MainScreen_Init(struct LScreen* s_) { static void MainScreen_Free(struct LScreen* s_) { struct MainScreen* s = (struct MainScreen*)s_; /* status should reset when user goes to another menu */ - s->lblStatus.text.length = 0; + LLabel_SetConst(&s->lblStatus, ""); } static void MainScreen_Layout(struct LScreen* s_) { diff --git a/src/LWidgets.c b/src/LWidgets.c index 9c951d047..4dd558a45 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -563,6 +563,20 @@ void LTable_SetSelectedTo(struct LTable* w, int index) { w->OnSelectedChanged(); } +void LTable_RowClick(struct LTable* w, int row) { + cc_uint64 now; + LTable_SetSelectedTo(w, row); + now = Stopwatch_Measure(); + + /* double click on row to join */ + if (Stopwatch_ElapsedMS(w->_lastClick, now) < 1000 && row == w->_lastRow) { + Launcher_ConnectToServer(<able_Get(row)->hash); + } + + w->_lastRow = LTable_GetSelectedIndex(w); + w->_lastClick = now; +} + cc_bool LTable_HandlesKey(int key) { return key == KEY_UP || key == KEY_DOWN || key == KEY_PAGEUP || key == KEY_PAGEDOWN; } diff --git a/src/LWidgets.h b/src/LWidgets.h index 3c7aee23e..b36372765 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -221,4 +221,5 @@ void LTable_ClampTopRow(struct LTable* w); int LTable_GetSelectedIndex(struct LTable* w); /* Sets selected row to given row, scrolling table if needed */ void LTable_SetSelectedTo(struct LTable* w, int index); +void LTable_RowClick(struct LTable* w, int row); #endif diff --git a/src/TexturePack.c b/src/TexturePack.c index 05b6b9c2c..5db459385 100644 --- a/src/TexturePack.c +++ b/src/TexturePack.c @@ -15,6 +15,7 @@ #include "Logger.h" #include "Utils.h" #include "Chat.h" /* TODO avoid this include */ +#include "Errors.h" /*########################################################################################################################* *------------------------------------------------------TerrainAtlas-------------------------------------------------------* @@ -306,10 +307,7 @@ static cc_result ExtractZip(struct Stream* stream) { static cc_result ExtractPng(struct Stream* stream) { struct Bitmap bmp; - cc_result res; - if ((res = stream->Seek(stream, 0))) return res; - - res = Png_Decode(&bmp, stream); + cc_result res = Png_Decode(&bmp, stream); if (!res && Atlas_TryChange(&bmp)) return 0; Mem_Free(bmp.scan0); @@ -318,7 +316,6 @@ static cc_result ExtractPng(struct Stream* stream) { static cc_bool needReload; static cc_result ExtractFrom(struct Stream* stream, const cc_string* path) { - cc_uint8 sig[PNG_SIG_SIZE]; cc_result res; Event_RaiseVoid(&TextureEvents.PackChanged); @@ -327,18 +324,13 @@ static cc_result ExtractFrom(struct Stream* stream, const cc_string* path) { if (Gfx.LostContext) { needReload = true; return 0; } needReload = false; - /* check for PNG signature/header */ - res = Stream_Read(stream, sig, PNG_SIG_SIZE); - if (res) { - Logger_SysWarn2(res, "detecting", path); return res; - } - - if (Png_Detect(sig, PNG_SIG_SIZE)) { - res = ExtractPng(stream); - if (res) Logger_SysWarn2(res, "decoding", path); - } else { + res = ExtractPng(stream); + if (res == PNG_ERR_INVALID_SIG) { + /* file isn't a .png, probably a .zip then */ res = ExtractZip(stream); if (res) Logger_SysWarn2(res, "extracting", path); + } else if (res) { + Logger_SysWarn2(res, "decoding", path); } return res; } diff --git a/src/interop_ios.m b/src/interop_ios.m index 5583a29da..1674eb384 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -621,7 +621,7 @@ static struct LWidget* FindWidgetForView(id obj) { } static NSString* cellID = @"CC_Cell"; -@interface CCUIController : NSObject +@interface CCUIController : NSObject @end @implementation CCUIController @@ -647,6 +647,7 @@ static NSString* cellID = @"CC_Cell"; if (ipt->TextChanged) ipt->TextChanged(ipt); } +// === UITableViewDataSource === - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { //UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath]; UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID]; @@ -678,6 +679,16 @@ static NSString* cellID = @"CC_Cell"; return FetchServersTask.numServers; } +// === UITableViewDelegate === +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + Platform_LogConst("CLIKO"); + extern void LTable_ClickRow(struct LTable* w, int row); + + struct LTable* w = FindWidgetForView(tableView); + if (w == NULL) return; + LTable_ClickRow(w, [indexPath row]); +} + @end static CCUIController* ui_controller;