selectPoint
This commit is contained in:
parent
550252817c
commit
1cee65b7ff
@ -1897,7 +1897,7 @@ clearMap_s
|
|||||||
tooltip : clearMap: 清除画布
|
tooltip : clearMap: 清除画布
|
||||||
helpUrl : https://h5mota.com/games/template/_docs/#/event?id=clearMap%ef%bc%9a%e6%b8%85%e9%99%a4%e7%94%bb%e5%b8%83
|
helpUrl : https://h5mota.com/games/template/_docs/#/event?id=clearMap%ef%bc%9a%e6%b8%85%e9%99%a4%e7%94%bb%e5%b8%83
|
||||||
colour : this.subColor
|
colour : this.subColor
|
||||||
default : ["0", "0", "416", "480"]
|
default : ["0", "0", "100", "100"]
|
||||||
var code = '{"type": "clearMap", "x": ' + PosString_0 + ', "y": ' + PosString_1 +
|
var code = '{"type": "clearMap", "x": ' + PosString_0 + ', "y": ' + PosString_1 +
|
||||||
', "width": ' + PosString_2 + ', "height": ' + PosString_3 + '},\n';
|
', "width": ' + PosString_2 + ', "height": ' + PosString_3 + '},\n';
|
||||||
return code;
|
return code;
|
||||||
|
|||||||
@ -369,36 +369,42 @@ selectBox.isSelected=function(value){
|
|||||||
|
|
||||||
// ------ UI预览 & 地图选点相关 ------ //
|
// ------ UI预览 & 地图选点相关 ------ //
|
||||||
|
|
||||||
uievent = {};
|
uievent = {
|
||||||
|
div: {},
|
||||||
|
values: {},
|
||||||
|
isOpen: false,
|
||||||
|
mode: ""
|
||||||
|
};
|
||||||
|
|
||||||
uievent.div = document.getElementById('uieventDiv');
|
uievent.div.div = document.getElementById('uieventDiv');
|
||||||
uievent.title = document.getElementById('uieventTitle');
|
uievent.div.title = document.getElementById('uieventTitle');
|
||||||
uievent.yes = document.getElementById('uieventYes');
|
uievent.div.yes = document.getElementById('uieventYes');
|
||||||
uievent.no = document.getElementById('uieventNo');
|
uievent.div.no = document.getElementById('uieventNo');
|
||||||
|
uievent.div.selectBackground = document.getElementById('uieventBackground');
|
||||||
uievent.selectDiv = document.getElementById('selectPoint');
|
uievent.div.selectPoint = document.getElementById('selectPoint');
|
||||||
uievent.selectFloor = document.getElementById('selectPointFloor');
|
uievent.div.selectFloor = document.getElementById('selectPointFloor');
|
||||||
uievent.selectPointBox = document.getElementById('selectPointBox');
|
uievent.div.selectPointBox = document.getElementById('selectPointBox');
|
||||||
uievent.body = document.getElementById('uieventBody');
|
uievent.div.body = document.getElementById('uieventBody');
|
||||||
uievent.selectPointButtons = document.getElementById('selectPointButtons');
|
uievent.div.selectPointButtons = document.getElementById('selectPointButtons');
|
||||||
|
|
||||||
uievent.confirm = function () {
|
uievent.confirm = function () {
|
||||||
|
var callback = uievent.values.callback, floorId = uievent.values.floorId,
|
||||||
|
x = uievent.values.x, y = uievent.values.y;
|
||||||
uievent.close();
|
uievent.close();
|
||||||
if (uievent.callback) {
|
if (callback) {
|
||||||
uievent.callback(uievent.floorId, uievent.x, uievent.y);
|
callback(floorId, x, y);
|
||||||
}
|
}
|
||||||
delete uievent.callback;
|
|
||||||
}
|
}
|
||||||
uievent.yes.onclick = uievent.confirm;
|
uievent.div.yes.onclick = uievent.confirm;
|
||||||
|
|
||||||
uievent.close = function () {
|
uievent.close = function () {
|
||||||
uievent.isOpen = false;
|
uievent.isOpen = false;
|
||||||
uievent.div.style.display = 'none';
|
uievent.div.div.style.display = 'none';
|
||||||
|
uievent.values = {};
|
||||||
}
|
}
|
||||||
uievent.no.onclick = uievent.close;
|
uievent.div.no.onclick = uievent.close;
|
||||||
|
|
||||||
uievent.background = document.getElementById('uieventBackground');
|
uievent.div.selectBackground.onchange = function () {
|
||||||
uievent.background.onchange = function () {
|
|
||||||
uievent.drawPreviewUI();
|
uievent.drawPreviewUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +413,7 @@ uievent.drawPreviewUI = function () {
|
|||||||
core.clearMap('uievent');
|
core.clearMap('uievent');
|
||||||
|
|
||||||
// 绘制UI
|
// 绘制UI
|
||||||
var background = uievent.background.value;
|
var background = uievent.div.selectBackground.value;
|
||||||
if (background == 'thumbnail') {
|
if (background == 'thumbnail') {
|
||||||
core.drawThumbnail(editor.currentFloorId, null, {}, 'uievent');
|
core.drawThumbnail(editor.currentFloorId, null, {}, 'uievent');
|
||||||
}
|
}
|
||||||
@ -415,8 +421,8 @@ uievent.drawPreviewUI = function () {
|
|||||||
core.fillRect('uievent', 0, 0, core.__PIXELS__, core.__PIXELS__, background);
|
core.fillRect('uievent', 0, 0, core.__PIXELS__, core.__PIXELS__, background);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uievent.list instanceof Array) {
|
if (uievent.values.list instanceof Array) {
|
||||||
uievent.list.forEach(function (data) {
|
uievent.values.list.forEach(function (data) {
|
||||||
var type = data.type;
|
var type = data.type;
|
||||||
if (!type || !core.ui["_uievent_"+type]) return;
|
if (!type || !core.ui["_uievent_"+type]) return;
|
||||||
core.ui["_uievent_"+type](data);
|
core.ui["_uievent_"+type](data);
|
||||||
@ -426,101 +432,102 @@ uievent.drawPreviewUI = function () {
|
|||||||
|
|
||||||
uievent.previewUI = function (list) {
|
uievent.previewUI = function (list) {
|
||||||
uievent.isOpen = true;
|
uievent.isOpen = true;
|
||||||
uievent.div.style.display = 'block';
|
uievent.div.div.style.display = 'block';
|
||||||
uievent.mode = 'previewUI';
|
uievent.mode = 'previewUI';
|
||||||
uievent.selectDiv.style.display = 'none';
|
uievent.div.selectPoint.style.display = 'none';
|
||||||
uievent.yes.style.display = 'none';
|
uievent.div.yes.style.display = 'none';
|
||||||
uievent.title.innerText = 'UI绘制预览';
|
uievent.div.title.innerText = 'UI绘制预览';
|
||||||
uievent.background.style.display = 'inline';
|
uievent.div.selectBackground.style.display = 'inline';
|
||||||
uievent.background.value = 'thumbnail';
|
uievent.div.selectBackground.value = 'thumbnail';
|
||||||
uievent.selectPointBox.style.display = 'none';
|
uievent.div.selectPointBox.style.display = 'none';
|
||||||
|
|
||||||
uievent.list = list;
|
uievent.values.list = list;
|
||||||
uievent.drawPreviewUI();
|
uievent.drawPreviewUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.selectPoint = function (floorId, x, y, hideFloor, callback) {
|
uievent.selectPoint = function (floorId, x, y, hideFloor, callback) {
|
||||||
uievent.hideFloor = hideFloor;
|
uievent.values.hideFloor = hideFloor;
|
||||||
uievent.callback = callback;
|
uievent.values.callback = callback;
|
||||||
|
|
||||||
uievent.isOpen = true;
|
uievent.isOpen = true;
|
||||||
uievent.div.style.display = 'block';
|
uievent.div.div.style.display = 'block';
|
||||||
uievent.mode = 'selectPoint';
|
uievent.mode = 'selectPoint';
|
||||||
uievent.selectDiv.style.display = 'block';
|
uievent.div.selectPoint.style.display = 'block';
|
||||||
uievent.yes.style.display = 'inline';
|
uievent.div.yes.style.display = 'inline';
|
||||||
uievent.background.style.display = 'none';
|
uievent.div.selectBackground.style.display = 'none';
|
||||||
uievent.selectFloor.style.display = hideFloor ? 'none': 'inline';
|
uievent.div.selectFloor.style.display = hideFloor ? 'none': 'inline';
|
||||||
uievent.selectPointBox.style.display = 'block';
|
uievent.div.selectPointBox.style.display = 'block';
|
||||||
|
|
||||||
// Append children
|
// Append children
|
||||||
var floors = "";
|
var floors = "";
|
||||||
core.floorIds.forEach(function (f) {
|
core.floorIds.forEach(function (f) {
|
||||||
floors += "<option value="+f+">"+f+"</option>";
|
floors += "<option value="+f+">"+f+"</option>";
|
||||||
})
|
})
|
||||||
uievent.selectFloor.innerHTML = floors;
|
uievent.div.selectFloor.innerHTML = floors;
|
||||||
|
|
||||||
this.setPoint(floorId || editor.currentFloorId, core.calValue(x) || 0, core.calValue(y) || 0);
|
this.setPoint(floorId || editor.currentFloorId, core.calValue(x) || 0, core.calValue(y) || 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.updateSelectPoint = function (redraw) {
|
uievent.updateSelectPoint = function (redraw) {
|
||||||
uievent.title.innerText = '地图选点 ('+uievent.x+","+uievent.y+')';
|
uievent.div.title.innerText = '地图选点 ('+uievent.values.x+","+uievent.values.y+')';
|
||||||
if (redraw) {
|
if (redraw) {
|
||||||
core.drawThumbnail(uievent.floorId, null, null,
|
core.drawThumbnail(uievent.values.floorId, null, null,
|
||||||
{ctx: 'uievent', centerX: uievent.left + core.__HALF_SIZE__, centerY: uievent.top + core.__HALF_SIZE__});
|
{ctx: 'uievent', centerX: uievent.values.left + core.__HALF_SIZE__,
|
||||||
|
centerY: uievent.values.top + core.__HALF_SIZE__});
|
||||||
}
|
}
|
||||||
uievent.selectPointBox.style.left = 32 * (uievent.x - uievent.left) + "px";
|
uievent.div.selectPointBox.style.left = 32 * (uievent.values.x - uievent.values.left) + "px";
|
||||||
uievent.selectPointBox.style.top = 32 * (uievent.y - uievent.top) + "px";
|
uievent.div.selectPointBox.style.top = 32 * (uievent.values.y - uievent.values.top) + "px";
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.setPoint = function (floorId, x, y) {
|
uievent.setPoint = function (floorId, x, y) {
|
||||||
uievent.floorId = floorId;
|
uievent.values.floorId = floorId;
|
||||||
uievent.selectFloor.value = floorId;
|
uievent.div.selectFloor.value = floorId;
|
||||||
uievent.x = x || uievent.x || 0;
|
uievent.values.x = x || uievent.values.x || 0;
|
||||||
uievent.y = y || uievent.y || 0;
|
uievent.values.y = y || uievent.values.y || 0;
|
||||||
uievent.width = core.floors[uievent.floorId].width || core.__SIZE__;
|
uievent.values.width = core.floors[uievent.values.floorId].width || core.__SIZE__;
|
||||||
uievent.height = core.floors[uievent.floorId].height || core.__SIZE__;
|
uievent.values.height = core.floors[uievent.values.floorId].height || core.__SIZE__;
|
||||||
uievent.left = core.clamp(uievent.x - core.__HALF_SIZE__, 0, uievent.width - core.__SIZE__);
|
uievent.values.left = core.clamp(uievent.values.x - core.__HALF_SIZE__, 0, uievent.values.width - core.__SIZE__);
|
||||||
uievent.top = core.clamp(uievent.y - core.__HALF_SIZE__, 0, uievent.height - core.__SIZE__);
|
uievent.values.top = core.clamp(uievent.values.y - core.__HALF_SIZE__, 0, uievent.values.height - core.__SIZE__);
|
||||||
uievent.updateSelectPoint(true);
|
uievent.updateSelectPoint(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.selectFloor.onchange = function () {
|
uievent.div.selectFloor.onchange = function () {
|
||||||
uievent.setPoint(uievent.selectFloor.value);
|
uievent.setPoint(uievent.div.selectFloor.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.body.onclick = function (e) {
|
uievent.div.body.onclick = function (e) {
|
||||||
if (uievent.mode != 'selectPoint') return;
|
if (uievent.mode != 'selectPoint') return;
|
||||||
uievent.x = uievent.left + Math.floor(e.offsetX / 32);
|
uievent.values.x = uievent.values.left + Math.floor(e.offsetX / 32);
|
||||||
uievent.y = uievent.top + Math.floor(e.offsetY / 32);
|
uievent.values.y = uievent.values.top + Math.floor(e.offsetY / 32);
|
||||||
uievent.updateSelectPoint(false);
|
uievent.updateSelectPoint(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.move = function (dx, dy) {
|
uievent.move = function (dx, dy) {
|
||||||
if (uievent.mode != 'selectPoint') return;
|
if (uievent.mode != 'selectPoint') return;
|
||||||
uievent.left = core.clamp(uievent.left + dx, 0, uievent.width - core.__SIZE__);
|
uievent.values.left = core.clamp(uievent.values.left + dx, 0, uievent.values.width - core.__SIZE__);
|
||||||
uievent.top = core.clamp(uievent.top + dy, 0, uievent.height - core.__SIZE__);
|
uievent.values.top = core.clamp(uievent.values.top + dy, 0, uievent.values.height - core.__SIZE__);
|
||||||
this.updateSelectPoint(true);
|
this.updateSelectPoint(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.selectPointButtons.children[0].onclick = function () {
|
uievent.div.selectPointButtons.children[0].onclick = function () {
|
||||||
uievent.move(-1, 0);
|
uievent.move(-1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.selectPointButtons.children[1].onclick = function () {
|
uievent.div.selectPointButtons.children[1].onclick = function () {
|
||||||
uievent.move(0, -1);
|
uievent.move(0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.selectPointButtons.children[2].onclick = function () {
|
uievent.div.selectPointButtons.children[2].onclick = function () {
|
||||||
uievent.move(0, 1);
|
uievent.move(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.selectPointButtons.children[3].onclick = function () {
|
uievent.div.selectPointButtons.children[3].onclick = function () {
|
||||||
uievent.move(1, 0);
|
uievent.move(1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uievent.div.onmousewheel = function (e) {
|
uievent.div.div.onmousewheel = function (e) {
|
||||||
if (uievent.mode != 'selectPoint' || uievent.hideFloor) return;
|
if (uievent.mode != 'selectPoint' || uievent.values.hideFloor) return;
|
||||||
var index = core.floorIds.indexOf(uievent.floorId);
|
var index = core.floorIds.indexOf(uievent.values.floorId);
|
||||||
try {
|
try {
|
||||||
if (e.wheelDelta)
|
if (e.wheelDelta)
|
||||||
index+=Math.sign(e.wheelDelta);
|
index+=Math.sign(e.wheelDelta);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user