Browser is now browsing!

This commit is contained in:
Scott Duensing 2022-04-27 19:34:50 -05:00
parent f477ee15d0
commit 2807ff5521
5 changed files with 242 additions and 55 deletions

View file

@ -64,20 +64,25 @@ static ListboxT *_lstInfo = NULL;
static uint8_t _channel = 0;
static char *_lastSearchText = NULL;
static char *_nextZoomImage = NULL;
static GameT _selectedGame = { 0 };
static void btnTabClick(WidgetT *widget);
static void btnZoomCloseClick(WidgetT *widget);
static void fraBoxShow(void);
static void fraBoxReady(char *file);
static void fraDescriptionShow(void);
static void fraDescriptionReady(char *file);
static void fraInfoShow(void);
static void fraScreensShow(void);
static void fraScreensReady(char *file);
static void packetHandler(PacketDecodeDataT *packet);
static void picClick(WidgetT *widget);
static void tabsBusySet(uint8_t busy);
static void timSearchUpdate(WidgetT *widget);
static void updateSelectedGame(void);
static void winZoomReady(char *file);
void browserHide(void) {
@ -90,8 +95,6 @@ void browserHide(void) {
void browserShow(void) {
//char **lines = NULL;
TagItemT uiBrowser[] = {
T_START,
T_WINDOW, O(_winBrowser),
@ -162,27 +165,33 @@ void browserShow(void) {
T_PICTURE, O(_picThumb[0]), // Thumbs are 160x100
T_X, 1, T_Y, 5,
T_CACHENAME, P("browser:no-screen.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_PICTURE, O(_picThumb[1]),
T_X, 167, T_Y, 5,
T_CACHENAME, P("browser:no-screen.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_PICTURE, O(_picThumb[2]),
T_X, 333, T_Y, 5,
T_CACHENAME, P("browser:no-screen.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_PICTURE, O(_picThumb[3]),
T_X, 1, T_Y, 116,
T_CACHENAME, P("browser:no-screen.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_PICTURE, O(_picThumb[4]),
T_X, 167, T_Y, 116,
T_CACHENAME, P("browser:no-screen.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_PICTURE, O(_picThumb[5]),
T_X, 333, T_Y, 116,
T_CACHENAME, P("browser:no-screen.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_FRAME, T_DONE,
@ -203,10 +212,12 @@ void browserShow(void) {
T_PICTURE, O(_picBox[0]), // Thumbs are 240x210
T_X, 1, T_Y, 5,
T_CACHENAME, P("browser:no-box.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_PICTURE, O(_picBox[1]),
T_X, 250, T_Y, 5,
T_CACHENAME, P("browser:no-box.png"),
T_CLICK, P(picClick),
T_PICTURE, T_DONE,
T_FRAME, T_DONE,
@ -245,49 +256,15 @@ void browserShow(void) {
guiFocusSet(W(_txtSearch));
_channel = netChannelGet(packetHandler);
// This forces the background timer to run the search.
_lastSearchText = strdup("x");
/*
guiDebugAreaShow(W(_fraSearch));
lines = utilWrapText(
"The Post-Terran Minerals Corporation (PTMC) digs up minerals on all nine planets of the solar system, "
"employing humans and robots to do its job. Unfortunately, the mining robots are now being controlled by a hacker, "
"and have taken the human workers hostage. The PTMC has tried to get the robots back under their control, but "
"communication with the mining stations has been lost. In desperation, the PTMC modifies a Pyro-GX ship for combat "
"and hires a mercenary, codenamed 'Material Defender', to fly it. The mission is to destroy the infected mines and "
"rescue human hostages, destroying any hostile robot that gets in the way.", 57);
while (arrlen(lines) > 0) {
listboxItemAdd(_lstDescription, lines[0]);
DEL(lines[0]);
arrdel(lines, 0);
}
listboxItemAdd(_lstResults, "123456789012345678901234567890123456789012345678901234567");
listboxItemAdd(_lstResults, "2");
listboxItemAdd(_lstResults, "3");
listboxItemAdd(_lstResults, "4");
listboxItemAdd(_lstResults, "5");
listboxItemAdd(_lstResults, "6");
listboxItemAdd(_lstResults, "7");
listboxItemAdd(_lstResults, "8");
listboxItemAdd(_lstResults, "9");
listboxItemAdd(_lstResults, "10");
listboxItemAdd(_lstResults, "11");
listboxItemAdd(_lstResults, "12");
listboxItemAdd(_lstResults, "13");
listboxItemAdd(_lstResults, "14");
listboxItemAdd(_lstResults, "15");
listboxItemAdd(_lstResults, "16");
listboxItemAdd(_lstResults, "17");
*/
guiDebugAreaShow(W(_btnBoxTab));
}
static void btnTabClick(WidgetT *widget) {
tabsBusySet(1);
// Hide everything.
widgetVisibleSet(W(_fraBox), 0);
widgetVisibleSet(W(_fraDescription), 0);
@ -302,28 +279,153 @@ static void btnTabClick(WidgetT *widget) {
if (widget == W(_btnDescriptionTab)) fraDescriptionShow();
if (widget == W(_btnInfoTab)) fraInfoShow();
if (widget == W(_btnScreensTab)) fraScreensShow();
if (widget == W(_btnSearchTab)) {
widgetVisibleSet(W(_fraSearch), 1);
tabsBusySet(0);
}
if (widget == W(_btnSearchTab)) widgetVisibleSet(W(_fraSearch), 1);
}
static void btnZoomCloseClick(WidgetT *widget) {
WindowT *w = (WindowT *)guiParentGet(widget);
guiDelete(D(w));
}
static void fraBoxShow(void) {
widgetVisibleSet(W(_fraBox), 1);
tabsBusySet(0);
char **fileList = NULL;
char *temp;
uint8_t i;
tabsBusySet(1);
// Build list of box filenames needed.
for (i=0; i<_selectedGame.boxes; i++) {
temp = utilCreateString("games:%c:%s:box%d.png", _selectedGame.shortName[0], _selectedGame.shortName, i + 1);
utilStringToLower(temp);
arrput(fileList, temp);
temp = utilCreateString("games:%c:%s:box%d-thumb.png", _selectedGame.shortName[0], _selectedGame.shortName, i + 1);
utilStringToLower(temp);
arrput(fileList, temp);
}
if (fileList) {
fileCacheCheckArr(fraBoxReady, fileList);
} else {
fraBoxReady(NULL);
}
}
static void fraDescriptionShow(void) {
widgetVisibleSet(W(_fraDescription), 1);
static void fraBoxReady(char *file) {
uint8_t i;
// Is this a file update notice? If so, exit.
if (file) return;
tabsBusySet(0);
// Are there boxes?
if (_selectedGame.boxes == 0) {
// Nope.
pictureReplace(_picBox[0], "browser:no-box.png");
widgetVisibleSet(W(_picBox[1]), 0);
} else {
for (i=0; i<2; i++) {
if (i < _selectedGame.boxes) {
snprintf(_scratch, SCRATCH_SIZE, "games:%c:%s:box%d-thumb.png", _selectedGame.shortName[0], _selectedGame.shortName, i + 1);
utilStringToLower(_scratch);
pictureReplace(_picBox[i], _scratch);
widgetVisibleSet(W(_picBox[i]), 1);
} else {
widgetVisibleSet(W(_picBox[i]), 0);
}
}
}
// Display us.
widgetVisibleSet(W(_fraBox), 1);
}
static void fraDescriptionShow(void) {
char **fileList = NULL;
char *temp;
tabsBusySet(1);
temp = utilCreateString("games:%c:%s:banner.png", _selectedGame.shortName[0], _selectedGame.shortName);
utilStringToLower(temp);
arrput(fileList, temp);
fileCacheCheckArr(fraDescriptionReady, fileList);
}
static void fraDescriptionReady(char *file) {
char **lines = NULL;
// Is this a file update notice? If so, exit.
if (file) return;
tabsBusySet(0);
snprintf(_scratch, SCRATCH_SIZE, "games:%c:%s:banner.png", _selectedGame.shortName[0], _selectedGame.shortName);
utilStringToLower(_scratch);
pictureReplace(_picBanner, _scratch);
listboxItemsClear(_lstDescription);
lines = utilWrapText(_selectedGame.description, 57);
while (arrlen(lines) > 0) {
listboxItemAdd(_lstDescription, lines[0]);
DEL(lines[0]);
arrdel(lines, 0);
}
// Show us.
widgetVisibleSet(W(_fraDescription), 1);
}
static void fraInfoShow(void) {
listboxItemsClear(_lstInfo);
snprintf(_scratch, SCRATCH_SIZE, " Title: %s", _selectedGame.title);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, "Developer: %s", _selectedGame.developer);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, "Publisher: %s", _selectedGame.publisher);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, " Released: %s", _selectedGame.releaseDate);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, " Rating: %s", _selectedGame.rating);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, " Series: %s", _selectedGame.series);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, " Source: %s", _selectedGame.origin);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, " Type: %s",
_selectedGame.type == GAME_TYPE_DOOR ? "BBS Door" :
_selectedGame.type == GAME_TYPE_SERIAL ? "Modem or Serial" :
_selectedGame.type == GAME_TYPE_IPX ? "IPX Network" :
_selectedGame.type == GAME_TYPE_FICTION ? "Interactive Fiction" : "Unknown"
);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, " Players: %d", _selectedGame.maxPlayers);
listboxItemAdd(_lstInfo, _scratch);
snprintf(_scratch, SCRATCH_SIZE, " Joinable: %s", _selectedGame.joinable ? "Yes" : "No");
listboxItemAdd(_lstInfo, _scratch);
widgetVisibleSet(W(_fraInfo), 1);
tabsBusySet(0);
}
@ -332,6 +434,8 @@ static void fraScreensShow(void) {
char *temp;
uint8_t i;
tabsBusySet(1);
// Build list of screen filenames needed.
for (i=0; i<_selectedGame.screens; i++) {
temp = utilCreateString("games:%c:%s:screen%d.png", _selectedGame.shortName[0], _selectedGame.shortName, i + 1);
@ -357,6 +461,8 @@ static void fraScreensReady(char *file) {
// Is this a file update notice? If so, exit.
if (file) return;
tabsBusySet(0);
// Are there screenshots?
if (_selectedGame.screens == 0) {
// Nope.
@ -369,7 +475,6 @@ static void fraScreensReady(char *file) {
if (i < _selectedGame.screens) {
snprintf(_scratch, SCRATCH_SIZE, "games:%c:%s:screen%d-thumb.png", _selectedGame.shortName[0], _selectedGame.shortName, i + 1);
utilStringToLower(_scratch);
logWrite("Loading screen: %s\n", _scratch);
pictureReplace(_picThumb[i], _scratch);
widgetVisibleSet(W(_picThumb[i]), 1);
} else {
@ -380,7 +485,6 @@ static void fraScreensReady(char *file) {
// Display us.
widgetVisibleSet(W(_fraScreens), 1);
tabsBusySet(0);
}
@ -389,6 +493,38 @@ static void packetHandler(PacketDecodeDataT *packet) {
}
static void picClick(WidgetT *widget) {
PictureT *p = (PictureT *)widget;
char *c = NULL;
char **fileList = NULL;
_nextZoomImage = strdup(pictureFilenameGet(p));
if (strcmp(_nextZoomImage, "browser:no-box.png") == 0 || strcmp(_nextZoomImage, "browser:no-screen.png") == 0) {
// Can't zoom nothing!
DEL(_nextZoomImage);
return;
}
c = strstr(_nextZoomImage, "-thumb.png");
if (!c) {
// Someone didn't follow naming rules!
DEL(_nextZoomImage);
return;
}
c[0] = '.';
c[1] = 'p';
c[2] = 'n';
c[3] = 'g';
c[4] = 0;
tabsBusySet(1);
arrput(fileList, _nextZoomImage);
fileCacheCheckArr(winZoomReady, fileList);
}
static void tabsBusySet(uint8_t busy) {
uint8_t enabled = busy ? 0 : 1;
@ -501,3 +637,30 @@ static void updateSelectedGame(void) {
}
}
}
static void winZoomReady(char *file) {
WindowT *winZoom = NULL;
PictureT *picZoom = NULL;
ButtonT *btnClose = NULL;
uint16_t w;
uint16_t h;
// Is this a file update notice? If so, exit.
if (file) return;
tabsBusySet(0);
picZoom = pictureNew(1, 1, _nextZoomImage);
w = widgetWidthGet(W(picZoom)) + 7 + 8 + 2;
h = widgetHeightGet(W(picZoom)) + 26 + 8 + 22 + 6;
btnClose = buttonNew(w - 77, widgetHeightGet(W(picZoom)) + 3, "Close", btnZoomCloseClick);
winZoom = windowNew(vbeDisplayWidthGet() / 2 - w / 2, vbeDisplayHeightGet() / 2 - h / 2, w, h, "Image");
guiAttach(W(winZoom), W(picZoom));
guiAttach(W(winZoom), W(btnClose));
guiAttach(guiRootGet(), W(winZoom));
DEL(_nextZoomImage);
}

View file

@ -218,7 +218,6 @@ void guiDelayedFree(void **pointer) {
// Delayed Free allows freeing of data that may be in use by the
// GUI system at a safe time. (After compositing.)
arrput(_guiPendingFrees, *pointer);
*pointer = NULL;
}
@ -231,7 +230,6 @@ void guiDelete(WidgetT **widget) {
// that is also handled in the paint event.
arrput(_guiDeleteList, widget);
*widget = NULL;
}
@ -239,7 +237,7 @@ static void guiDeleteList(void) {
WidgetT **w = NULL;
WindowT *win = NULL;
if (_guiDeleteList) {
if (_guiDeleteList != NULL) {
while (arrlen(_guiDeleteList) > 0) {
w = arrpop(_guiDeleteList);
guiDeleteListItem(w);
@ -261,12 +259,17 @@ static void guiDeleteList(void) {
static void guiDeleteListItem(WidgetT **widget) {
WidgetT *w = *widget;
size_t len = arrlenu(w->children);
size_t plen = arrlen(w->parent != NULL ? w->parent->children : 0);
size_t len = 0;
size_t plen = 0;
size_t x = 0;
uint8_t nuke = 1;
static uint16_t depth = 0;
if (!w) return;
len = arrlenu(w->children);
plen = arrlen(w->parent != NULL ? w->parent->children : 0);
// Delete children.
if (len > 0) {
for (x=0; x<len; x++) {
@ -329,6 +332,7 @@ void guiFocusSet(WidgetT *widget) {
return;
}
}
// Did the focus change?
if (widget != _guiFocused) {
// Remove focus from current control.
@ -424,8 +428,16 @@ static uint8_t guiMouseChildrenProcess(WidgetT *widget, MouseT *mouse) {
uint16_t sx;
uint16_t sy;
uint8_t event = MOUSE_EVENT_NONE;
WidgetT *who = NULL;
static WidgetT *focusDown = NULL;
// If one of our parents is hidden or disabled, skip all this.
who = widget;
while (who) {
if (GUI_GET_FLAG(widget, WIDGET_FLAG_DISABLED) || GUI_GET_FLAG(widget, WIDGET_FLAG_HIDDEN)) return 0;
who = who->parent;
}
// Get widget and screen coordinates of pointer.
guiWidgetPositionOnScreenGet(widget, &r);
sx = r.x;
@ -582,6 +594,11 @@ void guiParentAndChildrenDirtySet(WidgetT *widget) {
}
WidgetT *guiParentGet(WidgetT *widget) {
return widget->parent;
}
void guiPendingEventAdd(WidgetT *widget, void *callback) {
PendingEventsT *p = NULL;

View file

@ -208,6 +208,7 @@ void guiMouseBusyPop();
void guiMouseBusyPush();
void guiPaint(WidgetT *widget);
void guiParentAndChildrenDirtySet(WidgetT *widget);
WidgetT *guiParentGet(WidgetT *widget);
void guiPendingEventAdd(WidgetT *widget, void *callback);
WidgetT *guiRootGet(void);
void guiShutdown(void);

View file

@ -39,6 +39,11 @@ static void pictureDel(WidgetT **widget) {
}
char *pictureFilenameGet(PictureT *picture) {
return picture->filename;
}
WidgetT *pictureInit(WidgetT *widget, char *filename) {
PictureT *l = (PictureT *)widget;

View file

@ -43,6 +43,7 @@ typedef struct PictureS {
void pictureClickHandlerSet(PictureT *picture, widgetCallback callback);
char *pictureFilenameGet(PictureT *picture);
WidgetT *pictureInit(WidgetT *widget, char *filename);
PictureT *pictureNew(uint16_t x, uint16_t y, char *filename);
void pictureReplace(PictureT *picture, char *filename);