2018-05-15 14:57:45 +00:00
|
|
|
module TK.SpaceTac.UI {
|
2018-06-05 22:34:03 +00:00
|
|
|
export interface UIGraphicsCircleOptions {
|
|
|
|
center?: { x: number, y: number }
|
|
|
|
radius: number
|
|
|
|
fill?: { color: number, alpha?: number }
|
|
|
|
border?: { color: number, width?: number, alpha?: number }
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UIGraphicsCirclePortionOptions extends UIGraphicsCircleOptions {
|
|
|
|
angle: { start: number, span: number }
|
|
|
|
}
|
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* UI component that supports drawing simple shapes (circles, lines...)
|
|
|
|
*/
|
|
|
|
export class UIGraphics extends Phaser.GameObjects.Graphics {
|
|
|
|
constructor(view: BaseView, name: string, visible = true, x = 0, y = 0) {
|
|
|
|
super(view, {});
|
|
|
|
this.setName(name);
|
|
|
|
this.setVisible(visible);
|
|
|
|
this.setPosition(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a rectangle
|
|
|
|
*/
|
|
|
|
addRectangle(shape: IBounded, color: number, border_width = 0, border_color?: number, alpha = 1): void {
|
|
|
|
let rect = new Phaser.Geom.Rectangle(shape.x, shape.y, shape.width, shape.height);
|
|
|
|
|
|
|
|
this.fillStyle(color, alpha);
|
|
|
|
this.fillRectShape(rect);
|
|
|
|
if (border_width && border_color) {
|
|
|
|
this.lineStyle(border_width, border_color, alpha);
|
|
|
|
this.strokeRectShape(rect);
|
|
|
|
}
|
|
|
|
}
|
2018-06-05 22:34:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a portion of circle
|
|
|
|
*/
|
|
|
|
addCircleArc(options: UIGraphicsCirclePortionOptions): void {
|
|
|
|
let x = options.center ? options.center.x : 0;
|
|
|
|
let y = options.center ? options.center.y : 0;
|
|
|
|
|
|
|
|
if (options.fill) {
|
|
|
|
this.fillStyle(options.fill.color, options.fill.alpha);
|
|
|
|
this.slice(x, y, options.radius, options.angle.start, options.angle.start + options.angle.span, false);
|
|
|
|
this.fillPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.border) {
|
|
|
|
this.lineStyle(options.border.width || 1, options.border.color, options.border.alpha);
|
|
|
|
this.slice(x, y, options.radius, options.angle.start, options.angle.start + options.angle.span, false);
|
|
|
|
this.strokePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a full circle
|
|
|
|
*/
|
|
|
|
addCircle(options: UIGraphicsCircleOptions): void {
|
|
|
|
let x = options.center ? options.center.x : 0;
|
|
|
|
let y = options.center ? options.center.y : 0;
|
|
|
|
|
|
|
|
if (options.fill) {
|
|
|
|
this.fillStyle(options.fill.color, options.fill.alpha);
|
|
|
|
this.fillCircle(x, y, options.radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.border) {
|
|
|
|
this.lineStyle(options.border.width || 1, options.border.color, options.border.alpha);
|
|
|
|
this.strokeCircle(x, y, options.radius);
|
|
|
|
}
|
|
|
|
}
|
2018-05-15 14:57:45 +00:00
|
|
|
}
|
|
|
|
}
|