Commit 83c582a4 authored by Max Bebök's avatar Max Bebök

#54 added actual actor search and select all actions, added select/deselect from the list

parent 8c0c9fa8
......@@ -79,6 +79,20 @@
border: 1px solid black;
width: 100%;
}
#searchWindow-actor table tr td {
border-color: #282c34;
border-width: 1px 0;
border-style: solid;
}
#searchWindow-actor table tr:active td,
#searchWindow-actor table tr.active td {
border-width: 1px 0 1px 0;
border-color: #73c990;
border-style: solid;
color: #73c990;
}
</style>
<div>
<div class="search-header">
......
......@@ -14,13 +14,16 @@ module.exports = class Actor
this.params = params;
this.type = type;
this.gui = null;
this.objInstance = objInstance;
this.objInstance.setActor(this);
this.selected = false;
}
getName()
{
return this.params.UnitConfigName.value;
return (this.params.UnitConfigName && this.params.UnitConfigName.value) ? this.params.UnitConfigName.value : "";
}
getHashId()
......
......@@ -6,37 +6,88 @@
module.exports = class Actor_Search_Finder
{
constructor(actorHandler)
constructor(actorHandler, actorEditor)
{
this.actorHandler = actorHandler;
console.log(this.actorHandler);
this.actorEditor = actorEditor;
this.result = [];
}
search(searchValue, filter)
{
searchValue = searchValue.toLowerCase();
console.warn("SEARCH");
console.log(filter);
console.log(searchValue);
const result = [];
this.result = [];
for(const actorId in this.actorHandler.actors)
{
const actor = this.actorHandler.actors[actorId];
const params = actor.params;
if(params.UnitConfigName && params.UnitConfigName.value) {
const nameNorm = params.UnitConfigName.value.toLowerCase();
if(nameNorm.includes(searchValue)) {
result.push(actor);
//console.log(actor);
}
}
if(this._checkActor(actor, searchValue, filter))
this.result.push(actor);
}
return this.result;
}
_checkActor(actor, searchValue, filter)
{
const params = actor.params;
if(!["Static", "Dynamic"].includes(actor.type))
return false;
if(!filter.static && actor.type == "Static")
return false;
if(!filter.dynamic && actor.type == "Dynamic")
return false;
if(filter.id && actor.getHashId() == searchValue)
return true;
if(filter.srt && actor.getSRTHash() == searchValue)
return true;
if(filter.name)
{
const nameNorm = actor.getName().toLowerCase();
if(nameNorm.includes(searchValue))
return true;
}
return result;
if(filter.params)
{
const paramStr = JSON.stringify(params).toLowerCase();
if(paramStr.includes(searchValue))
return true;
}
return false;
}
selectIndex(actorIndex)
{
actorIndex = parseInt(actorIndex);
if(actorIndex >= 0 && actorIndex < this.result.length)
this.actorEditor.selectActor(this.result[actorIndex]);
}
deselectIndex(actorIndex)
{
actorIndex = parseInt(actorIndex);
if(actorIndex >= 0 && actorIndex < this.result.length)
this.actorEditor.deselectActor(this.result[actorIndex]);
}
selectAll()
{
console.log("select all");
for(let actor of this.result)
this.actorEditor.selectActor(actor);
}
};
\ No newline at end of file
......@@ -18,10 +18,9 @@ module.exports = class Actor_Search_GUI
this.searchValue = "";
this._createView(uiNode);
this._initFilters();
this._initActions();
this.resultNode = uiNode.querySelector(".data-resultTable");
}
/**
......@@ -41,6 +40,9 @@ module.exports = class Actor_Search_GUI
onDragEnd: () => this.windowNode.classList.remove("isMoving"),
useGPU: true
});
this.resultNode = uiNode.querySelector(".data-resultTable");
this.resultCount = uiNode.querySelector(".data-resultCount");
}
/**
......@@ -50,14 +52,25 @@ module.exports = class Actor_Search_GUI
{
const result = this.actorFinder.search(this.searchValue, this.filter);
let i = 0;
this.resultNode.innerHTML = result.reduce((resultHtml, actor) => {
return resultHtml + `<tr>
return resultHtml + `<tr data-actorIndex="${i++}" class="${actor.selected ? "active" : ""}">
<td>${actor.getName()}</td>
<td>${actor.getHashId()}</td>
<td>${actor.getSRTHash()}</td>
<td>${actor.type}</td>
</tr>`;
}, "");
this.resultCount.innerHTML = result.length || 0;
}
_triggerSelectAll()
{
for(let row of this.resultNode.children)
row.classList.add("active");
this.actorFinder.selectAll();
}
/**
......@@ -92,6 +105,23 @@ module.exports = class Actor_Search_GUI
*/
_initActions()
{
this.windowNode.querySelector(".data-tool-selectAll").onclick = () => this.actorFinder.selectAll();
this.windowNode.querySelector(".data-tool-selectAll").onclick = () => this._triggerSelectAll();
this.resultNode.onclick = ev => {
for(const node of ev.path) {
if(node instanceof HTMLTableRowElement) {
const actorIndex = node.getAttribute("data-actorIndex");
if(node.classList.contains("active")) {
this.actorFinder.deselectIndex(actorIndex);
node.classList.remove("active");
} else {
this.actorFinder.selectIndex(actorIndex);
node.classList.add("active");
}
}
}
};
}
};
\ No newline at end of file
......@@ -89,10 +89,7 @@ module.exports = class Actor_Editor
{
if(!isMouseUp)
{
if(!this.selectedActors.includes(actor))
{
this._addToSelection(actor);
}
this.selectActor(actor);
}else if(!mouseMoved && !this.actorAdded && this.selectedActors.includes(actor))
{
this.deselectActor(actor);
......@@ -169,9 +166,13 @@ module.exports = class Actor_Editor
this.selectedActors = [];
}
_addToSelection(actor)
selectActor(actor)
{
if(this.selectedActors.includes(actor))
return;
this.selectedActors.push(actor);
actor.selected = true;
actor.setColor([1.0, 0.3, 0.3, 1.0]);
this.actorAdded = true;
......@@ -190,6 +191,7 @@ module.exports = class Actor_Editor
_removeActorSelection(actor)
{
actor.selected = false;
actor.setColor([1.0, 1.0, 1.0, 1.0]);
this.mubinRenderer.deselectActor(actor);
}
......
......@@ -40,7 +40,7 @@ module.exports = class Mubin_Editor
this.actorLoader = new Actor_Loader(this.actorHandler, (actorType) => this.generateMubinPath(actorType));
this.prodLoader = new PROD_Loader( this.actorHandler, (actorType) => this.generateProdPath(actorType));
this.actorFinder = new Actor_Search_Finder(this.actorHandler);
this.actorFinder = new Actor_Search_Finder(this.actorHandler, this.actorEditor);
this.loadActorData = true;
this.loadProdData = false;
......
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