<commit_before>package flixel.ui;

import flash.display.BitmapData;
import flash.events.MouseEvent;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.input.touch.FlxTouch;
import flixel.interfaces.IFlxDestroyable;
import flixel.system.FlxSound;
import flixel.util.FlxPoint;

@:bitmap("assets/images/ui/button.png")	private class GraphicButton	extends BitmapData {}

/**
 * A simple button class that calls a function when clicked by the mouse.
 */
class FlxTypedButton<T:FlxSprite> extends FlxSprite
{
	/**
	 * The label that appears on the button. Can be any FlxSprite.
	 */
	public var label:T;
	/**
	 * What offsets the label should have for each status.
	 */
	public var labelOffsets:Array<FlxPoint>;
	/**
	 * What alpha value the label should have for each status. Default is [0.8, 1.0, 0.5].
	 */
	public var labelAlphas:Array<Float>;
	/**
	 * Whether you can press the button simply by releasing the touch / mouse button over it (default).
	 * If false, the input has to be pressed while hovering over the button.
	 */
	public var allowSwiping:Bool = true;
	/**
	 * Whether to allow the HIHGLIGHT frame of the button graphic to be used on mobile 
	 * (false by default, the NORMAL graphic is used instead then).
	 */
	public var allowHighlightOnMobile:Bool = false;
	/**
	 * Shows the current state of the button, either FlxButton.NORMAL, 
	 * FlxButton.HIGHLIGHT or FlxButton.PRESSED.
	 */
	public var status(default, set):Int;
	/**
	 * The properties of this button's onUp event (callback function, sound).
	 */
	public var onUp(default, null):FlxButtonEvent;
	/**
	 * The properties of this button's onDown event (callback function, sound).
	 */
	public var onDown(default, null):FlxButtonEvent;
	/**
	 * The properties of this button's onOver event (callback function, sound).
	 */
	public var onOver(default, null):FlxButtonEvent;
	/**
	 * The properties of this button's onOut event (callback function, sound).
	 */
	public var onOut(default, null):FlxButtonEvent;

	/**
	 * The touch currently pressing this button, if none, it's null. Needed to check for its release.
	 */
	private var _pressedTouch:FlxTouch;
	/**
	 * Whether this button is currently being pressed by the mouse. Needed to check for its release.
	 */
	private var _pressedMouse:Bool = false;
	
	/**
	 * Creates a new FlxTypedButton object with a gray background.
	 * 
	 * @param	X				The X position of the button.
	 * @param	Y				The Y position of the button.
	 * @param	Label			The text that you want to appear on the button.
	 * @param	OnClick			The function to call whenever the button is clicked.
	 */
	public function new(X:Float = 0, Y:Float = 0, ?Label:String, ?OnClick:Void->Void)
	{
		super(X, Y);
		
		loadGraphic(GraphicButton, true, false, 80, 20);
		
		onUp = new FlxButtonEvent(OnClick);
		onDown = new FlxButtonEvent();
		onOver = new FlxButtonEvent();
		onOut = new FlxButtonEvent();
		
		labelAlphas = [0.8, 1.0, 0.5];
		labelOffsets = [FlxPoint.get(), FlxPoint.get(), FlxPoint.get(0, 1)];
		
		status = FlxButton.NORMAL;
		
		// Since this is a UI element, the default scrollFactor is (0, 0)
		scrollFactor.set();
		
		#if !FLX_NO_MOUSE
		FlxG.stage.addEventListener(MouseEvent.MOUSE_UP, onUpEventListener);
		#end
	}
	
	/**
	 * Called by the game state when state is changed (if this object belongs to the state)
	 */
	override public function destroy():Void
	{
		label = FlxG.safeDestroy(label);
		
		onUp = FlxG.safeDestroy(onUp);
		onDown = FlxG.safeDestroy(onDown);
		onOver = FlxG.safeDestroy(onOver);
		onOut = FlxG.safeDestroy(onOut);
		
		for (point in labelOffsets)
		{
			point.put();
		}
		
		labelOffsets = null;
		labelAlphas = null;<commit_msg>FlxTypedButton.destroy(): add a null check<commit_after>package flixel.ui;

import flash.display.BitmapData;
import flash.events.MouseEvent;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.input.touch.FlxTouch;
import flixel.interfaces.IFlxDestroyable;
import flixel.system.FlxSound;
import flixel.util.FlxPoint;

@:bitmap("assets/images/ui/button.png")	private class GraphicButton	extends BitmapData {}

/**
 * A simple button class that calls a function when clicked by the mouse.
 */
class FlxTypedButton<T:FlxSprite> extends FlxSprite
{
	/**
	 * The label that appears on the button. Can be any FlxSprite.
	 */
	public var label:T;
	/**
	 * What offsets the label should have for each status.
	 */
	public var labelOffsets:Array<FlxPoint>;
	/**
	 * What alpha value the label should have for each status. Default is [0.8, 1.0, 0.5].
	 */
	public var labelAlphas:Array<Float>;
	/**
	 * Whether you can press the button simply by releasing the touch / mouse button over it (default).
	 * If false, the input has to be pressed while hovering over the button.
	 */
	public var allowSwiping:Bool = true;
	/**
	 * Whether to allow the HIHGLIGHT frame of the button graphic to be used on mobile 
	 * (false by default, the NORMAL graphic is used instead then).
	 */
	public var allowHighlightOnMobile:Bool = false;
	/**
	 * Shows the current state of the button, either FlxButton.NORMAL, 
	 * FlxButton.HIGHLIGHT or FlxButton.PRESSED.
	 */
	public var status(default, set):Int;
	/**
	 * The properties of this button's onUp event (callback function, sound).
	 */
	public var onUp(default, null):FlxButtonEvent;
	/**
	 * The properties of this button's onDown event (callback function, sound).
	 */
	public var onDown(default, null):FlxButtonEvent;
	/**
	 * The properties of this button's onOver event (callback function, sound).
	 */
	public var onOver(default, null):FlxButtonEvent;
	/**
	 * The properties of this button's onOut event (callback function, sound).
	 */
	public var onOut(default, null):FlxButtonEvent;

	/**
	 * The touch currently pressing this button, if none, it's null. Needed to check for its release.
	 */
	private var _pressedTouch:FlxTouch;
	/**
	 * Whether this button is currently being pressed by the mouse. Needed to check for its release.
	 */
	private var _pressedMouse:Bool = false;
	
	/**
	 * Creates a new FlxTypedButton object with a gray background.
	 * 
	 * @param	X				The X position of the button.
	 * @param	Y				The Y position of the button.
	 * @param	Label			The text that you want to appear on the button.
	 * @param	OnClick			The function to call whenever the button is clicked.
	 */
	public function new(X:Float = 0, Y:Float = 0, ?Label:String, ?OnClick:Void->Void)
	{
		super(X, Y);
		
		loadGraphic(GraphicButton, true, false, 80, 20);
		
		onUp = new FlxButtonEvent(OnClick);
		onDown = new FlxButtonEvent();
		onOver = new FlxButtonEvent();
		onOut = new FlxButtonEvent();
		
		labelAlphas = [0.8, 1.0, 0.5];
		labelOffsets = [FlxPoint.get(), FlxPoint.get(), FlxPoint.get(0, 1)];
		
		status = FlxButton.NORMAL;
		
		// Since this is a UI element, the default scrollFactor is (0, 0)
		scrollFactor.set();
		
		#if !FLX_NO_MOUSE
		FlxG.stage.addEventListener(MouseEvent.MOUSE_UP, onUpEventListener);
		#end
	}
	
	/**
	 * Called by the game state when state is changed (if this object belongs to the state)
	 */
	override public function destroy():Void
	{
		label = FlxG.safeDestroy(label);
		
		onUp = FlxG.safeDestroy(onUp);
		onDown = FlxG.safeDestroy(onDown);
		onOver = FlxG.safeDestroy(onOver);
		onOut = FlxG.safeDestroy(onOut);
		
		if (labelOffsets != null)
		{
			for (point in labelOffsets)
			{
				point.put();
			}
		}
		
		labelOffsets = null;
		labelAlphas = null;
{'fraction_non_alphanumeric': 0.10614449696151249, 'fraction_numerical': 0.005941931127616476, 'mean_word_length': 3.6520100502512562, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5366406', 'n_tokens_mistral': 2566, 'n_tokens_neox': 2336, 'n_words': 808}