Commit ef6224d3 authored by haiyoucuv's avatar haiyoucuv

1

parent 3c9f90c7
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/qcs.iml" filepath="$PROJECT_DIR$/.idea/qcs.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager">
<list default="true" id="6d7f36c9-7613-4f12-9933-91b1cd2225cf" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/default.res.json" beforeDir="false" afterPath="$PROJECT_DIR$/egret/resource/default.res.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/default.thm.json" beforeDir="false" afterPath="$PROJECT_DIR$/egret/resource/default.thm.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/skins/MyPrizeItemSkin.exml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/skins/MyPrizeSceneSkin.exml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/skins/NoMorePanelSkin.exml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/skins/NoPrizePanelSkin.exml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/skins/NoTImesPanelSkin.exml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/egret/resource/skins/PrizePanelSkin.exml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/egret/src/Panels/TurnTablePanel/TurnTablePanel.ts" beforeDir="false" afterPath="$PROJECT_DIR$/egret/src/Panels/TurnTablePanel/TurnTablePanel.ts" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FindInProjectRecents">
<replaceStrings>
<replace />
</replaceStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="qx_qcs_20190906" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectConfigurationFiles">
<option name="files">
<list>
<option value="$PROJECT_DIR$/.idea/qcs.iml" />
<option value="$PROJECT_DIR$/.idea/vcs.xml" />
<option value="$PROJECT_DIR$/.idea/misc.xml" />
<option value="$PROJECT_DIR$/.idea/modules.xml" />
</list>
</option>
</component>
<component name="ProjectId" id="1SHpG2fOzn71sKVJU3FZKToPNBc" />
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/egret/src" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" /> <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" /> <property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="prettierjs.PrettierConfiguration.Package" value="$PROJECT_DIR$/node_modules/prettier" />
<property name="ts.external.directory.path" value="$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/egret/src/Panels" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/egret/src" />
</key>
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
...@@ -72,61 +16,4 @@ ...@@ -72,61 +16,4 @@
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager">
<configuration name="build.js" type="NodeJSConfigurationType" temporary="true" nameIsGenerated="true" path-to-js-file="build.js" working-dir="$PROJECT_DIR$">
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Node.js.build.js" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="6d7f36c9-7613-4f12-9933-91b1cd2225cf" name="Default Changelist" comment="" />
<created>1568254772505</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1568254772505</updated>
<workItem from="1568254773776" duration="1466000" />
<workItem from="1568257307246" duration="3000" />
<workItem from="1571230277900" duration="16000" />
<workItem from="1573611813763" duration="332000" />
<<<<<<< HEAD
<workItem from="1573612228867" duration="11921000" />
=======
<workItem from="1573612228867" duration="11325000" />
>>>>>>> 9d40bdee21c87d5752a4949bdfcacf56400a40a5
</task>
<servers />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
<is-autoscroll-to-source value="true" />
</todo-panel>
<todo-panel id="all">
<are-packages-shown value="true" />
<is-autoscroll-to-source value="true" />
</todo-panel>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="COLUMN_ORDER" />
</State>
</value>
</entry>
</map>
</option>
</component>
</project> </project>
\ No newline at end of file
...@@ -22,7 +22,8 @@ export class GDispatcher { ...@@ -22,7 +22,8 @@ export class GDispatcher {
} }
const index: number = this.callbackPool[name].indexOf(callback); const index: number = this.callbackPool[name].indexOf(callback);
if (index != -1) { const thisObjIndex: number = this.thisObjPool[name].indexOf(thisObj);
if (index != -1 && thisObjIndex != -1) {
this.callbackPool[name][index] = callback; this.callbackPool[name][index] = callback;
this.thisObjPool[name][index] = thisObj; this.thisObjPool[name][index] = thisObj;
} else { } else {
......
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
"resource/skins/LoadingSkin.exml", "resource/skins/LoadingSkin.exml",
"resource/skins/RulePanelSkin.exml", "resource/skins/RulePanelSkin.exml",
"resource/skins/ToastPanelSkin.exml", "resource/skins/ToastPanelSkin.exml",
"resource/skins/Objs/OptionPanelSkin.exml",
"resource/skins/Objs/CropSkin.exml", "resource/skins/Objs/CropSkin.exml",
"resource/skins/Objs/LandSkin.exml", "resource/skins/Objs/LandSkin.exml",
"resource/skins/Component/TimeProgressBarSkin.exml",
"resource/skins/ui/IconButtonSkin.exml", "resource/skins/ui/IconButtonSkin.exml",
"resource/skins/ui/ProgressBarSkin.exml", "resource/skins/ui/ProgressBarSkin.exml"
"resource/skins/ui/TimeProgressBarSkin.exml"
], ],
"path": "resource/default.thm.json" "path": "resource/default.thm.json"
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<e:Skin class="TimeProgressBarSkin" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing" width="186" height="31">
<e:Rect id="bg" fillColor="0xffffff" left="0" top="0" bottom="0" right="0" ellipseWidth="13" ellipseHeight="13"/>
<e:Label id="corpName" text="鸡" size="16" textColor="0x000000" horizontalCenter="-70" verticalCenter="0"/>
<e:Group width="139" height="29" verticalCenter="0" left="46">
<e:Rect id="progressBar" ellipseWidth="13" ellipseHeight="13" width="139" height="29" fillColor="0x643b14" x="0" y="0"/>
<e:Rect id="fillMask" ellipseWidth="13" ellipseHeight="13" width="139" height="29" fillColor="0x643B14" x="0" y="0"/>
<e:Rect id="progressFill" ellipseWidth="13" ellipseHeight="13" width="69.5" height="29" fillColor="0xd52c25" x="0" y="0"/>
<e:Label id="progressLabel" text="23时54分后喂食" size="16" scaleX="1" scaleY="1" textColor="0xffffff" horizontalCenter="0" verticalCenter="0"/>
</e:Group>
</e:Skin>
\ No newline at end of file
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
<e:Skin class="LoadingSceneSkin" width="750" height="1624" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing" xmlns:ns1="*"> <e:Skin class="LoadingSceneSkin" width="750" height="1624" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing" xmlns:ns1="*">
<w:Config id="16e64c53e86"/> <w:Config id="16e64c53e86"/>
<e:Group verticalCenter="0" horizontalCenter="0" height="1624" width="750"> <e:Group verticalCenter="0" horizontalCenter="0" height="1624" width="750">
<e:Image source="index_bg_png" horizontalCenter="0" verticalCenter="0" x="0" y="0" scaleX="1" scaleY="1"/> <e:Image id="bg" source="index_bg_png" horizontalCenter="-1" verticalCenter="0" x="0" y="0" scaleX="1" scaleY="1"/>
<e:Group id="gameLayer" left="0" top="0" bottom="0" right="0" horizontalCenter="0" verticalCenter="0"/> <e:Group id="gameLayer" left="0" top="0" bottom="0" right="0" horizontalCenter="0" verticalCenter="0">
<e:Component y="636" x="156" skinName="Land" visible="false"/>
<e:Component y="739" x="368" skinName="Land" visible="false"/>
<e:Component y="842" x="68" skinName="Land" visible="false"/>
<e:Component y="958" x="302" skinName="Land" visible="false"/>
</e:Group>
</e:Group> </e:Group>
</e:Skin> </e:Skin>
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<e:Skin class="LoadingSceneSkin" width="750" height="1624" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing" xmlns:ns1="*"> <e:Skin class="LoadingSceneSkin" width="750" height="1624" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing" xmlns:ns1="*">
<w:Config id="16e64c53e86"/> <w:Config id="16e64c53e86"/>
<e:Image source="index_bg_png" horizontalCenter="0" verticalCenter="0" x="0" y="0" scaleX="1" scaleY="1" visible="false"/> <e:Image source="index_bg_png" horizontalCenter="0" verticalCenter="0" x="0" y="0" scaleX="1" scaleY="1" visible="false"/>
<e:Group id="uiLayer" left="0" top="0" bottom="0" right="0" horizontalCenter="0" verticalCenter="0"> <e:Group id="uiLayer" left="0" top="0" bottom="0" right="0" horizontalCenter="0" verticalCenter="0" touchChildren="true" touchEnabled="false">
<e:Group id="btnGroup" y="1242" left="0" right="182" anchorOffsetX="0"> <e:Group id="btnGroup" y="1242" left="0" right="182" anchorOffsetX="0">
<e:Button id="taskBtn" label="" x="143" y="0"> <e:Button id="taskBtn" label="" x="143" y="0">
<e:skinName> <e:skinName>
...@@ -38,11 +38,11 @@ ...@@ -38,11 +38,11 @@
<e:Group id="avatarPanel" x="26" y="236" width="252" height="88"> <e:Group id="avatarPanel" x="26" y="236" width="252" height="88">
<e:Image source="头像面板_png" x="0" y="0"/> <e:Image source="头像面板_png" x="0" y="0"/>
<e:Image source="头像背景_png" x="6" y="5"/> <e:Image source="头像背景_png" x="6" y="5"/>
<e:Image source="默认头像_png" x="8" y="8" width="58" height="58"/> <e:Image id="avatarImg" source="默认头像_png" x="8" y="8" width="58" height="58"/>
<e:Image id="avaterMask" source="默认头像_png" x="8" y="8" width="58" height="58"/> <e:Image id="avatarMask" source="默认头像_png" x="8" y="8" width="58" height="58"/>
<e:Label id="userName" text="十一的欢趣庄园" x="79" y="10" size="20"/> <e:Label id="userName" text="十一的欢趣庄园" x="79" y="10" size="20"/>
<e:Label id="userGold" text="欢趣豆:23" x="78" y="41" size="20"/> <e:Label id="userGold" text="欢趣豆:23" x="78" y="41" size="20"/>
<e:Image id="medal" source="勋章_png" x="44" y="49"/> <e:Image id="medal" source="勋章_png" x="44" y="49" visible="false"/>
</e:Group> </e:Group>
</e:Group> </e:Group>
</e:Skin> </e:Skin>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<e:Skin class="ss" width="276" height="240" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing"> <e:Skin class="Crop" width="276" height="240" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing">
<e:Image id="cropImg" horizontalCenter="0" verticalCenter="0" source=""/> <e:Image id="cropImg" horizontalCenter="0" verticalCenter="0" source=""/>
</e:Skin> </e:Skin>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<e:Skin class="LandSkin" width="363" height="280" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing"> <e:Skin class="Land" width="362" height="245" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing" xmlns:ns1="*">
<e:Image id="land" source="plant_land_none_png" bottom="9" left="15"/> <e:Image id="land" source="plant_land_none_png" touchEnabled="true" y="71" x="15"/>
<e:Image id="fence" source="篱笆_png" left="0" top="37"/> <e:Image id="fence" source="篱笆_png" top="0" horizontalCenter="0" width="362" touchEnabled="false"/>
<e:Image id="trough" source="食槽_png" left="0" bottom="0"/> <e:Image id="trough" source="食槽_png" left="0" bottom="0" touchEnabled="false"/>
<ns1:TimeProgressBar y="190" skinName="TimeProgressBarSkin" horizontalCenter="0"/>
</e:Skin> </e:Skin>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<e:Skin class="OptionPanel" width="271" height="171" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing">
<e:Image source="option_panel_png" horizontalCenter="0" verticalCenter="0"/>
<e:Image id="chickBtn" source="option_chicken_png" y="15" x="158"/>
<e:Image id="wheatBtn" source="option_wheat_png" y="15" left="25"/>
</e:Skin>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<e:Skin class="TimeProgressBarSkin" xmlns:e="http://ns.egret.com/eui">
<e:Image id="track" source="timeTickBarBg_png" x="0"/>
<e:Image id="thumb" left="60" top="20" source="timeBarTemp_png"/>
</e:Skin>
\ No newline at end of file
import Scene from "../../views/Scene"; import Scene from "../../views/Scene";
import IndexUI from "./IndexUI"; import IndexUI from "./IndexUI";
import Land from "./Objs/Land"; import LandMgr from "./LandMgr";
import OptionPanel, { GDispatchHideOption } from "./Objs/OptionPanel";
import Dispatcher from "../../comm/Dispatcher";
export default class IndexScene extends Scene { ////////////////// Instance //////////////////
public gameLayer:eui.Group; let instance = null;
const IndexInstance = function() {
return instance;
};
const SetIndexInstance = function(ins) {
instance = ins;
};
const DestroyIndexInstance = function() {
instance = null;
};
public indexUI:IndexUI; export { IndexInstance };
constructor(data?) { ////////////////// Instance //////////////////
super(data);
}
protected getTapEvts(): any[] { // Index场景的事件收发器
return super.getTapEvts().concat([]); let IndexDispatcher = null;
export { IndexDispatcher };
} const NewIndexDispatcher = function() {
IndexDispatcher = new Dispatcher()
};
const DestroyDispatcher = function() {
IndexDispatcher = null;
};
private onTouchTap(e: egret.TouchEvent) { /**
switch(e.target) { * 主场景
*/
export default class IndexScene extends Scene {
public bg: eui.Image;
public gameLayer: eui.Group;
default: private indexUI: IndexUI;
break; private optionPanel: OptionPanel;
}
constructor(data?) {
super(data);
} }
private landMgr: LandMgr = null;
protected start() { protected start() {
super.start(); super.start();
SetIndexInstance(this); // 设置单例
NewIndexDispatcher(); // 创建一个局部事件收发器
this.initUI(); this.initUI();
} }
private initUI(): void { private initUI(): void {
// 创建UI层
this.indexUI = new IndexUI(); this.indexUI = new IndexUI();
this.addChild(this.indexUI); this.addChild(this.indexUI);
let s = new Land(); // 创建土地管理器
this.addChild(s); this.gameLayer.touchEnabled = false;
this.landMgr = new LandMgr(this, this.gameLayer);
// 创建操作Panel(初始为隐藏状态)
this.optionPanel = OptionPanel.getInstance();
this.addChild(this.optionPanel);
} }
destroy() { destroy() {
super.destroy(); super.destroy();
DestroyIndexInstance(); // 清除单例
DestroyDispatcher(); // 删除局部收发器
OptionPanel.destroy();
this.indexUI.destroy();
}
protected getTapEvts(): any[] {
return super.getTapEvts().concat([
[this.bg, GDispatchHideOption, this], // 点到bg触发Option隐藏,因为在游戏层中其他游戏元素都在bg上层
]);
}
private onTouchTap(e: egret.TouchEvent) {
switch(e.target) {
default:
break;
}
} }
protected async preLoadRes() { protected async preLoadRes() {
......
import Logger = egret.Logger; import ComponentBase from "../../components/ComponentBase";
import { GDispatchHideOption } from "./Objs/OptionPanel";
export default class IndexUI extends eui.Component {
public gameLayer: eui.Group; export default class IndexUI extends ComponentBase {
public uiLayer: eui.Group; public uiLayer:eui.Group;
public taskBtn: eui.Button; public btnGroup:eui.Group;
public warehouseBtn: eui.Button; public taskBtn:eui.Button;
public speedNum: eui.Label; public warehouseBtn:eui.Button;
public foodNum: eui.Label; public propPanel:eui.Group;
public waterNum: eui.Label; public speedNum:eui.Label;
public propInfoPanel: eui.Component; public foodNum:eui.Label;
public waterNum:eui.Label;
public avatarPanel:eui.Group;
public avatarImg:eui.Image;
public avatarMask:eui.Image;
public userName:eui.Label;
public userGold:eui.Label;
public medal:eui.Image;
constructor() { constructor() {
super(); super();
this.skinName = "resource/skins/IndexUISkin.exml";
this.initUI(); this.initUI();
} }
protected getTapEvts(): any[] {
return super.getTapEvts().concat([
[this, GDispatchHideOption, this],
[this.taskBtn, this.onTap, this],
[this.warehouseBtn, this.onTap, this],
])
}
onTap(e:egret.TouchEvent){
switch(e.target) {
case this.taskBtn: // 任务按钮
console.log('任务');
break;
case this.warehouseBtn: // 仓库按钮
console.log('仓库');
break;
default:
break;
}
}
protected start() {
super.start();
}
private initUI(): void { private initUI(): void {
// this.touchChildren = true; // 保证空白处不可点击,且UI可点击
this.touchEnabled = true;
/////////////// 根据数据初始化道具Panel ///////////////
}
get skinKey() {
return 'IndexUI';
} }
} }
\ No newline at end of file
class LandMgr { import Land from "./Objs/Land";
import { IndexDispatcher } from "./IndexScene";
const landPos = [ // 地块位置(注意顺序,影响层级)
{x: 156, y: 636},
{x: 368, y: 739},
{x: 68, y: 842},
{x: 302, y: 958},
];
export default class LandMgr {
private _parent: egret.DisplayObject = null;
public get parent() {
return this._parent;
}
private landLayer;
private lands: Land[] = [];
constructor(parent: egret.DisplayObject, landLayer) {
this._parent = parent;
this.landLayer = landLayer;
this.initEvents();
this.addLand();
}
private initEvents() {
IndexDispatcher.addEvent('hideOption', this.reActiveAll, this);
}
private reActiveAll() {
this.lands.forEach(v => v.reActive());
}
/**
* 添加地块
*/
private addLand() {
for(let i = 0; i < landPos.length; i++) {
let newLand = new Land({index: i});
newLand.x = landPos[i].x;
newLand.y = landPos[i].y;
this.landLayer.addChild(newLand);
this.lands.push(newLand); // 加入数组方便管理
}
}
} }
\ No newline at end of file
...@@ -15,26 +15,37 @@ enum CROP_STATE { ...@@ -15,26 +15,37 @@ enum CROP_STATE {
DONE = 2, // 成熟 DONE = 2, // 成熟
} }
const CROP_X = 53.5;
const CROP_Y = -18;
/**
* 作物类
*/
export default class Crop extends eui.Component { export default class Crop extends eui.Component {
public cropImg: eui.Image; public cropImg: eui.Image;
private data = null; private data = null;
private type: CROP_TYPE; private _type: CROP_TYPE;
public get type(){
return this._type;
}
private state: CROP_STATE; private state: CROP_STATE;
constructor(data?) { constructor(data?) {
super(); super();
this.skinName = getSkinPath('Objs/Crop'); this.skinName = getSkinPath('Objs/Crop');
this.data = data || null; this.data = data || null;
this.x = 46.5; this.x = CROP_X;
this.y = 20; this.y = CROP_Y;
this.initUI() this.initUI()
} }
private initUI() { private initUI() {
this.changeType(CROP_TYPE.WHEAT); /////////////// 根据数据添加Crop 初始化状态 ///////////////
this.changeState(CROP_STATE.BABY); this.changeType(CROP_TYPE.NONE);
this.changeState(CROP_STATE.NONE);
} }
...@@ -46,7 +57,7 @@ export default class Crop extends eui.Component { ...@@ -46,7 +57,7 @@ export default class Crop extends eui.Component {
this.state = state; // 设置状态 this.state = state; // 设置状态
this.type != -1 && this.state != -1 && (this.cropImg.source = `plant_${this.type}_${this.state}_png`); this._type != -1 && this.state != -1 && (this.cropImg.source = `plant_${this._type}_${this.state}_png`);
switch(this.state) { switch(this.state) {
case CROP_STATE.NONE: // 啥也没有 case CROP_STATE.NONE: // 啥也没有
...@@ -67,14 +78,14 @@ export default class Crop extends eui.Component { ...@@ -67,14 +78,14 @@ export default class Crop extends eui.Component {
// 改变类型 // 改变类型
private changeType(type: CROP_TYPE) { private changeType(type: CROP_TYPE) {
if(type == this.type) { if(type == this._type) {
return; return;
} }
this.type = type; // 设置状态 this._type = type; // 设置状态
this.type != -1 && this.state != -1 && (this.cropImg.source = `plant_${this.type}_${this.state}_png`); this._type != -1 && this.state != -1 && (this.cropImg.source = `plant_${this._type}_${this.state}_png`);
switch(this.type) { switch(this._type) {
case CROP_TYPE.NONE: // 啥也没有 case CROP_TYPE.NONE: // 啥也没有
break; break;
......
import { getSkinPath } from "../../../utils"; import { getSkinPath } from "../../../utils";
import Crop from "./Crop"; import Crop from "./Crop";
import { IndexDispatcher } from "../IndexScene";
import TimeProgressBar from "../TimeProgressBar";
enum LAND_STATE { enum LAND_STATE {
NONE = 'none', // 无 NONE = 'none', // 无
...@@ -8,6 +10,9 @@ enum LAND_STATE { ...@@ -8,6 +10,9 @@ enum LAND_STATE {
ANIMAL = 'animal' // 动物 ANIMAL = 'animal' // 动物
} }
/**
* 土地类
*/
export default class Land extends eui.Component { export default class Land extends eui.Component {
public land: eui.Image; public land: eui.Image;
public fence: eui.Image; public fence: eui.Image;
...@@ -15,19 +20,69 @@ export default class Land extends eui.Component { ...@@ -15,19 +20,69 @@ export default class Land extends eui.Component {
private data = null; private data = null;
private index;
private state: LAND_STATE; private state: LAND_STATE;
private crop: Crop;
private progressBar: TimeProgressBar;
constructor(data?) { constructor(data?) {
super(); super();
this.skinName = getSkinPath('Objs/Land'); this.skinName = getSkinPath('Objs/Land');
this.data = data || null; this.data = data || null;
this.initUI() this.index = data.index;
this.setTouchOption(); // 设置点击参数
this.initEvents(); // 注册事件
this.initUI(); // 设置显示
}
/**
* 取消active状态
*/
public reActive() {
this.state == LAND_STATE.ACTIVE && this.changeState(LAND_STATE.NONE);
}
/**
* 设置点击参数
*/
private setTouchOption() {
this.touchEnabled = false; // 保证空白处不可点击,且子对象可点击
this.touchChildren = true;
this.land.pixelHitTest = true; // 保证透明像素不可点击
this.fence.touchEnabled = false; // 保证栅栏和食槽不可点击
this.trough.touchEnabled = false;
}
private initEvents() {
this.land.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
}
private onTap() {
console.log(`点击了第${this.index}块土地`);
if(this.state != LAND_STATE.NONE) {
return;
}
// 显示操作
IndexDispatcher.dispatchEvent('showOption', {index: this.index, pos: {x: this.x, y: this.y}});
this.changeState(LAND_STATE.ACTIVE);
} }
private initUI() { private initUI() {
/////////////// 根据数据添加Crop 初始化状态 ///////////////
this.changeState(LAND_STATE.NONE); this.changeState(LAND_STATE.NONE);
let t = new Crop(); this.crop = new Crop();
this.addChild(t); this.addChildAt(this.crop, 2);
}
private addProgress() {
/////////////// 根据数据添加进度条 ///////////////
this.progressBar && this.progressBar.stop();
this.progressBar = new TimeProgressBar('鸡', 1574684000000, 1574684500000, 1574685000000, this.state);
this.addChild(this.progressBar);
} }
...@@ -51,10 +106,10 @@ export default class Land extends eui.Component { ...@@ -51,10 +106,10 @@ export default class Land extends eui.Component {
break; break;
case LAND_STATE.PLANT: // 植物 case LAND_STATE.PLANT: // 植物
this.addProgress();
break; break;
case LAND_STATE.ANIMAL: // 动物 case LAND_STATE.ANIMAL: // 动物
this.addProgress();
break; break;
default: default:
break; break;
......
import { getSkinPath } from "../../../utils";
import { IndexDispatcher } from "../IndexScene";
// 触发Option隐藏
const GDispatchHideOption = function(){
IndexDispatcher.dispatchEvent('hideOption');
};
export {GDispatchHideOption};
/**
* 操作面板
*/
export default class OptionPanel extends eui.Component {
public chickBtn: eui.Image;
public wheatBtn: eui.Image;
private data = null;
////////////////////// 单例 //////////////////////
private static _instance:OptionPanel = null;
public static getInstance(data?){
return OptionPanel._instance || (OptionPanel._instance = new OptionPanel(data))
}
public static destroy(){
this._instance = null;
}
////////////////////// 单例 //////////////////////
constructor(data?) {
super();
this.skinName = getSkinPath('Objs/OptionPanel');
this.data = data || null;
this.initEvents();
this.initUI()
}
private initEvents() {
this.wheatBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
this.chickBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
IndexDispatcher.addEvent('showOption', this.showOption, this);
IndexDispatcher.addEvent('hideOption', this.hideOption, this);
}
private showOption(data?){
IndexDispatcher.dispatchEvent("hideOption"); // 先触发隐藏,保证地块
this.visible = true;
this.touchEnabled = true;
this.touchChildren = true;
this.x = data.pos.x + 52;
this.y = data.pos.y - 70;
}
private hideOption(){
if(!this.visible){
return;
}
this.visible = false;
this.touchEnabled = false;
this.touchChildren = false;
}
private onTap(e: egret.TouchEvent) {
switch(e.target) {
case this.wheatBtn:
console.log('点击了小麦');
break;
case this.chickBtn:
console.log('点击了鸡');
break;
default:
break;
}
}
private initUI() {
this.hideOption();
this.x = 100;
this.y = 200;
}
}
\ No newline at end of file
import { getSkinPath } from "../../utils";
const PROGRESS_X = 88;
const PROGRESS_Y = 190;
export default class TimeProgressBar extends eui.Component {
public bg: eui.Rect;
public corpName: eui.Label;
public progressBar: eui.Rect;
public fillMask: eui.Rect;
public progressFill: eui.Rect;
public progressLabel: eui.Label;
private labelText: string = '';
private startTime: number;
private nowTime: number;
private endTime: number;
private cTime:number;
private progressText = '';
private _timer: egret.Timer = null;
constructor(labelText, startTime, nowTime, endTime, type) {
super();
this.skinName = getSkinPath('Component/TimeProgressBar');
this.labelText = labelText;
this.startTime = startTime;
this.nowTime = nowTime;
this.endTime = endTime;
if(type == 'plant') {
this.progressText = 'hh时mm分后浇水';
} else {
this.progressText = 'hh时mm分后喂食';
}
this.initUI();
this.x = PROGRESS_X;
this.y = PROGRESS_Y;
}
private initUI() {
this.progressFill.mask = this.fillMask;
this.corpName.text = this.labelText;
this.setProgress();
this.cTime = this.endTime - (this.nowTime = this.nowTime - this.nowTime % 1000 + 1000); // 去除余数
this.cutFun();
this._timer = new egret.Timer(1000, 0);
this._timer.addEventListener(egret.TimerEvent.TIMER, this.cutFun, this);
this._timer.start();
}
private cutFun() {
let timer = this._convertTime(this.cTime -= 1000);
this.nowTime += 1000;
if(timer.hour === "00"
&& timer.min === "00"
&& timer.sec === "00") {
this.stop();
}
let str = this.progressText;
str = str.replace(/hh/g, timer.hour);
str = str.replace(/mm/g, timer.min);
str = str.replace(/ss/g, timer.sec);
this.progressLabel.text = str;
this.setProgress();
}
public stop(){
this._timer && this._timer.stop();
}
/**
* 设置进度
*/
private setProgress() {
let progress = (this.nowTime - this.startTime) / (this.endTime - this.startTime);
if(progress > 100) {
progress = 100;
} else if(progress < 0) {
progress = 0
}
this.progressFill.width = this.progressBar.width * progress;
}
/**
* 通过时间戳获取几时积分几秒 例:666666666 -> {hour: 18, min: 51, sec: 16}
* @param time 时间戳(毫秒)
* @private
*/
private _convertTime(time: number): { hour, min, sec } {
let hour = ~~(time / 3600000); // 小时
let min = ~~((time - hour * 3600000) / 60000); // 分
let sec = ~~((time - hour * 3600000 - min * 60000) / 1000); // 秒
return {
hour: this._prefixInteger(hour, 2),
min: this._prefixInteger(min, 2),
sec: this._prefixInteger(sec, 2)
}
}
/**
* 数字补0 例:(num = 2, length = 2) -> 02
* @param num 数字
* @param length 位数
* @private
*/
private _prefixInteger(num, length): string {
return (Array(length).join('0') + num).slice(-length);
}
}
\ No newline at end of file
/**
* 局部的事件收发器
*/
export default class Dispatcher {
/**
* 事件回调池
*/
private callbackPool: any = {};
/**
* 事件作用域池
*/
private thisObjPool: any = {};
/**
*
* @param name 事件名
* @param callback 回调
* @param thisObj 作用域
*/
public addEvent(name: string, callback, thisObj: any): void {
if(!this.callbackPool[name]) {
this.callbackPool[name] = [];
this.thisObjPool[name] = [];
}
const index: number = this.callbackPool[name].indexOf(callback);
const thisObjIndex: number = this.thisObjPool[name].indexOf(thisObj);
if(index != -1 && thisObjIndex != -1) {
this.callbackPool[name][index] = callback;
this.thisObjPool[name][index] = thisObj;
} else {
this.callbackPool[name].push(callback);
this.thisObjPool[name].push(thisObj);
}
}
/**
*
* @param name 事件名
* @param callback 回调
* @param thisObj 作用域
*/
public removeEvent(name: string, callback, thisObj?: any): void {
if(this.callbackPool[name]) {
const index: number = this.callbackPool[name].indexOf(callback);
if(index != -1) {
this.callbackPool[name].splice(index, 1);
this.thisObjPool[name].splice(index, 1);
}
}
}
/**
* 派发事件
* @param name 事件名
* @param args 任意参数
*/
public dispatchEvent(name: string, ...args): void {
const callbacks: Function[] = this.callbackPool[name];
const thisObjs: any = this.thisObjPool[name];
if(callbacks) {
let i = 0;
const len: number = callbacks.length;
for(i; i < len; i++) {
callbacks[i].apply(thisObjs[i], args);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment