ios: support joining servers through list by clicking, fix status text not disappearing after leaving main menu

This commit is contained in:
UnknownShadow200 2022-04-14 23:44:14 +10:00
parent 94bd27f94a
commit 8c6375b462
6 changed files with 36 additions and 29 deletions

View File

@ -730,18 +730,7 @@ void LBackend_TableDraw(struct LTable* w) {
static void LTable_RowsClick(struct LTable* w, int idx) { static void LTable_RowsClick(struct LTable* w, int idx) {
int mouseY = Pointers[idx].y - w->rowsBegY; int mouseY = Pointers[idx].y - w->rowsBegY;
int row = w->topRow + mouseY / w->rowHeight; int row = w->topRow + mouseY / w->rowHeight;
cc_uint64 now; LTable_RowClick(w, row);
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(&LTable_Get(row)->hash);
}
w->_lastRow = LTable_GetSelectedIndex(w);
w->_lastClick = now;
} }
/* Handles clicking on column headers (either resizes a column or sort rows) */ /* Handles clicking on column headers (either resizes a column or sort rows) */

View File

@ -931,7 +931,7 @@ static void MainScreen_Init(struct LScreen* s_) {
static void MainScreen_Free(struct LScreen* s_) { static void MainScreen_Free(struct LScreen* s_) {
struct MainScreen* s = (struct MainScreen*)s_; struct MainScreen* s = (struct MainScreen*)s_;
/* status should reset when user goes to another menu */ /* 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_) { static void MainScreen_Layout(struct LScreen* s_) {

View File

@ -563,6 +563,20 @@ void LTable_SetSelectedTo(struct LTable* w, int index) {
w->OnSelectedChanged(); 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(&LTable_Get(row)->hash);
}
w->_lastRow = LTable_GetSelectedIndex(w);
w->_lastClick = now;
}
cc_bool LTable_HandlesKey(int key) { cc_bool LTable_HandlesKey(int key) {
return key == KEY_UP || key == KEY_DOWN || key == KEY_PAGEUP || key == KEY_PAGEDOWN; return key == KEY_UP || key == KEY_DOWN || key == KEY_PAGEUP || key == KEY_PAGEDOWN;
} }

View File

@ -221,4 +221,5 @@ void LTable_ClampTopRow(struct LTable* w);
int LTable_GetSelectedIndex(struct LTable* w); int LTable_GetSelectedIndex(struct LTable* w);
/* Sets selected row to given row, scrolling table if needed */ /* Sets selected row to given row, scrolling table if needed */
void LTable_SetSelectedTo(struct LTable* w, int index); void LTable_SetSelectedTo(struct LTable* w, int index);
void LTable_RowClick(struct LTable* w, int row);
#endif #endif

View File

@ -15,6 +15,7 @@
#include "Logger.h" #include "Logger.h"
#include "Utils.h" #include "Utils.h"
#include "Chat.h" /* TODO avoid this include */ #include "Chat.h" /* TODO avoid this include */
#include "Errors.h"
/*########################################################################################################################* /*########################################################################################################################*
*------------------------------------------------------TerrainAtlas-------------------------------------------------------* *------------------------------------------------------TerrainAtlas-------------------------------------------------------*
@ -306,10 +307,7 @@ static cc_result ExtractZip(struct Stream* stream) {
static cc_result ExtractPng(struct Stream* stream) { static cc_result ExtractPng(struct Stream* stream) {
struct Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res = Png_Decode(&bmp, stream);
if ((res = stream->Seek(stream, 0))) return res;
res = Png_Decode(&bmp, stream);
if (!res && Atlas_TryChange(&bmp)) return 0; if (!res && Atlas_TryChange(&bmp)) return 0;
Mem_Free(bmp.scan0); Mem_Free(bmp.scan0);
@ -318,7 +316,6 @@ static cc_result ExtractPng(struct Stream* stream) {
static cc_bool needReload; static cc_bool needReload;
static cc_result ExtractFrom(struct Stream* stream, const cc_string* path) { static cc_result ExtractFrom(struct Stream* stream, const cc_string* path) {
cc_uint8 sig[PNG_SIG_SIZE];
cc_result res; cc_result res;
Event_RaiseVoid(&TextureEvents.PackChanged); 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; } if (Gfx.LostContext) { needReload = true; return 0; }
needReload = false; 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); res = ExtractPng(stream);
if (res) Logger_SysWarn2(res, "decoding", path); if (res == PNG_ERR_INVALID_SIG) {
} else { /* file isn't a .png, probably a .zip then */
res = ExtractZip(stream); res = ExtractZip(stream);
if (res) Logger_SysWarn2(res, "extracting", path); if (res) Logger_SysWarn2(res, "extracting", path);
} else if (res) {
Logger_SysWarn2(res, "decoding", path);
} }
return res; return res;
} }

View File

@ -621,7 +621,7 @@ static struct LWidget* FindWidgetForView(id obj) {
} }
static NSString* cellID = @"CC_Cell"; static NSString* cellID = @"CC_Cell";
@interface CCUIController : NSObject<UITableViewDataSource> @interface CCUIController : NSObject<UITableViewDataSource, UITableViewDelegate>
@end @end
@implementation CCUIController @implementation CCUIController
@ -647,6 +647,7 @@ static NSString* cellID = @"CC_Cell";
if (ipt->TextChanged) ipt->TextChanged(ipt); if (ipt->TextChanged) ipt->TextChanged(ipt);
} }
// === UITableViewDataSource ===
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
//UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath]; //UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID]; UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID];
@ -678,6 +679,16 @@ static NSString* cellID = @"CC_Cell";
return FetchServersTask.numServers; 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 @end
static CCUIController* ui_controller; static CCUIController* ui_controller;