Skip to content

Commit

Permalink
VList can handle pages with no selectable items, fixes #31
Browse files Browse the repository at this point in the history
- instead of throwing an error, it will now log a warning and continue
- can now send a 'back' event when inputMode=1 or no selectables
  • Loading branch information
john32b committed Jan 24, 2024
1 parent edaa5d7 commit 5b41001
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions djFlixel/ui/VList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -451,22 +451,27 @@ class VList<T:IListItem<K> & FlxSprite, K> extends FlxSpriteGroup

public function focus()
{
#if debug
if (indexLastSlot ==-1) throw "Must SetData first";
#end

if (data == null) {
trace("Error: No data on the list, call setDataSource() first");
return;
}

if (isFocused || isScrolling) return;
isFocused = true;

queue_listEvent("focus");

if(scind!=null) scind.visible();

if (inputMode == 2)
{
if (indexLastSlot ==-1) {
trace("Warning: No available item to focus");
return;
}

slot_focus(indexLastSlot);
}

if(scind!=null) scind.visible();

}//---------------------------------------------------;

public function unfocus()
Expand Down Expand Up @@ -618,7 +623,12 @@ class VList<T:IListItem<K> & FlxSprite, K> extends FlxSpriteGroup
}

if (inputMode == 2) {
setSelection(get_nextSelectableIndex(0, 1));
var ind = get_nextSelectableIndex(0, 1);
if(ind<0) {
trace("Warning: No selectable items on the list");
setScroll(0); // just init the items
}
else setSelection(ind);
}else{
setScroll(0);
}
Expand All @@ -641,7 +651,7 @@ class VList<T:IListItem<K> & FlxSprite, K> extends FlxSpriteGroup

if (ind >= data.length) {
ind = data.length - 1;
}
}else if(ind<0) ind=0;

if (isFocused) slot_unfocus();

Expand All @@ -667,7 +677,7 @@ class VList<T:IListItem<K> & FlxSprite, K> extends FlxSpriteGroup
_islot += delta;
}

indexLastSlot = _islot; // In case the menu is unfocused.
indexLastSlot = _islot; // In case the menu is currently unfocused (or when initializing)

if (isFocused) slot_focus(_islot);

Expand Down Expand Up @@ -731,9 +741,13 @@ class VList<T:IListItem<K> & FlxSprite, K> extends FlxSpriteGroup
scrollDown1();
}
}else



if (D.ctrl.justPressed(X)) {
queue_listEvent("back");
}else

if (inputMode == 1) return;
if (indexItem == null) return;

if (D.ctrl.timePress(LEFT, 0.7, 0.08, 0.02)) {
indexItem.onInput(left);
Expand All @@ -750,10 +764,6 @@ class VList<T:IListItem<K> & FlxSprite, K> extends FlxSpriteGroup
indexItem.onInput(fire);
}else

if (D.ctrl.justPressed(X)) {
queue_listEvent("back");
}else

if (D.ctrl.justPressed(START)) {
if (OPT.start_button_fire)
indexItem.onInput(fire);
Expand Down

0 comments on commit 5b41001

Please sign in to comment.