Improved world selection scrolling code slightly

This commit is contained in:
Sasha Koshka
2022-05-07 15:26:13 -04:00
parent 28f130ec0b
commit d2de705000
2 changed files with 24 additions and 19 deletions

View File

@@ -284,9 +284,9 @@ void scrollbar (
SDL_Rect foreground = { SDL_Rect foreground = {
.x = x, .x = x,
.y = ceil((float)*level * sectionLength), .y = (float)*level * sectionLength,
.w = 4, .w = 4,
.h = sectionLength .h = ceil(sectionLength)
}; };
int hover = mouseX >= background.x && int hover = mouseX >= background.x &&

View File

@@ -102,24 +102,29 @@ void state_selectWorld (
int yLimit = BUFFER_H - 44; int yLimit = BUFFER_H - 44;
data_WorldListItem *item = data_worldList; data_WorldListItem *item = data_worldList;
while (item != NULL) { while (item != NULL) {
if (y > yLimit) { break; } if (y > yLimit) { break;}
if (index < scroll) { goto nextItem; }
if (index >= scroll) {
if (drawWorldListItem(renderer, item,
BUFFER_HALF_W - 64, y,
inputs->mouse.x,
inputs->mouse.y) && inputs->mouse.left
) {
if (World_load(world, item->name)) {
gameLoop_error("Could not load world");
} else {
*gameState = STATE_LOADING;
}
return;
}
y += 21;
}
int hover = drawWorldListItem(renderer, item,
BUFFER_HALF_W - 64, y,
inputs->mouse.x,
inputs->mouse.y);
y += 21;
if (!inputs->mouse.left) { goto nextItem; }
switch (hover) {
case 1:
if (World_load(world, item->name)) {
gameLoop_error("Could not load world");
} else {
*gameState = STATE_LOADING;
}
return;
case 2:
break;
}
nextItem:
index ++; index ++;
item = item->next; item = item->next;
} }