Skip to content

Commit

Permalink
Fixes and preparing to multiple ent selection.
Browse files Browse the repository at this point in the history
Fixes and preparing to multiple ent selection.
  • Loading branch information
Karaulov committed Nov 24, 2022
1 parent 2ff3acd commit 3dd68b5
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 108 deletions.
3 changes: 1 addition & 2 deletions imgui/misc/cpp/imgui_stdlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ static int InputTextCallback(ImGuiInputTextCallbackData* data)
std::string* str = user_data->Str;
if (data->BufTextLen > 0)
{
IM_ASSERT(data->Buf == str->c_str());
str->resize(data->BufTextLen);
data->Buf = (char*)str->c_str();
}
else
else if (data->Buf == str->c_str())
{
str->clear();
}
Expand Down
1 change: 0 additions & 1 deletion src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void Bsp::selectModelEnt()
{
g_app->clearSelection();
g_app->selectMap(map);
g_app->pickInfo.ent = map->ents[n];
g_app->pickInfo.entIdx = n;
return;
}
Expand Down
18 changes: 8 additions & 10 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ void BspRenderer::drawPointEntities(int highlightEnt)
colorShader->popMatrix(MAT_MODEL);
}

bool BspRenderer::pickPoly(vec3 start, const vec3& dir, int hullIdx, PickInfo& tempPickInfo)
bool BspRenderer::pickPoly(vec3 start, const vec3& dir, int hullIdx, PickInfo& tempPickInfo, Bsp** tmpMap)
{
bool foundBetterPick = false;

Expand All @@ -1837,15 +1837,15 @@ bool BspRenderer::pickPoly(vec3 start, const vec3& dir, int hullIdx, PickInfo& t
}
start -= mapOffset;



if (pickModelPoly(start, dir, vec3(0, 0, 0), 0, hullIdx, tempPickInfo))
{
if (tempPickInfo.map || (tempPickInfo.map && map && tempPickInfo.map == map))
if (*tmpMap || (*tmpMap && map && *tmpMap == map))
{
tempPickInfo.entIdx = 0;
tempPickInfo.modelIdx = 0;
tempPickInfo.map = map;
tempPickInfo.ent = map->ents[0];
*tmpMap = map;
foundBetterPick = true;
}
}
Expand Down Expand Up @@ -1876,12 +1876,11 @@ bool BspRenderer::pickPoly(vec3 start, const vec3& dir, int hullIdx, PickInfo& t

if (pickModelPoly(start, dir, renderEnts[i].offset, renderEnts[i].modelIdx, hullIdx, tempPickInfo))
{
if (!tempPickInfo.map || (tempPickInfo.map && map && tempPickInfo.map == map))
if (!*tmpMap || (*tmpMap && map && *tmpMap == map))
{
tempPickInfo.entIdx = i;
tempPickInfo.modelIdx = renderEnts[i].modelIdx;
tempPickInfo.map = map;
tempPickInfo.ent = map->ents[i];
*tmpMap = map;
foundBetterPick = true;
}
}
Expand All @@ -1892,13 +1891,12 @@ bool BspRenderer::pickPoly(vec3 start, const vec3& dir, int hullIdx, PickInfo& t
vec3 maxs = renderEnts[i].offset + renderEnts[i].pointEntCube->maxs;
if (pickAABB(start, dir, mins, maxs, tempPickInfo.bestDist))
{
if (!tempPickInfo.map || (tempPickInfo.map && map && tempPickInfo.map == map))
if (!*tmpMap || (*tmpMap && map && *tmpMap == map))
{
tempPickInfo.entIdx = i;
tempPickInfo.modelIdx = -1;
tempPickInfo.faceIdx = -1;
tempPickInfo.map = map;
tempPickInfo.ent = map->ents[i];
*tmpMap = map;
foundBetterPick = true;
}
};
Expand Down
6 changes: 1 addition & 5 deletions src/editor/BspRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,10 @@ struct PickInfo
int modelIdx;
int faceIdx;
float bestDist;
Entity* ent;
Bsp* map;
PickInfo()
{
bestDist = 0.0f;
entIdx = modelIdx = faceIdx = -1;
ent = NULL;
map = NULL;
}
};

Expand All @@ -129,7 +125,7 @@ class BspRenderer
void drawModelClipnodes(int modelIdx, bool highlight, int hullIdx);
void drawPointEntities(int highlightEnt);

bool pickPoly(vec3 start, const vec3& dir, int hullIdx, PickInfo& pickInfo);
bool pickPoly(vec3 start, const vec3& dir, int hullIdx, PickInfo& pickInfo, Bsp ** map);
bool pickModelPoly(vec3 start, const vec3& dir, vec3 offset, int modelIdx, int hullIdx, PickInfo& pickInfo);
bool pickFaceMath(const vec3& start, const vec3& dir, FaceMath& faceMath, float& bestDist);

Expand Down
4 changes: 2 additions & 2 deletions src/editor/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ DeleteEntityCommand::DeleteEntityCommand(std::string desc, PickInfo& pickInfo)
{
this->entIdx = pickInfo.entIdx;
this->entData = new Entity();
*this->entData = *pickInfo.ent;
*this->entData = *(g_app->getSelectedMap()->ents[entIdx]);
this->allowedDuringLoad = true;
}

Expand Down Expand Up @@ -486,7 +486,7 @@ EditBspModelCommand::EditBspModelCommand(std::string desc, PickInfo& pickInfo, L
this->newLumps = newLumps;
this->allowedDuringLoad = false;
this->oldOrigin = oldOrigin;
this->newOrigin = pickInfo.ent->getOrigin();
this->newOrigin = (g_app->getSelectedMap()->ents[entIdx])->getOrigin();
}

EditBspModelCommand::~EditBspModelCommand()
Expand Down
36 changes: 16 additions & 20 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,20 +443,21 @@ void Gui::draw3dContextMenus()

Bsp* map = app->getSelectedMap();

if (map && app->originHovered)
if (map && app->originHovered && app->pickInfo.entIdx >= 0)
{
Entity* ent = map->ents[app->pickInfo.entIdx];
if (ImGui::BeginPopup("ent_context") || ImGui::BeginPopup("empty_context"))
{
if (ImGui::MenuItem("Center", ""))
{
app->transformedOrigin = app->getEntOrigin(map, app->pickInfo.ent);
app->transformedOrigin = app->getEntOrigin(map, ent);
app->applyTransform();
app->pickCount++; // force gui refresh
}

if (app->pickInfo.ent && ImGui::BeginMenu("Align"))
if (ent && ImGui::BeginMenu("Align"))
{
BSPMODEL& model = map->models[app->pickInfo.ent->getBspModelIdx()];
BSPMODEL& model = map->models[ent->getBspModelIdx()];

if (ImGui::MenuItem("Top"))
{
Expand Down Expand Up @@ -1219,7 +1220,7 @@ void Gui::drawMenuBar()
std::string redoTitle = redoCmd ? "Redo " + redoCmd->desc : "Can't redo";
bool canUndo = undoCmd && (!app->isLoading || undoCmd->allowedDuringLoad);
bool canRedo = redoCmd && (!app->isLoading || redoCmd->allowedDuringLoad);
bool entSelected = app->pickInfo.ent;
bool entSelected = app->pickInfo.entIdx >= 0;
bool mapSelected = map;
bool nonWorldspawnEntSelected = entSelected && app->pickInfo.entIdx != 0;

Expand Down Expand Up @@ -1913,11 +1914,11 @@ void Gui::drawKeyvalueEditor()
//ImGui::SetNextWindowContentSize(ImVec2(550, 0.0f));
if (ImGui::Begin("Keyvalue Editor", &showKeyvalueWidget, 0))
{
if (app->pickInfo.ent && app->fgd
if (app->pickInfo.entIdx >= 0 && app->fgd
&& !app->isLoading && !app->isModelsReloading && !app->reloading)
{
Bsp* map = app->getSelectedMap();
Entity* ent = app->pickInfo.ent;
Entity* ent = map->ents[app->pickInfo.entIdx];
std::string cname = ent->keyvalues["classname"];
FgdClass* fgdClass = app->fgd->getFgdClass(cname);

Expand Down Expand Up @@ -2015,7 +2016,7 @@ void Gui::drawKeyvalueEditor()
}
else
{
if (!app->pickInfo.ent)
if (!app->pickInfo.entIdx)
ImGui::Text("No entity selected");
else
ImGui::Text("No fgd loaded");
Expand Down Expand Up @@ -2627,9 +2628,9 @@ void Gui::drawTransformWidget()
bool transformingEnt = false;
Entity* ent = NULL;
Bsp* map = app->getSelectedMap();
if (map)
if (map && app->pickInfo.entIdx >= 0)
{
ent = app->pickInfo.ent;
ent = map->ents[app->pickInfo.entIdx];
transformingEnt = app->pickInfo.entIdx > 0;
}

Expand Down Expand Up @@ -4228,9 +4229,8 @@ void Gui::drawLimitTab(Bsp* map, int sortMode)
if (entIdx < map->ents.size())
{
Entity* ent = map->ents[entIdx];
app->pickInfo.ent = ent;
app->pickInfo.entIdx = entIdx;
app->pickInfo.modelIdx = map->ents[entIdx]->getBspModelIdx();
app->pickInfo.modelIdx = ent->getBspModelIdx();
// map should already be valid if limits are showing

if (ImGui::IsMouseDoubleClicked(0))
Expand Down Expand Up @@ -4337,7 +4337,7 @@ void Gui::drawEntityReport()

for (int k = 0; k < MAX_FILTERS; k++)
{
if (keyFilter[k].size())
if (keyFilter[k].size() && keyFilter[k][0] != '\0')
{
std::string searchKey = trimSpaces(toLowerCase(keyFilter[k]));

Expand Down Expand Up @@ -4370,7 +4370,7 @@ void Gui::drawEntityReport()
}
}
}
else if(valueFilter[k].size())
else if(valueFilter[k].size() && valueFilter[k][0] != '\0')
{
std::string searchValue = trimSpaces(toLowerCase(valueFilter[k]));
bool foundMatch = false;
Expand Down Expand Up @@ -4476,14 +4476,10 @@ void Gui::drawEntityReport()
{
if (selectedEnts.find(i) != selectedEnts.end())
{
delete map->ents[i];
}
else
{
newEnts.push_back(map->ents[i]);
app->deleteEnt(i);
}
}
map->ents = std::move(newEnts);

app->deselectObject();
map->getBspRender()->preRenderEnts();
reloadLimits();
Expand Down
Loading

0 comments on commit 3dd68b5

Please sign in to comment.