Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interact with touch controls + back arrow with present #24

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion source/entities/Minigame.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Minigame extends Interactable
{
super.update(elapsed);

if (ready_to_play && Ctrl.interact[1])
if (ready_to_play && (Ctrl.interact[1] || FlxG.mouse.overlaps(this) && FlxG.mouse.justReleased))
{
start_minigame();
}
Expand Down
2 changes: 1 addition & 1 deletion source/entities/NPC.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NPC extends Interactable
sprite_anim.anim(PresentAnimation.IDLE);
case NEARBY:
sprite_anim.anim(PresentAnimation.NEARBY);
if (Ctrl.jinteract[1])
if (Ctrl.jinteract[1] || FlxG.mouse.overlaps(this) && FlxG.mouse.justReleased)
start_chat();
case CHATTING:
sprite_anim.anim(PresentAnimation.IDLE);
Expand Down
4 changes: 2 additions & 2 deletions source/entities/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Player extends BaseUser
{
if (active_activity_area == null)
return;
if (Ctrl.interact[1])
if (Ctrl.interact[1] || FlxG.mouse.overlaps(active_activity_area) && FlxG.mouse.justReleased)
{
active_activity_area.on_interact(this);
}
Expand Down Expand Up @@ -243,7 +243,7 @@ class Player extends BaseUser
closest.marked = true;
active_interactable = closest;

if (Ctrl.jinteract[1])
if (Ctrl.jinteract[1] || FlxG.mouse.overlaps(this) && FlxG.mouse.justReleased)
{
active_interactable.on_interact();
}
Expand Down
21 changes: 20 additions & 1 deletion source/states/substates/ArtSubstate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package states.substates;

import data.JsonData;
import entities.Present;
import flixel.tweens.FlxEase;
import ui.button.HoverButton;

class ArtSubstate extends flixel.FlxSubState
{
var art:FlxSprite;
var data:data.types.TankmasDefs.PresentDef;
var theText:FlxText;

var back_button:HoverButton;

override public function new(content:String)
{
super();
Expand Down Expand Up @@ -37,9 +41,24 @@ class ArtSubstate extends flixel.FlxSubState
theText.setFormat(null, 32, FlxColor.WHITE, CENTER, OUTLINE, FlxColor.BLACK);
add(theText);

add(back_button = new HoverButton((b) -> back_button_activated()));

back_button.scrollFactor.set(0, 0);

back_button.loadAllFromAnimationSet("back-arrow-but-smaller-for-present-art");
back_button.setPosition(FlxG.width - back_button.width - 16, FlxG.height - back_button.height - 16);
back_button.offset.y = -back_button.height;
back_button.tween = FlxTween.tween(back_button.offset, {y: 0}, 0.25, {ease: FlxEase.cubeInOut});

back_button.on_neutral = (b) -> b.alpha = 0.35;
back_button.on_hover = (b) -> b.alpha = 0.75;

members.for_all_members((member:flixel.FlxBasic) -> cast(member, FlxObject).scrollFactor.set(0, 0));
}

function back_button_activated()
close();

override function update(elapsed:Float)
{
super.update(elapsed);
Expand All @@ -54,7 +73,7 @@ class ArtSubstate extends flixel.FlxSubState
art.x += 5;
if (Ctrl.menuConfirm[1])
close();
if (FlxG.mouse.justPressed && FlxG.mouse.overlaps(theText))
if (FlxG.mouse.justPressed && FlxG.mouse.overlaps(theText) && !FlxG.mouse.overlaps(back_button))
FlxG.openURL(data.link != null ? data.link : 'https://${data.artist.toLowerCase()}.newgrounds.com');
}
}
2 changes: 1 addition & 1 deletion source/ui/DialogueBox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class DialogueBox extends FlxTypedGroupExt<FlxSprite>
FlxTween.tween(bg, {y: -bg.height}, 0.15, {ease: FlxEase.quadIn, onComplete: (t:FlxTween) -> next_dlg()});
sstate(WAIT);
case TYPING:
if (Ctrl.interact[1])
if (Ctrl.interact[1] || FlxG.mouse.justPressed)
type_index = dlg.text.str.length - 1;
if (ttick() % type_rate == 0)
type();
Expand Down
21 changes: 15 additions & 6 deletions source/ui/button/HoverButton.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import flixel.system.FlxAssets.FlxGraphicAsset;
class HoverButton extends FlxSpriteExt
{
public var on_release:HoverButton->Void;
public var on_hover:HoverButton->Void;
public var on_neutral:HoverButton->Void;

var enabled:Bool = true;

Expand All @@ -16,15 +18,22 @@ class HoverButton extends FlxSpriteExt

override function update(elapsed:Float)
{
var overlapping:Bool = FlxG.mouse.overlaps(this) && enabled;
var overlap_scale:Float = overlapping ? 1.1 : 1;
var hovering:Bool = FlxG.mouse.overlaps(this) && enabled;
var hover_scale:Float = hovering ? 1.1 : 1;

if (FlxG.mouse.pressed && overlapping)
overlap_scale = 1.35;
if (hovering)
if (on_hover != null)
on_hover(this);
if (!hovering)
if (on_neutral != null)
on_neutral(this);

scale.set(overlap_scale, overlap_scale);
if (FlxG.mouse.pressed && hovering)
hover_scale = 1.35;

if (overlapping && FlxG.mouse.justReleased)
scale.set(hover_scale, hover_scale);

if (hovering && FlxG.mouse.justReleased)
if (on_release != null)
on_release(this);

Expand Down