import { IDisplayObjectContainerWrapper , EngineAdapter , IGraphicsWrapper , ITextWrapper } from "fgraphics/dist/index" ; import { BaseEventListenerObject , EventListenerHelper } from "fcore/dist/index" ; import { DragHelper , DragHelperEvent } from "flibs/dist/index" ; import { BaseConsoleButton } from "./BaseConsoleButton" ; import { FC } from "../FC" ; import { CaptureKeyButton } from "./capturekey/CaptureKeyButton" ; import { CaptuerKeyButtonEvent } from "./capturekey/CaptureKeyButtonEvent" ; import { ITooltipData } from "../../tooltip/ITooltipData" ; export class BaseConsoleView extends BaseEventListenerObject { private static CAPTURE_LABEL_FIRST_PART : string = "Capture key:" ; private static NO_CAPTURE_KEY_TEXT : string = "(click to add)" ; public view : IDisplayObjectContainerWrapper ; private bgGraphics : IGraphicsWrapper ; protected contentCont : IDisplayObjectContainerWrapper ; protected titleCont : IDisplayObjectContainerWrapper ; protected insideContentCont : IDisplayObjectContainerWrapper ; private _visible : boolean ; private dragHelper : DragHelper ; private viewDragStartX : number ; private viewDragStartY : number ; private buttonsList : BaseConsoleButton [ ] ; private btnsCont : IDisplayObjectContainerWrapper ; private buttonsEventListenerHelper : EventListenerHelper < string > ; protected titleLabel : ITextWrapper ; private _titleVisible : boolean ; protected captureBtn : BaseConsoleButton ; private _captureVisible : boolean ; public lastBgWidth : number = 0 ; public lastBgHeight : number = 0 ; constructor ( ) { super ( ) ; } protected construction ( ) { super . construction ( ) ; this . _titleVisible = true ; this . _captureVisible = false ; this . buttonsList = [ ] ; this . buttonsEventListenerHelper = new EventListenerHelper < string > ( this ) ; this . view = EngineAdapter . instance . createDisplayObjectContainerWrapper ( ) ; this . bgGraphics = EngineAdapter . instance . createGraphicsWrapper ( ) ; this . view . addChild ( this . bgGraphics ) ; this . bgGraphics . interactive = true ; this . dragHelper = new DragHelper ( ) ; this . dragHelper . view = ( this . bgGraphics as any ) ; this . contentCont = EngineAdapter . instance . createDisplayObjectContainerWrapper ( ) ; this . view . addChild ( this . contentCont ) ; this . titleCont = EngineAdapter . instance . createDisplayObjectContainerWrapper ( ) ; this . contentCont . addChild ( this . titleCont ) ; this . titleLabel = EngineAdapter . instance . createTextWrapper ( ) ; this . titleCont . addChild ( this . titleLabel ) ; this . titleLabel . color = FC . config . viewSettings . titleLabelColor ; this . titleLabel . size = FC . config . viewSettings . titleLabelSize ; this . titleLabel . text = "Test Title" ; this . btnsCont = EngineAdapter . instance . createDisplayObjectContainerWrapper ( ) ; this . titleCont . addChild ( this . btnsCont ) ; this . captureBtn = new CaptureKeyButton ( ) ; this . titleCont . addChild ( this . captureBtn . view ) ; this . captureBtn . view . y = this . titleLabel . y + this . titleLabel . height ; this . captureBtn . tooltipData = { title : FC . config . localization . captureKeyBtnTooltipTitle } ; this . insideContentCont = EngineAdapter . instance . createDisplayObjectContainerWrapper ( ) ; this . contentCont . addChild ( this . insideContentCont ) ; } public destruction ( ) { super . destruction ( ) ; if ( this . buttonsEventListenerHelper ) { this . buttonsEventListenerHelper . destruction ( ) ; this . buttonsEventListenerHelper = null ; } } protected addListeners ( ) { super . addListeners ( ) ; this . eventListenerHelper . addEventListener ( this . dragHelper , DragHelperEvent . DRAG_START , this . onDragStart ) ; this . eventListenerHelper . addEventListener ( this . dragHelper , DragHelperEvent . DRAG_UPDATE , this . onDragUpdate ) ; this . eventListenerHelper . addEventListener ( this . captureBtn , CaptuerKeyButtonEvent . CAPTURE_KEY_PRESS , this . onCaptureKey ) ; } private onDragStart ( ) { this . viewDragStartX = this . view . x ; this . viewDragStartY = this . view . y ; FC . moveViewToTopLayer ( this ) ; } private onDragUpdate ( ) { this . view . x = this . viewDragStartX + this . dragHelper . changeDragGlobalX ; this . view . y = this . viewDragStartY + this . dragHelper . changeDragGlobalY ; } protected onClose ( ) { FC . hideView ( this ) ; } protected onCaptureKey ( ) { } public get visible ( ) : boolean { return this . _visible ; } public set visible ( value ) { if ( value == this . visible ) { return ; } this . _visible = value ; this . commitData ( ) ; } protected commitData ( ) { super . commitData ( ) ; this . titleLabel . visible = this . titleVisible ; this . captureBtn . view . visible = this . captureVisible ; this . arrange ( ) ; } protected arrange ( ) { let tempBtn ; let prevBtn ; let btnsCount = this . buttonsList . length ; for ( let btnIndex = 0 ; btnIndex < btnsCount ; btnIndex ++ ) { tempBtn = this . buttonsList [ btnIndex ] ; if ( prevBtn ) { tempBtn . view . x = prevBtn . view . x + prevBtn . view . width + 5 ; } prevBtn = tempBtn ; } if ( this . titleVisible ) { this . btnsCont . x = this . titleLabel . x + this . titleLabel . width + 10 ; } else { this . btnsCont . x = this . titleLabel . x ; } if ( this . insideContentCont . visible ) { this . insideContentCont . y = this . titleCont . y + this . titleCont . height ; } else { this . insideContentCont . y = 0 ; } let tempWidth = this . contentCont . width + FC . config . viewSettings . bgToContentShift . x ; let tempHeight = this . contentCont . height + FC . config . viewSettings . bgToContentShift . y ; if ( tempWidth != this . lastBgWidth || tempHeight != this . lastBgHeight ) { this . lastBgWidth = tempWidth ; this . lastBgHeight = tempHeight ; this . bgGraphics . clear ( ) ; this . bgGraphics . beginFill ( FC . config . viewSettings . bgColor , FC . config . viewSettings . bgAlpha ) ; this . bgGraphics . lineStyle ( FC . config . viewSettings . borderWidth , FC . config . viewSettings . borderColor , FC . config . viewSettings . borderAlpha ) ; this . bgGraphics . drawRect ( 0 , 0 , tempWidth , tempHeight ) ; this . bgGraphics . endFill ( ) ; } this . contentCont . x = this . bgGraphics . x + ( ( this . bgGraphics . width - this . contentCont . width ) >> 1 ) ; this . contentCont . y = this . bgGraphics . y + ( ( this . bgGraphics . height - this . contentCont . height ) >> 1 ) ; } protected createTitleBtn ( label , tooltipData ? ) { let tempBtn = new BaseConsoleButton ( ) ; this . btnsCont . addChild ( tempBtn . view ) ; tempBtn . label = label ; tempBtn . tooltipData = tooltipData ; this . buttonsList . push ( tempBtn ) ; return tempBtn ; } get titleVisible ( ) : boolean { return this . _titleVisible ; } set titleVisible ( value ) { if ( value == this . titleVisible ) { return ; } this . _titleVisible = value ; this . commitData ( ) ; } get captureVisible ( ) : boolean { return this . _captureVisible ; } set captureVisible ( value ) { if ( value == this . captureVisible ) { return ; } this . _captureVisible = value ; this . commitData ( ) ; } }