Permalink
Browse files

Decoupled mouse highlighting from the selected item.

*  Created a new iHighlightIndex that generally works like iSelectedIndex
   did, except that it is not always the same as selectedIndex.
*  doSetSelectedIndex() takes a third parameter, if it is explicitly
   true, then only the highlighted index changes, if not set to true,
   then it will also change the iSelectedIndex as in vanilla.
*  SetEntry() uses iHighlightedIndex instead of iSelectedIndex,
   thus allowing to highlight other items without iSelectedIndex
   changing.
*  iSelectedIndex is controlled by keyboard only, or it is set when
    the mouse is clicked, but no longer when the mouse is moved.
*  Navigation up or down always moves the highlight back to the
   selected item, which is at center.
*  The mousewheel scroll now uses moveSelectionUp/Down()
   so it also always resets the highlight to the center item.
  • Loading branch information...
1 parent 583fda2 commit e5f0d8d719acd2d2545357d4415882f54084d74d @fabd committed Nov 23, 2012
@@ -78,6 +78,7 @@ class Shared.BSScrollingList extends MovieClip
var iScrollPosition: Number;
var iScrollbarDrawTimerID: Number;
var iSelectedIndex: Number;
+ var iHighlightedIndex: Number; // new
var iTextOption: Number;
var itemIndex: Number;
@@ -92,6 +93,7 @@ class Shared.BSScrollingList extends MovieClip
Mouse.addListener(this);
iSelectedIndex = -1;
+ iHighlightedIndex = -1;
iScrollPosition = 0;
iMaxScrollPosition = 0;
iListItemsShown = 0;
@@ -102,16 +104,19 @@ class Shared.BSScrollingList extends MovieClip
for (var item: MovieClip = GetClipByIndex(iMaxItemsShown); item != undefined; item = GetClipByIndex(++iMaxItemsShown)) {
item.clipIndex = iMaxItemsShown;
+
item.onRollOver = function ()
{
if (!_parent.listAnimating && !_parent.bDisableInput && itemIndex != undefined) {
- _parent.doSetSelectedIndex(itemIndex, 0);
+GlobalFunc.getInstance().Deebug("onRollOver() doSetSelectedIndex " + itemIndex);
+ _parent.doSetSelectedIndex(itemIndex, 0, true);
_parent.bMouseDrivenNav = true;
}
};
item.onPress = function (aiMouseIndex, aiKeyboardOrMouse)
{
if (itemIndex != undefined) {
+//GlobalFunc.getInstance().Deebug("item::onPress() " + aiKeyboardOrMouse);
_parent.onItemPress(aiKeyboardOrMouse);
if (!_parent.bDisableInput && onMousePress != undefined)
onMousePress();
@@ -145,6 +150,7 @@ class Shared.BSScrollingList extends MovieClip
function handleInput(details: InputDetails, pathToFocus: Array): Boolean
{
+GlobalFunc.getInstance().Deebug("handleInput() BSScrollingList");
var bHandledInput: Boolean = false;
if (!bDisableInput) {
var item: MovieClip = GetClipByIndex(selectedIndex - scrollPosition);
@@ -200,8 +206,58 @@ class Shared.BSScrollingList extends MovieClip
bListAnimating = abFlag;
}
+ /**
+ *
+ *
+ */
+ function doSetSelectedIndex(aiNewIndex:Number, aiKeyboardOrMouse: Number, abMouseFocus: Boolean): Void
+ {
+ // current focus is selectedindex, or mouse highlighted index (decoupled from selection)
+ var iCurHighlightIndex = iHighlightedIndex; // abMouseFocus ? iHighlightedIndex : iSelectedIndex;
+
+ if (!bDisableSelection) {
+
+ // change selectedIndex, unless explicitly doing the mouse highlighting
+ if (abMouseFocus !== true) {
+ iSelectedIndex = aiNewIndex;
+ }
+
+ if (aiNewIndex != iCurHighlightIndex) {
+ var iCurrentIndex: Number = iHighlightedIndex;
+
+ iHighlightedIndex = aiNewIndex;
+GlobalFunc.getInstance().Deebug("iHighlightedIndex = " + iHighlightedIndex);
+
+ if (iCurrentIndex != -1)
+ SetEntry(GetClipByIndex(EntriesA[iCurrentIndex].clipIndex), EntriesA[iCurrentIndex]);
+
+ if (iHighlightedIndex != -1) {
+ if (iPlatform != 0) {
+ if (iHighlightedIndex < iScrollPosition)
+ scrollPosition = iHighlightedIndex;
+ else if (iHighlightedIndex >= iScrollPosition + iListItemsShown)
+ scrollPosition = Math.min(iHighlightedIndex - iListItemsShown + 1, iMaxScrollPosition);
+ else
+ SetEntry(GetClipByIndex(EntriesA[iHighlightedIndex].clipIndex),EntriesA[iHighlightedIndex]);
+ } else {
+ SetEntry(GetClipByIndex(EntriesA[iHighlightedIndex].clipIndex),EntriesA[iHighlightedIndex]);
+ }
+ }
+
+ // note: this could have unwanted effects here, since highlighted is not always *selected*
+ // note: OR... dispatch only when selectedIndex changes... usually would want highlight change
+ dispatchEvent({type:"selectionChange", index:iHighlightedIndex, keyboardOrMouse:aiKeyboardOrMouse});
+ }
+ }
+ }
+
+ /**
+ * If parameters are (-1, 0), clears the existing selected index.
+ *
+
function doSetSelectedIndex(aiNewIndex:Number, aiKeyboardOrMouse: Number): Void
{
+GlobalFunc.getInstance().Deebug("doSetSelectedIndex("+aiNewIndex+") iSelectedIndex="+iSelectedIndex);
if (!bDisableSelection && aiNewIndex != iSelectedIndex) {
var iCurrentIndex: Number = iSelectedIndex;
iSelectedIndex = aiNewIndex;
@@ -224,6 +280,7 @@ class Shared.BSScrollingList extends MovieClip
dispatchEvent({type:"selectionChange", index:iSelectedIndex, keyboardOrMouse:aiKeyboardOrMouse});
}
}
+ */
function get scrollPosition(): Number
{
@@ -310,24 +367,24 @@ class Shared.BSScrollingList extends MovieClip
{
var iFirstItemy: Number = GetClipByIndex(0)._y;
var iItemHeightSum: Number = 0;
- var iLastItemShownIndex: Number = 0;
- while (iLastItemShownIndex < iScrollPosition) {
- EntriesA[iLastItemShownIndex].clipIndex = undefined;
- ++iLastItemShownIndex;
+ var i: Number = 0;
+ while (i < iScrollPosition) {
+ EntriesA[i].clipIndex = undefined;
+ ++i;
}
iListItemsShown = 0;
- iLastItemShownIndex = iScrollPosition;
- while (iLastItemShownIndex < EntriesA.length && iListItemsShown < iMaxItemsShown && iItemHeightSum <= fListHeight) {
+ i = iScrollPosition;
+ while (i < EntriesA.length && iListItemsShown < iMaxItemsShown && iItemHeightSum <= fListHeight) {
var item: MovieClip = GetClipByIndex(iListItemsShown);
- SetEntry(item, EntriesA[iLastItemShownIndex]);
- EntriesA[iLastItemShownIndex].clipIndex = iListItemsShown;
- item.itemIndex = iLastItemShownIndex;
+ SetEntry(item, EntriesA[i]);
+ EntriesA[i].clipIndex = iListItemsShown;
+ item.itemIndex = i;
item._y = iFirstItemy + iItemHeightSum;
item._visible = true;
iItemHeightSum += item._height;
if (iItemHeightSum <= fListHeight && iListItemsShown < iMaxItemsShown)
++iListItemsShown;
- ++iLastItemShownIndex;
+ ++i;
}
var iLastItemIndex: Number = iListItemsShown;
while (iLastItemIndex < iMaxItemsShown) {
@@ -409,9 +466,16 @@ class Shared.BSScrollingList extends MovieClip
scrollPosition = scrollPosition + 1;
}
+ /**
+ * MovieClip onPress() aiKeyboardOrMouse == 0
+ *
+ * If keyboard (handleInput), aiKeyboardOrMouse is undefined.
+ *
+ */
function onItemPress(aiKeyboardOrMouse: Number): Void
{
if (!bDisableInput && !bDisableSelection && iSelectedIndex != -1) {
+//GlobalFunc.getInstance().Deebug("onItemPress() aiKeyboardOrMouse = " + aiKeyboardOrMouse);
dispatchEvent({type: "itemPress", index: iSelectedIndex, entry: EntriesA[iSelectedIndex], keyboardOrMouse: aiKeyboardOrMouse});
return;
}
@@ -424,10 +488,13 @@ class Shared.BSScrollingList extends MovieClip
dispatchEvent({type: "itemPressAux", index: iSelectedIndex, entry: EntriesA[iSelectedIndex], keyboardOrMouse: aiKeyboardOrMouse});
}
+ // New: aSelectedEntry is based on highlighted index, which is not always selected index
function SetEntry(aEntryClip: MovieClip, aEntryObject: Object): Void
{
+ var aSelectedEntry: Object = EntriesA[iHighlightedIndex];
+
if (aEntryClip != undefined) {
- if (aEntryObject == selectedEntry)
+ if (aEntryObject == aSelectedEntry)
aEntryClip.gotoAndStop("Selected");
else
aEntryClip.gotoAndStop("Normal");
@@ -206,6 +206,9 @@ class Shared.CenteredScrollingList extends Shared.BSScrollingList
if (itemIndex != undefined) {
iSelectedIndex = itemIndex;
+ iHighlightedIndex = itemIndex; //faB++
+ bRecenterSelection = true; //fab
+
if (iScrollPosition > 0)
--iScrollPosition;
bMouseDrivenNav = false;
@@ -224,6 +227,9 @@ class Shared.CenteredScrollingList extends Shared.BSScrollingList
}
if (itemIndex != undefined) {
iSelectedIndex = itemIndex;
+ iHighlightedIndex = itemIndex; //faB++
+ bRecenterSelection = true; //fab
+
if (iScrollPosition < iMaxScrollPosition)
++iScrollPosition;
bMouseDrivenNav = false;
@@ -273,14 +279,16 @@ class Shared.CenteredScrollingList extends Shared.BSScrollingList
function SetEntry(aEntryClip: MovieClip, aEntryObject: Object): Void
{
+ var aSelectedEntry: Object = EntriesA[iHighlightedIndex];
+
if (aEntryClip != undefined) {
if (IsDivider(aEntryObject) == true)
aEntryClip.gotoAndStop("Divider");
else
aEntryClip.gotoAndStop("Normal");
if (iPlatform == 0) {
- aEntryClip._alpha = aEntryObject == selectedEntry ? 100 : 60;
+ aEntryClip._alpha = aEntryObject == aSelectedEntry ? 100 : 60;
} else {
var iAlphaMulti: Number = 4;
if (aEntryClip.clipIndex < iNumTopHalfEntries)
@@ -1,4 +1,7 @@
-class DialogueCenteredList extends Shared.CenteredScrollingList
+//faB++
+import Shared.GlobalFunc;
+
+class DialogueCenteredList extends Shared.CenteredScrollingList
{
var EntriesA: Array;
@@ -14,6 +17,10 @@
var iScrollPosition: Number;
var iSelectedIndex: Number;
+//faB++
+static var lolcat: Number = 0;
+
+
function DialogueCenteredList()
{
super();
@@ -57,6 +64,7 @@
if (bRecenterSelection || iPlatform != 0) {
iSelectedIndex = centerIndex;
+ iHighlightedIndex = centerIndex; // faB++
}
for (var i = centerIndex; i < EntriesA.length && iListItemsShown < iMaxItemsShown && listCumulativeHeight <= fListHeight; i++) {
@@ -77,22 +85,28 @@
GetClipByIndex(i).itemIndex = undefined;
}
-
if (!bRecenterSelection) {
- for (var target: Object = Mouse.getTopMostEntity(); target != undefined; target = target._parent) {
- if (target._parent == this && target._visible && target.itemIndex != undefined) {
- doSetSelectedIndex(target.itemIndex,0);
- }
- }
+ // faB: moved to function below
+ SetSelectedIndexByMouse(true);
}
-
+
bRecenterSelection = false;
RepositionEntries();
var imaxItemsBelowShown: Number = 3;
_parent.ScrollIndicators.Up._visible = scrollPosition > iNumTopHalfEntries;
_parent.ScrollIndicators.Down._visible = EntriesA.length - scrollPosition - 1 > imaxItemsBelowShown || listCumulativeHeight > fListHeight;
}
+ function SetSelectedIndexByMouse(abMouseHighlight: Boolean)
+ {
+ for (var target: Object = Mouse.getTopMostEntity(); target != undefined; target = target._parent) {
+ if (target._parent == this && target._visible && target.itemIndex != undefined) {
+GlobalFunc.getInstance().Deebug("SetSelectedIndexByMouse() " + target.itemIndex);
+ doSetSelectedIndex(target.itemIndex, 0, abMouseHighlight);
+ }
+ }
+ }
+
function RepositionEntries()
{
var item_yOffset = GetClipByIndex(iNumTopHalfEntries)._y + GetClipByIndex(iNumTopHalfEntries)._height / 2;
@@ -111,17 +125,29 @@
return;
}
- iSelectedIndex = -1;
- bRecenterSelection = true;
+ // iSelectedIndex = -1;
+ // iHighlightedIndex = -1; //faB++
+ // bRecenterSelection = true;
+ /*faB-- disabled because we always want the selection to be the center
for (var target: Object = Mouse.getTopMostEntity(); target && target != undefined; target = target._parent) {
if (target == this) {
bRecenterSelection = false;
}
- }
+ }*/
+//GlobalFunc.getInstance().Deebug("bRecenterSelection = " + bRecenterSelection);
var listItem: MovieClip
-
+
+ // keep it simple, stupid
+ if (delta < 0) {
+ moveSelectionDown();
+ } else {
+ moveSelectionUp();
+ }
+
+ // Vanilla scroll wheel handling for reference
+ /*
if (delta < 0) {
listItem = GetClipByIndex(iNumTopHalfEntries + 1);
if (listItem._visible == true) {
@@ -132,7 +158,8 @@
if (listItem._visible == true) {
scrollPosition = scrollPosition - 1;
}
- }
+ }*/
+
return;
}
Oops, something went wrong.

0 comments on commit e5f0d8d

Please sign in to comment.