@flashist/appframework 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/gulp/tasks/clean.js +9 -0
  2. package/gulp/tasks/compile.js +27 -0
  3. package/gulp/tasks/copy-to-dist.js +15 -0
  4. package/gulp/tasks/generate-definitions.js +86 -0
  5. package/gulpfile.js +22 -0
  6. package/package.json +30 -0
  7. package/src/app/AppModule.ts +26 -0
  8. package/src/app/AppSettings.ts +9 -0
  9. package/src/app/commands/LoadAppConfigCommand.ts +61 -0
  10. package/src/app/commands/ParseStaticItemsConfigCommand.ts +32 -0
  11. package/src/app/data/AppConfigType.ts +1 -0
  12. package/src/app/data/AppConfigVO.ts +27 -0
  13. package/src/app/data/IAppModelStorageVO.ts +4 -0
  14. package/src/app/data/IItemsConfigVO.ts +5 -0
  15. package/src/app/managers/AppManager.ts +68 -0
  16. package/src/app/models/AppConfigModel.ts +20 -0
  17. package/src/app/models/AppModel.ts +18 -0
  18. package/src/app/views/AppMainContainer.ts +23 -0
  19. package/src/assets/AssetsModule.ts +13 -0
  20. package/src/assets/commands/ParseAssetsConfigCommand.ts +25 -0
  21. package/src/assets/data/IAssetsConfigVO.ts +5 -0
  22. package/src/assets/models/AssetsModel.ts +7 -0
  23. package/src/base/BaseObjectWithGlobalDispatcher.ts +23 -0
  24. package/src/base/commands/BaseAppCommand.ts +22 -0
  25. package/src/base/data/BaseAppObjectWithStaticVO.ts +15 -0
  26. package/src/base/managers/BaseAppManager.ts +5 -0
  27. package/src/base/mediators/BaseAppMediator.ts +24 -0
  28. package/src/base/models/BaseAppGenericObjectsModel.ts +23 -0
  29. package/src/base/models/BaseAppModel.ts +5 -0
  30. package/src/base/modules/AppModulesManager.ts +44 -0
  31. package/src/base/modules/BaseAppModule.ts +17 -0
  32. package/src/base/views/BaseAppView.ts +25 -0
  33. package/src/containers/ContainersModule.ts +13 -0
  34. package/src/containers/managers/ContainersManager.ts +27 -0
  35. package/src/data/IAppGenericObjectVO.ts +5 -0
  36. package/src/date/DateSettings.ts +6 -0
  37. package/src/debug/DebugModule.ts +22 -0
  38. package/src/dependencies/DependenciesModule.ts +13 -0
  39. package/src/display/data/IGetSizable.ts +5 -0
  40. package/src/display/tools/GetSizeTools.ts +25 -0
  41. package/src/display/views/AppContainer.ts +20 -0
  42. package/src/display/views/button/BaseBtn.ts +325 -0
  43. package/src/display/views/button/BaseBtnEvent.ts +4 -0
  44. package/src/display/views/button/BaseBtnState.ts +31 -0
  45. package/src/display/views/button/BaseBtnView.ts +230 -0
  46. package/src/display/views/button/DefaultButtonViewConfig.ts +10 -0
  47. package/src/display/views/button/IButtonViewConfig.ts +16 -0
  48. package/src/display/views/button/ISimpleButtonConfig.ts +22 -0
  49. package/src/display/views/button/SimpleButtonState.ts +31 -0
  50. package/src/display/views/button/SimpleButtonView.ts +226 -0
  51. package/src/display/views/getsize/GetSizeTools.ts +32 -0
  52. package/src/display/views/getsize/IGetSizeObject.ts +5 -0
  53. package/src/display/views/layout/BaseLayout.ts +160 -0
  54. package/src/display/views/layout/ColumnLayout.ts +120 -0
  55. package/src/display/views/layout/LayoutConfig.ts +15 -0
  56. package/src/display/views/layout/RowLayout.ts +115 -0
  57. package/src/display/views/layout/container/BaseLayoutableContainer.ts +21 -0
  58. package/src/display/views/layout/container/ILayoutableChild.ts +3 -0
  59. package/src/display/views/layout/container/ILayoutableContainer.ts +18 -0
  60. package/src/display/views/resize/IResizable.ts +6 -0
  61. package/src/display/views/resize/ResizableContainer.ts +80 -0
  62. package/src/display/views/simplelist/ISimpleListItem.ts +5 -0
  63. package/src/display/views/simplelist/SimpleList.ts +318 -0
  64. package/src/display/views/simplelist/SimpleListEvent.ts +4 -0
  65. package/src/display/views/sizedistributor/ISizeDistributorChild.ts +5 -0
  66. package/src/display/views/sizedistributor/SizeDistributor.ts +129 -0
  67. package/src/display/views/sizedistributor/SizeDistributorConfig.ts +12 -0
  68. package/src/display/views/togglegroup/IToggableItem.ts +6 -0
  69. package/src/display/views/togglegroup/IToggleGroupItem.ts +6 -0
  70. package/src/display/views/togglegroup/ToggleGroup.ts +140 -0
  71. package/src/display/views/togglegroup/ToggleGroupEvent.ts +3 -0
  72. package/src/display/views/viewstack/IViewStackItem.ts +7 -0
  73. package/src/display/views/viewstack/ViewLazyCreationServiceLocatorStack.ts +19 -0
  74. package/src/display/views/viewstack/ViewLazyCreationStack.ts +47 -0
  75. package/src/display/views/viewstack/ViewStack.ts +93 -0
  76. package/src/display/views/viewstack/ViewStackLazyCreation.ts +45 -0
  77. package/src/events/commands/DispatchGlobalEventCommand.ts +22 -0
  78. package/src/facade/Facade.ts +194 -0
  79. package/src/facade/IFacadeOptions.ts +7 -0
  80. package/src/globaleventdispatcher/GlobalEventDispatcherModule.ts +16 -0
  81. package/src/globaleventdispatcher/commands/WaitGlobalEventCommand.ts +25 -0
  82. package/src/globaleventdispatcher/dispatcher/GlobalEventDispatcher.ts +53 -0
  83. package/src/globaleventdispatcher/dispatcher/GlobalEventDispatcherEvent.ts +4 -0
  84. package/src/globaleventdispatcher/dispatcher/IGlobalDispatchEventVO.ts +4 -0
  85. package/src/globaleventdispatcher/managers/GlobalEventsCommandManager.ts +26 -0
  86. package/src/hints/commands/AnimateHintCommand.ts +99 -0
  87. package/src/hints/data/DefaultHintConfig.ts +22 -0
  88. package/src/hints/data/HintContainerId.ts +1 -0
  89. package/src/hints/data/IHintConfig.ts +20 -0
  90. package/src/html/HTMLModule.ts +13 -0
  91. package/src/html/managers/HTMLManager.ts +32 -0
  92. package/src/index.ts +21 -0
  93. package/src/init/commands/InitApplicationCommand.ts +34 -0
  94. package/src/init/commands/InitApplicationDataCommand.ts +19 -0
  95. package/src/init/commands/InitApplicationDataEvent.ts +3 -0
  96. package/src/load/LoadGroupName.ts +5 -0
  97. package/src/load/LoadModule.ts +23 -0
  98. package/src/load/LoaderId.ts +5 -0
  99. package/src/locales/LocalesModule.ts +11 -0
  100. package/src/locales/commands/ParseLocaleConfigCommand.ts +28 -0
  101. package/src/package.json +36 -0
  102. package/src/pages/PageId.ts +4 -0
  103. package/src/pages/PagesModule.ts +13 -0
  104. package/src/pages/commands/ChangePageCommand.ts +18 -0
  105. package/src/pages/models/PagesModel.ts +38 -0
  106. package/src/pages/models/PagesModelEvent.ts +3 -0
  107. package/src/pages/views/BasePageView.ts +75 -0
  108. package/src/pages/views/PagesView.ts +57 -0
  109. package/src/pool/ObjectsPoolModule.ts +13 -0
  110. package/src/renderer/RendererModule.ts +14 -0
  111. package/src/renderer/events/RendererManagerEvent.ts +3 -0
  112. package/src/renderer/managers/RendererManager.ts +52 -0
  113. package/src/server/ServerModule.ts +14 -0
  114. package/src/server/commands/BaseServerCommand.ts +39 -0
  115. package/src/server/data/IServerRequestVO.ts +12 -0
  116. package/src/server/data/IServerResponseVO.ts +15 -0
  117. package/src/server/data/ServerErrorCode.ts +3 -0
  118. package/src/server/models/ServerModel.ts +34 -0
  119. package/src/sounds/SoundsModule.ts +24 -0
  120. package/src/sounds/SoundsSettings.ts +5 -0
  121. package/src/sounds/managers/BackgroundMusicManager.ts +48 -0
  122. package/src/sounds/managers/SoundsStorageManager.ts +45 -0
  123. package/src/storage/StorageModule.ts +13 -0
  124. package/src/storage/StorageModuleConfig.ts +3 -0
  125. package/src/storage/managers/StorageManager.ts +159 -0
  126. package/src/strategy/managers/BaseStrategyManager.ts +37 -0
  127. package/src/strategy/models/BaseStrategyModel.ts +40 -0
  128. package/src/strategy/strategies/BaseStrategy.ts +21 -0
  129. package/src/time/TimeModule.ts +16 -0
  130. package/src/time/managers/TimeManager.ts +29 -0
  131. package/src/time/models/TimeModel.ts +29 -0
  132. package/src/time/models/TimeModelEvent.ts +3 -0
  133. package/src/windows/data/IWindowConfigVO.ts +9 -0
  134. package/src/windows/managers/IShowWindowVO.ts +4 -0
  135. package/src/windows/managers/WindowsManager.ts +72 -0
  136. package/src/windows/views/BaseWindow.ts +22 -0
  137. package/tsconfig.json +19 -0
@@ -0,0 +1,230 @@
1
+ import {ObjectTools} from "@flashist/fcore";
2
+
3
+ import {DisplayResizeTools, FContainer, Graphics, Point, Sprite, Texture} from "@flashist/flibs";
4
+
5
+ import {IToggleGroupItem} from "../togglegroup/IToggleGroupItem";
6
+ import {BaseBtn} from "./BaseBtn";
7
+ import {IButtonViewConfig} from "./IButtonViewConfig";
8
+ import {ResizableContainer} from "../resize/ResizableContainer";
9
+ import {BaseBtnState} from "./BaseBtnState";
10
+ import {BaseBtnEvent} from "./BaseBtnEvent";
11
+ import {DefaultButtonViewConfig} from "./DefaultButtonViewConfig";
12
+
13
+ export class BaseBtnView<DataType extends object = object> extends ResizableContainer<DataType> implements IToggleGroupItem {
14
+
15
+ private static readonly DEFAULT_CONFIG: IButtonViewConfig = new DefaultButtonViewConfig();
16
+
17
+ protected static DEFAULT_SIZE: Point = new Point(30, 24);
18
+
19
+ private _config: IButtonViewConfig;
20
+
21
+ public id: string;
22
+
23
+ protected btn: BaseBtn;
24
+
25
+ protected contentCont: FContainer;
26
+
27
+ protected bg: Graphics;
28
+ protected icon: Sprite;
29
+ protected pressView: Sprite;
30
+ protected overView: Sprite;
31
+
32
+ constructor(config: IButtonViewConfig) {
33
+ super(config);
34
+ }
35
+
36
+ protected construction(config: IButtonViewConfig): void {
37
+ super.construction(config);
38
+
39
+ this._config = config;
40
+ if (!this._config) {
41
+ this._config = BaseBtnView.DEFAULT_CONFIG;
42
+ }
43
+ ObjectTools.copyProps(this._config, BaseBtnView.DEFAULT_CONFIG, {ignoreExistedProperties: true});
44
+
45
+ this.contentCont = new FContainer();
46
+ this.addChild(this.contentCont);
47
+
48
+ this.bg = new Graphics();
49
+ this.contentCont.addChild(this.bg);
50
+ this.bg.beginFill(0x000000);
51
+ this.bg.drawRect(0, 0, 10, 10);
52
+ this.bg.alpha = 0;
53
+
54
+ this.pressView = new Sprite();
55
+ this.contentCont.addChild(this.pressView);
56
+
57
+ this.overView = new Sprite();
58
+ this.contentCont.addChild(this.overView);
59
+
60
+ this.icon = new Sprite();
61
+ this.contentCont.addChild(this.icon);
62
+
63
+ this.btn = new BaseBtn();
64
+ this.btn.hitArea = this;
65
+ // this.btn.commitStateDataCallback = () => this.commitStateData();
66
+
67
+ if (config.size) {
68
+ this.resize(config.size.x, config.size.y);
69
+ } else {
70
+ this.resize(BaseBtnView.DEFAULT_SIZE.x, BaseBtnView.DEFAULT_SIZE.y);
71
+ }
72
+
73
+ this.commitStateData();
74
+ }
75
+
76
+ destruction(): void {
77
+ super.destruction();
78
+
79
+ if (this.btn) {
80
+ this.btn.destruction();
81
+ }
82
+ }
83
+
84
+ protected addListeners(): void {
85
+ super.addListeners();
86
+
87
+ this.eventListenerHelper.addEventListener(
88
+ this.btn,
89
+ BaseBtnEvent.STATE_CHANGE,
90
+ this.onBtnStateChange
91
+ );
92
+
93
+ this.eventListenerHelper.addEventListener(
94
+ this.btn,
95
+ BaseBtnEvent.SELECTED_CHANGE,
96
+ this.onBtnSelectedChange
97
+ );
98
+ }
99
+
100
+ protected onBtnStateChange(): void {
101
+ this.commitStateData();
102
+
103
+ this.emit(BaseBtnEvent.STATE_CHANGE);
104
+ }
105
+
106
+ protected onBtnSelectedChange(): void {
107
+ this.emit(BaseBtnEvent.SELECTED_CHANGE);
108
+ }
109
+
110
+
111
+ protected commitData(): void {
112
+ super.commitData();
113
+
114
+ if (this.config.pressTextureId) {
115
+ this.pressView.texture = Texture.from(this.config.pressTextureId);
116
+ }
117
+
118
+ if (this.config.overTextureId) {
119
+ this.overView.texture = Texture.from(this.config.overTextureId);
120
+ }
121
+
122
+ if (this.config.iconTextureId) {
123
+ this.icon.texture = Texture.from(this.config.iconTextureId);
124
+ }
125
+
126
+ this.commitStateData();
127
+ }
128
+
129
+ protected commitStateData(): void {
130
+
131
+ this.contentCont.visible = true;
132
+ this.pressView.visible = false;
133
+ this.overView.visible = false;
134
+
135
+ let newAlpha: number = 1;
136
+
137
+ switch (this.btn.state) {
138
+ case BaseBtnState.NORMAL:
139
+ if (this.config.alphaNormal) {
140
+ newAlpha = this.config.alphaNormal;
141
+ }
142
+ break;
143
+ case BaseBtnState.OVER:
144
+ if (this.config.alphaOver) {
145
+ newAlpha = this.config.alphaOver;
146
+ }
147
+ this.overView.visible = true;
148
+ break;
149
+ case BaseBtnState.PRESS:
150
+ this.pressView.visible = true;
151
+ break;
152
+
153
+ case BaseBtnState.SELECTED_NORMAL:
154
+ if (this.config.alphaNormal) {
155
+ newAlpha = this.config.alphaNormal;
156
+ }
157
+ this.pressView.visible = true;
158
+ break;
159
+ case BaseBtnState.SELECTED_OVER:
160
+ if (this.config.alphaOver) {
161
+ newAlpha = this.config.alphaOver;
162
+ }
163
+
164
+ this.overView.visible = true;
165
+ this.pressView.visible = true;
166
+ break;
167
+ case BaseBtnState.SELECTED_PRESS:
168
+ this.pressView.visible = true;
169
+ break;
170
+ default:
171
+ this.contentCont.visible = true;
172
+ break;
173
+ }
174
+
175
+ this.alpha = newAlpha;
176
+
177
+ if (this.isConstructed) {
178
+ this.arrange();
179
+ }
180
+ }
181
+
182
+ public get selected(): boolean {
183
+ return this.btn.selected;
184
+ }
185
+
186
+ public set selected(value: boolean) {
187
+ if (value === this.btn.selected) {
188
+ return;
189
+ }
190
+
191
+ this.btn.selected = value;
192
+ }
193
+
194
+ protected arrange(): void {
195
+ super.arrange();
196
+
197
+ this.bg.width = this.resizeSize.x;
198
+ this.bg.height = this.resizeSize.y;
199
+
200
+ this.icon.scale.set(1, 1);
201
+ DisplayResizeTools.scaleObject(
202
+ this.icon,
203
+ this.resizeSize.x - (this.config.iconPadding.x * 2),
204
+ this.resizeSize.y - (this.config.iconPadding.y * 2)
205
+ );
206
+ this.overView.scale.set(1, 1);
207
+ DisplayResizeTools.scaleObject(this.overView, this.resizeSize.x, this.resizeSize.y);
208
+ this.pressView.scale.set(1, 1);
209
+ DisplayResizeTools.scaleObject(this.pressView, this.resizeSize.x, this.resizeSize.y);
210
+
211
+ this.overView.x = Math.floor(this.bg.x + ((this.bg.width - this.overView.width) / 2));
212
+ this.overView.y = Math.floor(this.bg.y + ((this.bg.height - this.overView.height) / 2));
213
+
214
+ this.pressView.x = Math.floor(this.bg.x + ((this.bg.width - this.pressView.width) / 2));
215
+ this.pressView.y = Math.floor(this.bg.y + ((this.bg.height - this.pressView.height) / 2));
216
+
217
+ this.icon.x = Math.floor(this.bg.x + ((this.bg.width - this.icon.width) / 2));
218
+ this.icon.y = Math.floor(this.bg.y + ((this.bg.height - this.icon.height) / 2));
219
+ }
220
+
221
+ get config(): IButtonViewConfig {
222
+ return this._config;
223
+ }
224
+
225
+ set config(value: IButtonViewConfig) {
226
+ this._config = value;
227
+
228
+ this.commitData();
229
+ }
230
+ }
@@ -0,0 +1,10 @@
1
+ import {Point} from "@flashist/flibs";
2
+
3
+ import {IButtonViewConfig} from "./IButtonViewConfig";
4
+
5
+ export class DefaultButtonViewConfig implements IButtonViewConfig {
6
+ iconPadding: Point = new Point();
7
+ iconTextureId: string = "";
8
+ pressTextureId: string = "tools_press_bg.png";
9
+ overTextureId: string = "tools_over_bg.png";
10
+ }
@@ -0,0 +1,16 @@
1
+ import {Point} from "@flashist/flibs";
2
+
3
+ export interface IButtonViewConfig {
4
+ iconTextureId?: string;
5
+ iconPadding?: Point;
6
+ pressTextureId?: string;
7
+ overTextureId?: string;
8
+
9
+ size?: {
10
+ x: number,
11
+ y: number
12
+ };
13
+
14
+ alphaNormal?: number;
15
+ alphaOver?: number;
16
+ }
@@ -0,0 +1,22 @@
1
+ import {IFLabelConfig} from "@flashist/flibs";
2
+
3
+ export interface ISimpleButtonConfig {
4
+ bgConfig?: {
5
+ image?: {
6
+ imageId: string;
7
+ };
8
+
9
+ vector?: {
10
+ bgColor: number;
11
+ overBgColor: number;
12
+ bgAlpha: number;
13
+ bgBorderColor: number;
14
+ bgBorderAlpha: number;
15
+ bgBorderWidth: number;
16
+ }
17
+
18
+ resizeBg: boolean;
19
+ };
20
+
21
+ labelConfig?: IFLabelConfig;
22
+ }
@@ -0,0 +1,31 @@
1
+ export class SimpleButtonState {
2
+ public static NORMAL:string = "normal";
3
+ public static OVER:string = "over";
4
+ public static PRESS:string = "press";
5
+ public static DISABLED:string = "disabled";
6
+
7
+ public static SELECTED_NORMAL:string = "selected_normal";
8
+ public static SELECTED_OVER:string = "selected_over";
9
+ public static SELECTED_PRESS:string = "selected_press";
10
+ public static SELECTED_DISABLED:string = "selected_disabled";
11
+
12
+ public static NORMAL_TO_SELECTED_MAP = ((): any => {
13
+ let result = {};
14
+ result[SimpleButtonState.NORMAL] = SimpleButtonState.SELECTED_NORMAL;
15
+ result[SimpleButtonState.OVER] = SimpleButtonState.SELECTED_OVER;
16
+ result[SimpleButtonState.PRESS] = SimpleButtonState.SELECTED_PRESS;
17
+ result[SimpleButtonState.DISABLED] = SimpleButtonState.SELECTED_DISABLED;
18
+
19
+ return result;
20
+ })();
21
+
22
+ public static SELECTED_TO_NORMAL_MAP = ((): any => {
23
+ let result = {};
24
+ result[SimpleButtonState.SELECTED_NORMAL] = SimpleButtonState.NORMAL;
25
+ result[SimpleButtonState.SELECTED_OVER] = SimpleButtonState.OVER;
26
+ result[SimpleButtonState.SELECTED_PRESS] = SimpleButtonState.PRESS;
27
+ result[SimpleButtonState.SELECTED_DISABLED] = SimpleButtonState.DISABLED;
28
+
29
+ return result;
30
+ })();
31
+ }
@@ -0,0 +1,226 @@
1
+ import {FContainer, FLabel, Graphics, InteractiveEvent, Sprite} from "@flashist/flibs";
2
+
3
+ import {ISimpleButtonConfig} from "./ISimpleButtonConfig";
4
+ import {SimpleButtonState} from "./SimpleButtonState";
5
+ import {ResizableContainer} from "../resize/ResizableContainer";
6
+ import {IToggableItem} from "../togglegroup/IToggableItem";
7
+
8
+ export class SimpleButtonView<DataType extends object = object> extends ResizableContainer<DataType> implements IToggableItem {
9
+
10
+ public id: string;
11
+
12
+ private _enabled: boolean;
13
+ protected _state: string;
14
+ protected _selected: boolean;
15
+
16
+ protected config: ISimpleButtonConfig;
17
+
18
+ protected contentCont: FContainer;
19
+ protected bg: Graphics | Sprite;
20
+ protected label: FLabel;
21
+
22
+ constructor(config: ISimpleButtonConfig) {
23
+ super(config);
24
+ }
25
+
26
+ protected construction(config: ISimpleButtonConfig): void {
27
+ super.construction();
28
+
29
+ this.config = config;
30
+
31
+ this.contentCont = new FContainer();
32
+ this.addChild(this.contentCont);
33
+
34
+ this.bg = this.createBg();
35
+ this.contentCont.addChild(this.bg);
36
+
37
+ this.label = new FLabel(this.config.labelConfig);
38
+ this.contentCont.addChild(this.label);
39
+ //
40
+ this.label.interactive = false;
41
+ this.label.interactiveChildren = false;
42
+
43
+ this.state = SimpleButtonState.NORMAL;
44
+ this.enabled = true;
45
+
46
+ if (!this.config.bgConfig.resizeBg) {
47
+ this.resize(
48
+ this.bg.width,
49
+ this.bg.height
50
+ );
51
+ }
52
+ }
53
+
54
+ protected addListeners(): void {
55
+ super.addListeners();
56
+
57
+ this.eventListenerHelper.addEventListener(
58
+ this,
59
+ InteractiveEvent.OVER,
60
+ this.onOver
61
+ );
62
+ this.eventListenerHelper.addEventListener(
63
+ this,
64
+ InteractiveEvent.OUT,
65
+ this.onOut
66
+ );
67
+ this.eventListenerHelper.addEventListener(
68
+ this,
69
+ InteractiveEvent.TAP,
70
+ this.onTap
71
+ );
72
+ this.eventListenerHelper.addEventListener(
73
+ this,
74
+ InteractiveEvent.UP_OUTSIDE,
75
+ this.onOut
76
+ );
77
+ }
78
+
79
+ private onOver(): void {
80
+ // this.contentCont.alpha = 1;
81
+ this.state = this.findStateValue(SimpleButtonState.OVER);
82
+ }
83
+
84
+ private onOut(): void {
85
+ // this.contentCont.alpha = 0.75;
86
+ this.state = this.findStateValue(SimpleButtonState.NORMAL);
87
+ }
88
+
89
+ protected onTap(): void {
90
+ // this.onOut();
91
+ }
92
+
93
+ protected arrange(): void {
94
+ super.arrange();
95
+
96
+ if (this.config.bgConfig.resizeBg) {
97
+ if (this.bg.width !== this.resizeSize.x ||
98
+ this.bg.height !== this.resizeSize.y) {
99
+
100
+ this.updateBg();
101
+ }
102
+ }
103
+
104
+ this.label.width = this.bg.width;
105
+ this.label.height = this.bg.height;
106
+ this.label.x = this.bg.x + Math.floor((this.bg.width - this.label.width) / 2);
107
+ this.label.y = this.bg.y + Math.floor((this.bg.height - this.label.height) / 2);
108
+ }
109
+
110
+ get enabled(): boolean {
111
+ return this._enabled;
112
+ }
113
+ set enabled(value: boolean) {
114
+ if (value === this._enabled) {
115
+ return;
116
+ }
117
+
118
+ this._enabled = value;
119
+
120
+ this.commitData();
121
+ }
122
+
123
+ public get text(): string {
124
+ return this.label.text;
125
+ }
126
+ public set text(value: string) {
127
+ this.label.text = value;
128
+ this.arrange();
129
+ }
130
+
131
+ public get state(): string {
132
+ return this._state;
133
+ }
134
+ public set state(value: string) {
135
+ if (value == this.state) {
136
+ return;
137
+ }
138
+
139
+ this._state = value;
140
+
141
+ this.commitData();
142
+ }
143
+
144
+ protected commitData(): void {
145
+ super.commitData();
146
+
147
+ if (this.enabled) {
148
+ this.interactive = true;
149
+ this.alpha = 1;
150
+
151
+ } else {
152
+ this.interactive = false;
153
+ this.alpha = 0.5;
154
+ }
155
+
156
+ this.updateBg();
157
+ }
158
+
159
+ public get selected(): boolean {
160
+ return this._selected;
161
+ }
162
+ public set selected(value: boolean) {
163
+ if (value == this.selected) {
164
+ return;
165
+ }
166
+
167
+ this._selected = value;
168
+
169
+ this.state = this.findStateValue(SimpleButtonState.NORMAL);
170
+ }
171
+
172
+ protected findStateValue(normalState: string): string {
173
+ let result: string;
174
+
175
+ if (this.selected) {
176
+ result = SimpleButtonState.NORMAL_TO_SELECTED_MAP[normalState];
177
+ }
178
+
179
+ if (!result) {
180
+ result = normalState;
181
+ }
182
+
183
+ return result;
184
+ }
185
+
186
+ protected createBg(): Sprite | Graphics {
187
+ let result: Sprite | Graphics;
188
+ if (this.config.bgConfig.image) {
189
+ result = Sprite.from(this.config.bgConfig.image.imageId);
190
+
191
+ } else {
192
+ result = new Graphics();
193
+ }
194
+
195
+ return result;
196
+ }
197
+
198
+ protected updateBg(): void {
199
+ if (this.config.bgConfig.image) {
200
+ if (this.config.bgConfig.resizeBg) {
201
+ this.bg.width = this.resizeSize.x;
202
+ this.bg.height = this.resizeSize.y;
203
+ }
204
+
205
+ } else {
206
+ const vectorBg: Graphics = this.bg as Graphics;
207
+
208
+ vectorBg.clear();
209
+
210
+ let bgColor: number = this.config.bgConfig.vector.bgColor;
211
+ if (this.state === SimpleButtonState.SELECTED_NORMAL || this.state === SimpleButtonState.OVER || this.state === SimpleButtonState.SELECTED_OVER) {
212
+ bgColor = this.config.bgConfig.vector.overBgColor;
213
+ }
214
+
215
+ vectorBg.beginFill(bgColor, this.config.bgConfig.vector.bgAlpha);
216
+ vectorBg.lineStyle(
217
+ this.config.bgConfig.vector.bgBorderWidth,
218
+ this.config.bgConfig.vector.bgBorderColor,
219
+ this.config.bgConfig.vector.bgBorderAlpha,
220
+ 0
221
+ );
222
+ vectorBg.drawRect(0, 0, this.resizeSize.x, this.resizeSize.y);
223
+ vectorBg.endFill();
224
+ }
225
+ }
226
+ }
@@ -0,0 +1,32 @@
1
+ import {DisplayObjectContainer, Point} from "@flashist/flibs";
2
+ import {IGetSizeObject} from "./IGetSizeObject";
3
+
4
+ export class GetSizeTools {
5
+
6
+ /**
7
+ * Получение размера объекта.
8
+ *
9
+ * @param sourceObject
10
+ *
11
+ * @return
12
+ */
13
+ static getObjectSize(sourceObject: DisplayObjectContainer): Point {
14
+ let result: Point = new Point();
15
+
16
+ let getSizeObject: IGetSizeObject = (sourceObject as any as IGetSizeObject);
17
+ if (getSizeObject.getSize) {
18
+ result = getSizeObject.getSize();
19
+
20
+ } else {
21
+ if (sourceObject.width) {
22
+ result.x = sourceObject.width;
23
+ }
24
+ if (sourceObject.height) {
25
+ result.y = sourceObject.height;
26
+ }
27
+ }
28
+
29
+ return result;
30
+ }
31
+
32
+ }
@@ -0,0 +1,5 @@
1
+ import {Point} from "@flashist/flibs";
2
+
3
+ export interface IGetSizeObject {
4
+ getSize():Point;
5
+ }