Skip to content

Commit 6798f2c

Browse files
committed
- New: autofocus on menuitems so that they are autofocused when page opens
- Bugfix: FullPage confirmation page now follow parent page custom positioning - Change: MPage.item_getCurrent() will now return MItem instead of MItemData
1 parent fa01454 commit 6798f2c

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

haxelib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "djFlixel",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"releasenote": "",
55
"description": "Set of tools and helpers for HaxeFlixel",
66
"url" : "https://github.com/john32b/djFlixel",

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
> :star: **NEW UPDATE** (2023-04) `V0.5.7` See [Announcement](https://github.com/john32b/djFlixel/discussions/25)
2+
> :star: **NEW UPDATE** (2023-05) `V0.5.8` See [Announcements Page](https://github.com/john32b/djFlixel/discussions/categories/announcements)
33
44
# 🔦 What is it
55

src/djFlixel/ui/FlxMenu.hx

+9-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,15 @@ class FlxMenu extends FlxGroup
476476

477477
case 3: // Call - Confirm New Page
478478
var P = MPageData.getConfirmationPage(it);
479-
_flag_restore_selected_index = true; // Use the custom index
479+
var a = pageActive;
480+
P.par({
481+
pos:a.PAR.pos,
482+
x:a.PAR.x,
483+
y:a.PAR.y,
484+
width:a.PAR.width
485+
});
480486
goto(P);
481-
_mev(pageCall, "?fs");
487+
_mev(pageCall, "?fs");
482488
return;
483489

484490
default:
@@ -648,7 +654,7 @@ class FlxMenu extends FlxGroup
648654
MP.y = mpActive.indexItem.y;
649655
add(MP);
650656

651-
MP.setSelection(P.PAR.cindex);
657+
MP.selectFirstAvailable();
652658
MP.viewOn();
653659
}//---------------------------------------------------;
654660

src/djFlixel/ui/menu/MItemData.hx

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
2626
- There are some standard field options that can go to any field, these are:
2727
28+
*new* |AF| AutoFocus. Will make the item focused by default when the page opens
2829
|D| Put it after the mandatory fields. Will DISABLE the element
2930
|U| Put it after the mandatory fields. Will make the item UNSELECTABLE (useful for labels)
3031
|I=Some Text| Writes custom text in the .info field of the object. It can be used later however you want
@@ -214,6 +215,8 @@ class MItemData
214215
.ask ; Array<String> The question to ask in {linK} if .ltype==2,3
215216
e.g. ["Are you sure?","Yes","No"] valid for {links}
216217
218+
.autofocus ; Boolean. If this is set. This item gets focused by default
219+
217220
218221
**/
219222
public var P:Dynamic = {};
@@ -255,8 +258,16 @@ class MItemData
255258
for (i in F)
256259
{
257260
// Check for universal parameters:
258-
// Currently : { |D| , |U| }
261+
// Currently : { |D| , |U| , |AF| }
259262

263+
264+
// |AF| , for autofocusing
265+
if (i == "AF")
266+
{
267+
P.autofocus = true;
268+
continue;
269+
}
270+
260271
// |D| , for Disabling the item
261272
if (i == "D") {
262273
disabled = true;

src/djFlixel/ui/menu/MPage.hx

+17-8
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class MPage extends VList<MItem,MItemData>
146146
// Set data and init the items
147147
setDataSource(page.items);
148148

149+
149150
// :: NEW : All cursor logic is in its own place
150151
// TODO, Cache the cursor object to be reusable?
151152
if (STP.cursor != null)
@@ -221,18 +222,24 @@ class MPage extends VList<MItem,MItemData>
221222
}
222223
}//---------------------------------------------------;
223224

224-
// Initializes the emenu, and focuses the first available
225+
/**
226+
- Called whenever a page is shown normally (i.e. not when going back to it)
227+
- Initializes the menu and focuses an item (first selectable, or custom autofocus)
228+
**/
225229
public function selectFirstAvailable()
226230
{
227-
setSelection(get_nextSelectableIndex(0, 1));
231+
var ind = page.getAutofocus();
232+
if (ind < 0) ind = get_nextSelectableIndex(0, 1);
233+
setSelection(ind);
228234
}//---------------------------------------------------;
229235

230236

231-
/**Focus an item, Moves the cursor to that item, scrolls the view if needed
237+
/** Focuses an item (moves the cursor to that item and item gets highlighted)
238+
Hard-scrolls the view if needed
232239
@param id ID of the Item
233240
@return Success
234241
**/
235-
public function item_moveCursorTo(id:String):Bool
242+
public function item_focus(id:String):Bool
236243
{
237244
var i = page.getIndex(id);
238245
if (i >-1){
@@ -277,12 +284,14 @@ class MPage extends VList<MItem,MItemData>
277284

278285
}//---------------------------------------------------;
279286

280-
/** Get the current active item data the cursor is pointing
287+
/**
288+
* ~ NEW in 0.5.8. BREAKING CHANGES : This now returns items, not itemdata
289+
* ~ to get itemdata, simple do item_getCurrent().data;
290+
* Get the current item the cursor is pointing
281291
*/
282-
public function item_getCurrent():MItemData
292+
public function item_getCurrent():MItem
283293
{
284-
if (indexData < 0) return null;
285-
return data[indexData];
294+
return indexItem;
286295
}//---------------------------------------------------;
287296

288297

src/djFlixel/ui/menu/MPageData.hx

+13-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ class MPageData
149149
}//---------------------------------------------------;
150150

151151

152+
/**
153+
Checks items for "autofocus"
154+
@return Index of item to be autofocused. -1 for nothing
155+
**/
156+
public function getAutofocus():Int
157+
{
158+
for (ind in 0...items.length) {
159+
if (items[ind].P.autofocus != null) return ind;
160+
}
161+
return -1;
162+
}//---------------------------------------------------;
163+
152164

153165
/**
154166
Quickly construct a pagedata with the confirmation options of the Link Item
@@ -171,10 +183,9 @@ class MPageData
171183
}
172184
}
173185

174-
P.add(' ${Q[1]}|link|${item.P.link} -|${Q[2]}|link|@back');
186+
P.add(' ${Q[1]}|link|${item.P.link} -|${Q[2]}|link|@back|AF');
175187
P.PAR.noPool = true;
176188
P.PAR.slots = P.items.length;
177-
P.PAR.cindex = P.items.length - 1; // Highlight the last one by default
178189
return P;
179190
}//---------------------------------------------------;
180191

0 commit comments

Comments
 (0)