highlight selected jigsaw pieces
This commit is contained in:
@@ -46,13 +46,18 @@ typedef StartPuzzleFunc = (Int, Int) -> Void;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class HabitState extends FlxState {
|
||||
public function drawPieceShape( surface: FlxSprite, jig: JigsawPiece, scale:Float, c: FlxColor )
|
||||
public function drawPieceShape( surface: FlxSprite, jig: JigsawPiece, scale:Float, fillColor: FlxColor, ?outlineColor: FlxColor)
|
||||
{
|
||||
if (outlineColor == null) outlineColor = fillColor;
|
||||
var points = [for (point in jig.getPoints()) new FlxPoint(point.x / scale + ROT_PADDING, point.y / scale + ROT_PADDING)];
|
||||
points.push(points[0]);
|
||||
FlxSpriteUtil.drawPolygon(
|
||||
surface,
|
||||
points,
|
||||
c);
|
||||
fillColor,
|
||||
{
|
||||
thickness: 1,
|
||||
color: outlineColor
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -299,6 +299,7 @@
|
||||
(unless (= lastRewardFileIndex rewardFileIndex)
|
||||
// Make a new camera so scroll from the last puzzle doesn't start the camera out of boundS
|
||||
(newPieceCamera)
|
||||
(set pieceCamera.bgColor (nth backgroundOptions save.data.backgroundIndex))
|
||||
(set rewardSprite
|
||||
(new FlxSprite 0 0
|
||||
(BitmapData.fromFile
|
||||
@@ -388,7 +389,8 @@
|
||||
(dictSet indexMap s i)
|
||||
(dictSet spriteMap i s)
|
||||
(set s.draggable true)
|
||||
(s.enableDragToSelect)
|
||||
|
||||
|
||||
(s.enableMouseDrag false true)
|
||||
(set s.mouseStartDragCallback
|
||||
->:Void [s x y]
|
||||
@@ -413,7 +415,7 @@
|
||||
(pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN)
|
||||
(save.flush)))
|
||||
|
||||
(var ROT_PADDING 2)
|
||||
(var ROT_PADDING 4)
|
||||
(localVar fWidth (+ (Std.int sourceRect.width) (* 2 ROT_PADDING)))
|
||||
(localVar fHeight (+ (Std.int sourceRect.height) (* 2 ROT_PADDING)))
|
||||
(source.makeGraphic fWidth fHeight FlxColor.TRANSPARENT true)
|
||||
@@ -421,15 +423,29 @@
|
||||
|
||||
(mask.makeGraphic fWidth fHeight FlxColor.TRANSPARENT true)
|
||||
(drawPieceShape mask jig ros FlxColor.BLACK)
|
||||
(FlxSpriteUtil.alphaMask s source.pixels mask.pixels)
|
||||
|
||||
// Uncomment to debug piece ids and row/columns
|
||||
(localVar unhighlightedS (new FlxSprite))
|
||||
(FlxSpriteUtil.alphaMask unhighlightedS source.pixels mask.pixels)
|
||||
(localVar highlightedS (new FlxSprite))
|
||||
(s.loadGraphic unhighlightedS.pixels)
|
||||
(highlightedS.loadGraphic unhighlightedS.pixels false 0 0 true)
|
||||
(drawPieceShape highlightedS jig ros FlxColor.TRANSPARENT FlxColor.LIME)
|
||||
|
||||
(localFunction loadRotatedGraphic [:FlxSprite _s]
|
||||
(s.loadRotatedGraphic _s.pixels 4 -1))
|
||||
(loadRotatedGraphic unhighlightedS)
|
||||
|
||||
(s.enableDragToSelect
|
||||
->:Void {
|
||||
(loadRotatedGraphic highlightedS)
|
||||
}
|
||||
->:Void {
|
||||
(loadRotatedGraphic unhighlightedS)
|
||||
})
|
||||
|
||||
**(#when debug
|
||||
(kiss_flixel.SpriteTools.writeOnSprite "$i" 32 s (object x (Percent 0.5) y (Percent 0.5)) FlxColor.RED)
|
||||
(kiss_flixel.SpriteTools.writeOnSprite "(${jig.col},${jig.row})" 32 s (object x (Percent 0.5) y (Percent 0.7)) FlxColor.RED))
|
||||
|
||||
(s.loadRotatedGraphic s.pixels 4 -1 /*false true*/)
|
||||
|
||||
(set s.cameras [pieceCamera])
|
||||
|
||||
|
||||
|
@@ -66,6 +66,11 @@ class DragToSelectPlugin extends FlxBasic {
|
||||
}
|
||||
|
||||
public function deselectSprites() {
|
||||
for (sprite in dragStates[FlxG.state].selectedSprites) {
|
||||
if (sprite.onDeselected != null) {
|
||||
sprite.onDeselected();
|
||||
}
|
||||
}
|
||||
dragStates[FlxG.state].selectedSprites = [];
|
||||
}
|
||||
|
||||
|
@@ -106,7 +106,11 @@ class KissExtendedSprite extends flixel.addons.display.FlxExtendedSprite {
|
||||
}
|
||||
|
||||
var _dragToSelectEnabled = false;
|
||||
public function enableDragToSelect(?state:FlxState, ?camera:FlxCamera) {
|
||||
public var onSelected:Void->Void = null;
|
||||
public var onDeselected:Void->Void;
|
||||
public function enableDragToSelect(?onSelected:Void->Void, ?onDeselected:Void->Void, ?state:FlxState, ?camera:FlxCamera) {
|
||||
this.onSelected = onSelected;
|
||||
this.onDeselected = onDeselected;
|
||||
var plugin = FlxG.plugins.get(DragToSelectPlugin);
|
||||
if (plugin == null) {
|
||||
plugin = new DragToSelectPlugin();
|
||||
@@ -149,7 +153,6 @@ class KissExtendedSprite extends flixel.addons.display.FlxExtendedSprite {
|
||||
}
|
||||
}
|
||||
|
||||
public var onSelected:Void->Void = null;
|
||||
|
||||
public function pixelPerfectDrag() {
|
||||
return _dragPixelPerfect;
|
||||
|
Reference in New Issue
Block a user