Skip to content

Commit

Permalink
debug pointer accounts for flxsprite opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 committed Apr 27, 2024
1 parent 5823c46 commit a7d8e3b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
68 changes: 41 additions & 27 deletions flixel/system/debug/interaction/Interaction.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import openfl.display.Sprite;
import openfl.display.DisplayObject;
import openfl.events.KeyboardEvent;
import flixel.FlxObject;
import flixel.FlxSprite;
import openfl.events.MouseEvent;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.input.FlxPointer;
Expand Down Expand Up @@ -36,7 +37,7 @@ class Interaction extends Window
static inline var BUTTONS_PER_LINE = 2;
static inline var SPACING = 25;
static inline var PADDING = 10;

public var activeTool(default, null):Tool;
public var selectedItems(default, null):FlxTypedGroup<FlxObject> = new FlxTypedGroup();

Expand All @@ -51,7 +52,7 @@ class Interaction extends Window
* selection marks, for instance.
*/
public var shouldDrawItemsSelection:Bool = true;

/**
* Whether or not the user is using a mac keyboard, determines whether to use command or ctrl
*/
Expand All @@ -63,7 +64,7 @@ class Interaction extends Window
#else
false;
#end

var _container:Sprite;
var _customCursor:Sprite;
var _tools:Array<Tool> = [];
Expand Down Expand Up @@ -240,34 +241,34 @@ class Interaction extends Window
addChild(button);
resizeByTotal(buttons);
}

/**
* Removes the tool, if possible. If the tool has a button, all other buttons will be moved and
* the containing window will be resized, if needed.
*
*
* @param tool The tool to be removed
* @since 5.4.0
*/
public function removeTool(tool)
{
if (!_tools.contains(tool))
return;

// If there's no button just remove it
if (tool.button == null)
{
_tools.remove(tool);
return;
}

// if there is a button move all the following buttons
var index = _tools.indexOf(tool);
var prevX = tool.button.x;
var prevY = tool.button.y;

_tools.remove(tool);
removeChild(tool.button);

while (index < _tools.length)
{
final tool = _tools[index];
Expand All @@ -285,15 +286,15 @@ class Interaction extends Window
}
index++;
}

autoResize();
}

inline function autoResize()
{
resizeByTotal(countToolsWithUIButton());
}

inline function resizeByTotal(total:Int)
{
final spacing = 25;
Expand Down Expand Up @@ -606,32 +607,32 @@ class Interaction extends Window

/**
* Returns a list all items in the state and substate that are within the given area
*
*
* @param state The state to search
* @param area The rectangular area to search
* @since 5.6.0
*/
public function getItemsWithinState(state:FlxState, area:FlxRect):Array<FlxObject>
{
final items = new Array<FlxObject>();

addItemsWithinArea(items, state.members, area);
if (state.subState != null)
addItemsWithinState(items, state.subState, area);

return items;
}

@:deprecated("findItemsWithinState is deprecated, use getItemsWithinState or addItemsWithinState")
public inline function findItemsWithinState(items:Array<FlxBasic>, state:FlxState, area:FlxRect):Void
{
addItemsWithinState(cast items, state, area);
}

/**
* finds all items in the state and substate that are within the given area and
* adds them to the given list.
*
*
* @param items The list to add the items
* @param state The state to search
* @param area The rectangular area to search
Expand All @@ -643,10 +644,10 @@ class Interaction extends Window
if (state.subState != null)
addItemsWithinState(items, state.subState, area);
}

/**
* Finds and returns top-most item in the state and substate within the given area
*
*
* @param state The state to search
* @param area The rectangular area to search
* @since 5.6.0
Expand All @@ -655,7 +656,7 @@ class Interaction extends Window
{
if (state.subState != null)
return getTopItemWithinState(state.subState, area);

return getTopItemWithinArea(state.members, area);
}

Expand All @@ -674,7 +675,7 @@ class Interaction extends Window
{
addItemsWithinArea(cast items, members, area);
}

/**
* Find all items within an area. In order to improve performance and reduce temporary allocations,
* the method has no return, you must pass an array where items will be placed. The method decides
Expand All @@ -696,10 +697,16 @@ class Interaction extends Window
// Ignore invisible or non-existent entities
if (member == null || !member.visible || !member.exists)
continue;

final group = FlxTypedGroup.resolveSelectionGroup(member);
if (group != null)
addItemsWithinArea(items, group.members, area);
else if (member is FlxSprite)
{
final object:FlxSprite = cast member;
if (object.pixelsOverlapPoint(flixelPointer, 0xEE))
items.push(object);
}
else if (member is FlxObject)
{
final object:FlxObject = cast member;
Expand All @@ -708,10 +715,10 @@ class Interaction extends Window
}
}
}

/**
* Searches the members for the top-most object inside the given rectangle
*
*
* @param members The list of FlxObjects or FlxGroups
* @param area The rectangular area to search
* @return The top-most item
Expand All @@ -728,11 +735,18 @@ class Interaction extends Window
// Ignore invisible or non-existent entities
if (member == null || !member.visible || !member.exists)
continue;

final group = FlxTypedGroup.resolveGroup(member);
if (group != null)
return getTopItemWithinArea(group.members, area);


if (member is FlxSprite)
{
final object:FlxSprite = cast member;
if (object.pixelsOverlapPoint(flixelPointer, 0xEE))
return object;
}

if (member is FlxObject)
{
final object:FlxObject = cast member;
Expand Down
14 changes: 7 additions & 7 deletions flixel/system/debug/interaction/tools/Pointer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Pointer extends Tool
// If we had a selection happening, it's time to end it.
if (!_selectionHappening)
return;

final selectedItems = stopSelectionAndFindItems();
final drewRect = _selectionArea.width != 0 || _selectionArea.height != 0;
// If we have items in the selection area, handle them
Expand Down Expand Up @@ -109,7 +109,7 @@ class Pointer extends Tool
_selectionHappening = false;
_selectionArea.set(0, 0, 0, 0);
}

/**
* Stop any selection activity that is happening.
*/
Expand All @@ -133,12 +133,12 @@ class Pointer extends Tool
if (topItem != null)
items = [topItem];
}

updateConsoleSelection(items);

// Clear everything
stopSelection();

return items;
}

Expand All @@ -160,15 +160,15 @@ class Pointer extends Tool
// We add things to the selection list if the user is pressing the "add-new-item" key
final adding = _brain.keyPressed(Keyboard.SHIFT);
final removing = _brain.keyPressed(Keyboard.ALTERNATE) && !adding;

// If we are not selectively adding items, just clear
// the brain's list of selected items.
if (!adding && !removing)
_brain.clearSelection();

if (items == null || items.length == 0)
return;

final prevSelectedItems = _brain.selectedItems;
if (adding && !drewRect && items.length == 1)
{
Expand Down

0 comments on commit a7d8e3b

Please sign in to comment.