mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 09:29:02 +02:00
entity list auto scroll
This commit is contained in:
parent
daa13b3706
commit
27e0c85b01
4 changed files with 55 additions and 13 deletions
|
@ -194,7 +194,7 @@ function loaded() {
|
||||||
if (selectedIndex >= 0) {
|
if (selectedIndex >= 0) {
|
||||||
selection = [];
|
selection = [];
|
||||||
selection = selection.concat(selectedEntities);
|
selection = selection.concat(selectedEntities);
|
||||||
selection.splice(selectedIndex, 1)
|
selection.splice(selectedIndex, 1);
|
||||||
} else {
|
} else {
|
||||||
selection = selection.concat(selectedEntities);
|
selection = selection.concat(selectedEntities);
|
||||||
}
|
}
|
||||||
|
@ -453,7 +453,10 @@ function loaded() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSelectedEntities(selectedIDs) {
|
function updateSelectedEntities(selectedIDs, autoScroll) {
|
||||||
|
// force autoScroll to be a boolean
|
||||||
|
autoScroll = !!autoScroll;
|
||||||
|
|
||||||
let notFound = false;
|
let notFound = false;
|
||||||
|
|
||||||
// reset all currently selected entities and their rows first
|
// reset all currently selected entities and their rows first
|
||||||
|
@ -482,6 +485,26 @@ function loaded() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (autoScroll && selectedIDs.length > 0) {
|
||||||
|
let firstItem = Number.MAX_VALUE;
|
||||||
|
let lastItem = -1;
|
||||||
|
let itemFound = false;
|
||||||
|
visibleEntities.forEach(function(entity, index) {
|
||||||
|
if (selectedIDs.indexOf(entity.id) !== -1) {
|
||||||
|
if (firstItem > index) {
|
||||||
|
firstItem = index;
|
||||||
|
}
|
||||||
|
if (lastItem < index) {
|
||||||
|
lastItem = index;
|
||||||
|
}
|
||||||
|
itemFound = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (itemFound) {
|
||||||
|
entityList.scrollToRow(firstItem, lastItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
refreshFooter();
|
refreshFooter();
|
||||||
|
|
||||||
return notFound;
|
return notFound;
|
||||||
|
@ -640,8 +663,8 @@ function loaded() {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
if (data.type === "clearEntityList") {
|
if (data.type === "clearEntityList") {
|
||||||
clearEntities();
|
clearEntities();
|
||||||
} else if (data.type === "selectionUpdate") {
|
} else if (data.type === "selectionUpdate" && data.caller !== "entityList") {
|
||||||
let notFound = updateSelectedEntities(data.selectedIDs);
|
let notFound = updateSelectedEntities(data.selectedIDs, true);
|
||||||
if (notFound) {
|
if (notFound) {
|
||||||
refreshEntities();
|
refreshEntities();
|
||||||
}
|
}
|
||||||
|
@ -653,13 +676,13 @@ function loaded() {
|
||||||
clearEntities();
|
clearEntities();
|
||||||
} else {
|
} else {
|
||||||
updateEntityData(newEntities);
|
updateEntityData(newEntities);
|
||||||
updateSelectedEntities(data.selectedIDs);
|
updateSelectedEntities(data.selectedIDs, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (data.type === "removeEntities" && data.deletedIDs !== undefined && data.selectedIDs !== undefined) {
|
} else if (data.type === "removeEntities" && data.deletedIDs !== undefined && data.selectedIDs !== undefined) {
|
||||||
removeEntities(data.deletedIDs);
|
removeEntities(data.deletedIDs);
|
||||||
updateSelectedEntities(data.selectedIDs);
|
updateSelectedEntities(data.selectedIDs, true);
|
||||||
} else if (data.type === "deleted" && data.ids) {
|
} else if (data.type === "deleted" && data.ids) {
|
||||||
removeEntities(data.ids);
|
removeEntities(data.ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,24 @@ ListView.prototype = {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
scrollToRow(rowIndex, lastRowIndex) {
|
||||||
|
lastRowIndex = lastRowIndex ? lastRowIndex : rowIndex;
|
||||||
|
let boundingTop = rowIndex * this.rowHeight;
|
||||||
|
let boundingBottom = (lastRowIndex * this.rowHeight) + this.rowHeight;
|
||||||
|
if ((boundingBottom - boundingTop) > this.elTableScroll.clientHeight) {
|
||||||
|
boundingBottom = boundingTop + this.elTableScroll.clientHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentVisibleAreaTop = this.elTableScroll.scrollTop;
|
||||||
|
let currentVisibleAreaBottom = currentVisibleAreaTop + this.elTableScroll.clientHeight;
|
||||||
|
|
||||||
|
if (boundingTop < currentVisibleAreaTop) {
|
||||||
|
this.elTableScroll.scrollTop = boundingTop;
|
||||||
|
} else if (boundingBottom > currentVisibleAreaBottom) {
|
||||||
|
this.elTableScroll.scrollTop = boundingBottom - (this.elTableScroll.clientHeight);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
// block refreshing before rows are initialized
|
// block refreshing before rows are initialized
|
||||||
|
|
|
@ -98,7 +98,7 @@ EntityListTool = function(shouldUseEditTabletApp) {
|
||||||
that.setVisible(!visible);
|
that.setVisible(!visible);
|
||||||
};
|
};
|
||||||
|
|
||||||
selectionManager.addEventListener(function() {
|
selectionManager.addEventListener(function(isSelectionUpdate, caller) {
|
||||||
var selectedIDs = [];
|
var selectedIDs = [];
|
||||||
|
|
||||||
for (var i = 0; i < selectionManager.selections.length; i++) {
|
for (var i = 0; i < selectionManager.selections.length; i++) {
|
||||||
|
@ -107,7 +107,8 @@ EntityListTool = function(shouldUseEditTabletApp) {
|
||||||
|
|
||||||
emitJSONScriptEvent({
|
emitJSONScriptEvent({
|
||||||
type: 'selectionUpdate',
|
type: 'selectionUpdate',
|
||||||
selectedIDs: selectedIDs
|
selectedIDs: selectedIDs,
|
||||||
|
caller: caller
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -224,7 +225,7 @@ EntityListTool = function(shouldUseEditTabletApp) {
|
||||||
for (var i = 0; i < ids.length; i++) {
|
for (var i = 0; i < ids.length; i++) {
|
||||||
entityIDs.push(ids[i]);
|
entityIDs.push(ids[i]);
|
||||||
}
|
}
|
||||||
selectionManager.setSelections(entityIDs);
|
selectionManager.setSelections(entityIDs, "entityList");
|
||||||
if (data.focus) {
|
if (data.focus) {
|
||||||
cameraManager.enable();
|
cameraManager.enable();
|
||||||
cameraManager.focus(selectionManager.worldPosition,
|
cameraManager.focus(selectionManager.worldPosition,
|
||||||
|
|
|
@ -136,7 +136,7 @@ SelectionManager = (function() {
|
||||||
return that.selections.length > 0;
|
return that.selections.length > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.setSelections = function(entityIDs) {
|
that.setSelections = function(entityIDs, caller) {
|
||||||
that.selections = [];
|
that.selections = [];
|
||||||
for (var i = 0; i < entityIDs.length; i++) {
|
for (var i = 0; i < entityIDs.length; i++) {
|
||||||
var entityID = entityIDs[i];
|
var entityID = entityIDs[i];
|
||||||
|
@ -144,7 +144,7 @@ SelectionManager = (function() {
|
||||||
Selection.addToSelectedItemsList(HIGHLIGHT_LIST_NAME, "entity", entityID);
|
Selection.addToSelectedItemsList(HIGHLIGHT_LIST_NAME, "entity", entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
that._update(true);
|
that._update(true, caller);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.addEntity = function(entityID, toggleSelection) {
|
that.addEntity = function(entityID, toggleSelection) {
|
||||||
|
@ -477,7 +477,7 @@ SelectionManager = (function() {
|
||||||
undoHistory.pushCommand(undo, copiedProperties, redo, copiedProperties);
|
undoHistory.pushCommand(undo, copiedProperties, redo, copiedProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
that._update = function(selectionUpdated) {
|
that._update = function(selectionUpdated, caller) {
|
||||||
var properties = null;
|
var properties = null;
|
||||||
if (that.selections.length === 0) {
|
if (that.selections.length === 0) {
|
||||||
that.localDimensions = null;
|
that.localDimensions = null;
|
||||||
|
@ -542,7 +542,7 @@ SelectionManager = (function() {
|
||||||
|
|
||||||
for (var j = 0; j < listeners.length; j++) {
|
for (var j = 0; j < listeners.length; j++) {
|
||||||
try {
|
try {
|
||||||
listeners[j](selectionUpdated === true);
|
listeners[j](selectionUpdated === true, caller);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("ERROR: entitySelectionTool.update got exception: " + JSON.stringify(e));
|
print("ERROR: entitySelectionTool.update got exception: " + JSON.stringify(e));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue