Files
fc/dev/project/library/imports/99/99814dc7-1d98-496c-9355-4ad00d34ed85.js
2026-05-24 10:21:26 +08:00

64 lines
1.8 KiB
JavaScript

"use strict";
cc._RF.push(module, '998143HHZhJbJNVStANNO2F', 'nx.fx.local.image');
// Scripts/nx/cmp/flex/nx.fx.local.image.js
"use strict";
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 组件--本地化图片
* 1. 规范路径
* 2. 只支持SpriteFrame
* 2018.05.18
******************************************************************/
var CFG = require("config");
// 默认扩展目录
var DEF_FOLDER = "images/sma";
cc.Class({
"extends": cc.Component,
properties: {
imgPath: {
"default": "",
displayName: "扩展目录"
}
},
// 编辑器特性
editor: {
// 允许当前组件在编辑器模式下运行
executeInEditMode: false,
// requireComponent 参数用来指定当前组件的依赖组件
requireComponent: cc.Sprite,
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
disallowMultiple: false,
// menu 用来将当前组件添加到组件菜单中,方便用户查找
menu: "Nx/本地化|图片"
},
// 展示
onLoad: function onLoad() {
var _this = this;
// 默认语种不处理
if (nx.getLocLanguage() == CFG.DesignLanguage) {
return;
}
// 无效组件
var sprite = nx.gui.getComponent(this, "", cc.Sprite);
if (!sprite || !sprite.spriteFrame) {
return;
}
var name = sprite.spriteFrame.name;
var fold = this.imgPath || DEF_FOLDER;
var path = cc.path.join("locals", nx.getLocLanguage(), fold, name);
path = path.replace("//", "/");
nx.gui.setSpriteFrame(this.node, "", path, function (_ret) {
if (!_ret) {
nx.gui.setSpriteFrame(_this.node, "", null);
}
});
}
});
cc._RF.pop();