Skip to content

Commit cb0ea9a

Browse files
committed
Add disable animations property
1 parent ae42447 commit cb0ea9a

1 file changed

Lines changed: 64 additions & 7 deletions

File tree

src/Dialog.ts

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Container, Graphics, NineSliceSprite, ObservablePoint, Sprite, Texture, Ticker } from 'pixi.js';
1+
import { Container, Graphics, NineSliceSprite, ObservablePoint, Sprite, TextStyleOptions, Texture, Ticker } from 'pixi.js';
22
import { Group, Tween } from 'tweedle.js';
33
import { Signal } from 'typed-signals';
44
import { FancyButton } from './FancyButton';
@@ -8,6 +8,7 @@ import { getView, type GetViewSettings } from './utils/helpers/view';
88

99
export type DialogButton = {
1010
text: AnyText;
11+
button?: FancyButton;
1112
};
1213

1314
export type DialogOptions = {
@@ -24,8 +25,15 @@ export type DialogOptions = {
2425
buttons?: DialogButton[];
2526
scrollBox?: ScrollBoxOptions;
2627
animationDuration?: number;
28+
disableAnimations?: boolean;
2729
closeOnBackdropClick?: boolean;
2830
nineSliceSprite?: [number, number, number, number];
31+
buttonWidth?: number;
32+
buttonHeight?: number;
33+
buttonColor?: number;
34+
buttonHoverColor?: number;
35+
buttonPressedColor?: number;
36+
buttonTextStyle?: TextStyleOptions;
2937
};
3038

3139
/**
@@ -290,15 +298,48 @@ export class Dialog extends Container
290298

291299
const buttonConfigs = this.options.buttons;
292300
const buttonSpacing = 10;
301+
const defaultButtonWidth = this.options.buttonWidth ?? 100;
302+
const defaultButtonHeight = this.options.buttonHeight ?? 40;
303+
const defaultButtonColor = this.options.buttonColor ?? 0xA5E24D;
304+
const defaultButtonHoverColor = this.options.buttonHoverColor;
305+
const defaultButtonPressedColor = this.options.buttonPressedColor;
293306

294307
buttonConfigs.forEach((btnConfig, index) =>
295308
{
296-
const button = new FancyButton({
297-
defaultView: new Graphics()
298-
.roundRect(0, 0, 100, 40, this.options.radius ?? 10)
299-
.fill(0xA5E24D),
300-
text: btnConfig.text,
301-
});
309+
let button: FancyButton;
310+
311+
// Use provided button instance or create a new one
312+
if (btnConfig.button)
313+
{
314+
button = btnConfig.button;
315+
}
316+
else
317+
{
318+
const buttonOptions: any = {
319+
defaultView: new Graphics()
320+
.roundRect(0, 0, defaultButtonWidth, defaultButtonHeight, this.options.radius ?? 10)
321+
.fill(defaultButtonColor),
322+
text: btnConfig.text,
323+
};
324+
325+
// Add hover view if color is specified
326+
if (defaultButtonHoverColor)
327+
{
328+
buttonOptions.hoverView = new Graphics()
329+
.roundRect(0, 0, defaultButtonWidth, defaultButtonHeight, this.options.radius ?? 10)
330+
.fill(defaultButtonHoverColor);
331+
}
332+
333+
// Add pressed view if color is specified
334+
if (defaultButtonPressedColor)
335+
{
336+
buttonOptions.pressedView = new Graphics()
337+
.roundRect(0, 0, defaultButtonWidth, defaultButtonHeight, this.options.radius ?? 10)
338+
.fill(defaultButtonPressedColor);
339+
}
340+
341+
button = new FancyButton(buttonOptions);
342+
}
302343

303344
button.anchor.set(0);
304345

@@ -350,6 +391,14 @@ export class Dialog extends Container
350391
this.visible = true;
351392
this._isOpen = true;
352393

394+
if (this.options.disableAnimations)
395+
{
396+
this.backdrop.alpha = this.options.backdropAlpha ?? 0.5;
397+
this.innerView.scale.set(1);
398+
399+
return;
400+
}
401+
353402
this.backdrop.alpha = 0;
354403
this.innerView.scale.set(0.8);
355404

@@ -367,6 +416,14 @@ export class Dialog extends Container
367416
{
368417
if (!this.innerView) return;
369418

419+
if (this.options.disableAnimations)
420+
{
421+
this.visible = false;
422+
this._isOpen = false;
423+
424+
return;
425+
}
426+
370427
new Tween(this.backdrop)
371428
.to({ alpha: 0 }, this._animationDuration)
372429
.start();

0 commit comments

Comments
 (0)