Skip to content

Commit

Permalink
Always restore previous selection and visibility #199
Browse files Browse the repository at this point in the history
  • Loading branch information
ousnius committed Jun 21, 2019
1 parent 64234c5 commit 9b70ce2
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 33 deletions.
113 changes: 86 additions & 27 deletions src/program/OutfitStudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2183,10 +2183,31 @@ void OutfitStudioFrame::UnlockShapeSelect() {
}

void OutfitStudioFrame::RefreshGUIFromProj() {
outfitShapes->UnselectAll();
LockShapeSelect();

selectedItems.clear();
std::vector<ShapeItemState> prevStates;

if (outfitRoot.IsOk()) {
wxTreeItemIdValue cookie;
wxTreeItemId child = outfitShapes->GetFirstChild(outfitRoot, cookie);
while (child.IsOk()) {
auto itemData = (ShapeItemData*)outfitShapes->GetItemData(child);
if (itemData) {
ShapeItemState prevState;
prevState.shape = itemData->GetShape();
prevState.state = outfitShapes->GetItemState(child);

if (outfitShapes->IsSelected(child))
prevState.selected = true;

prevStates.push_back(prevState);
}

child = outfitShapes->GetNextChild(outfitRoot, cookie);
}

outfitShapes->UnselectAll();
outfitShapes->DeleteChildren(outfitRoot);
outfitShapes->Delete(outfitRoot);
outfitRoot.Unset();
Expand All @@ -2201,39 +2222,74 @@ void OutfitStudioFrame::RefreshGUIFromProj() {
}

wxTreeItemId subItem;
wxTreeItemId prevSelItem;
for (auto &shape : shapes) {
auto itemData = new ShapeItemData(shape);
subItem = outfitShapes->AppendItem(outfitRoot, wxString::FromUTF8(shape->GetName()));
outfitShapes->SetItemState(subItem, 0);
outfitShapes->SetItemData(subItem, new ShapeItemData(shape));
outfitShapes->SetItemData(subItem, itemData);

if (project->IsBaseShape(shape)) {
outfitShapes->SetItemBold(subItem);
outfitShapes->SetItemTextColour(subItem, wxColour(0, 255, 0));
}
}

wxTreeItemId itemToSelect;
wxTreeItemIdValue cookie;
if (outfitRoot.IsOk())
itemToSelect = outfitShapes->GetFirstChild(outfitRoot, cookie);
auto it = std::find_if(prevStates.begin(), prevStates.end(), [&shape](const ShapeItemState& state) {
return state.shape == shape;
});

UnlockShapeSelect();
if (it != prevStates.end()) {
outfitShapes->SetItemState(subItem, it->state);

if (itemToSelect.IsOk()) {
activeItem = (ShapeItemData*)outfitShapes->GetItemData(itemToSelect);
outfitShapes->SelectItem(itemToSelect);
if (it->selected) {
outfitShapes->SelectItem(subItem);
selectedItems.push_back(itemData);

if (!prevSelItem.IsOk())
prevSelItem = subItem;
}
}
}

UnlockShapeSelect();

if (prevSelItem.IsOk())
activeItem = (ShapeItemData*)outfitShapes->GetItemData(prevSelItem);
else
activeItem = nullptr;

selectedItems.clear();
if (activeItem)
selectedItems.push_back(activeItem);

outfitShapes->ExpandAll();
MeshesFromProj();

AnimationGUIFromProj();

wxTreeItemIdValue cookie;
wxTreeItemId child = outfitShapes->GetFirstChild(outfitRoot, cookie);
while (child.IsOk()) {
bool vis = true;
bool ghost = false;

int state = outfitShapes->GetItemState(child);
switch (state) {
case 1:
vis = false;
ghost = false;
break;
case 2:
vis = true;
ghost = true;
break;
default:
vis = true;
ghost = false;
break;
}

std::string shapeName = outfitShapes->GetItemText(child).ToUTF8();
glView->SetShapeGhostMode(shapeName, ghost);
glView->ShowShape(shapeName, vis);
child = outfitShapes->GetNextChild(outfitRoot, cookie);
}
}

void OutfitStudioFrame::AnimationGUIFromProj() {
Expand Down Expand Up @@ -3088,20 +3144,22 @@ void OutfitStudioFrame::ToggleVisibility(wxTreeItemId firstItem) {

if (firstItem.IsOk()) {
state = outfitShapes->GetItemState(firstItem);
if (state == 0) {
switch (state) {
case 0:
vis = false;
ghost = false;
state = 1;
}
else if (state == 1) {
break;
case 1:
vis = true;
ghost = true;
state = 2;
}
else {
break;
default:
vis = true;
ghost = false;
state = 0;
break;
}

std::string shapeName = outfitShapes->GetItemText(firstItem).ToUTF8();
Expand Down Expand Up @@ -3134,6 +3192,11 @@ void OutfitStudioFrame::OnShapeSelect(wxTreeEvent& event) {
return;
}

if (selectionLocked) {
event.Veto();
return;
}

if (outfitShapes->GetItemParent(item).IsOk()) {
if (outfitShapes->IsSelected(item))
activeItem = (ShapeItemData*)outfitShapes->GetItemData(item);
Expand Down Expand Up @@ -3270,11 +3333,6 @@ void OutfitStudioFrame::OnBoneSelect(wxTreeEvent& event) {
}

void OutfitStudioFrame::OnCheckTreeSel(wxTreeEvent& event) {
if (selectionLocked) {
event.Veto();
return;
}

int outflags;
wxPoint p;
wxGetMousePosition(&p.x, &p.y);
Expand Down Expand Up @@ -7565,8 +7623,9 @@ void wxGLPanel::RecalculateMeshBVH(const std::string& shapeName) {

void wxGLPanel::ShowShape(const std::string& shapeName, bool show) {
int id = gls.GetMeshID(shapeName);
gls.SetMeshVisibility(id, show);
gls.RenderOneFrame();
bool changed = gls.SetMeshVisibility(id, show);
if (changed)
gls.RenderOneFrame();
}

void wxGLPanel::SetActiveShapes(const std::vector<std::string>& shapeNames) {
Expand Down
6 changes: 6 additions & 0 deletions src/program/OutfitStudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class ShapeItemData : public wxTreeItemData {
}
};

struct ShapeItemState {
NiShape* shape = nullptr;
int state = 0;
bool selected = false;
};

class SegmentItemData : public wxTreeItemData {
public:
std::set<uint> tris;
Expand Down
18 changes: 14 additions & 4 deletions src/render/GLSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,21 +1600,31 @@ void GLSurface::RecalculateMeshBVH(int shapeIndex) {
m->CreateBVH();
}

void GLSurface::SetMeshVisibility(const std::string& name, bool visible) {
bool GLSurface::SetMeshVisibility(const std::string& name, bool visible) {
bool changed = false;
int shapeIndex = GetMeshID(name);
if (shapeIndex < 0)
return;
return changed;

mesh* m = meshes[shapeIndex];
if (m->bVisible != visible)
changed = true;

m->bVisible = visible;
return changed;
}

void GLSurface::SetMeshVisibility(int shapeIndex, bool visible) {
bool GLSurface::SetMeshVisibility(int shapeIndex, bool visible) {
bool changed = false;
if (shapeIndex >= meshes.size())
return;
return changed;

mesh* m = meshes[shapeIndex];
if (m->bVisible != visible)
changed = true;

m->bVisible = visible;
return changed;
}

void GLSurface::SetOverlayVisibility(const std::string& name, bool visible) {
Expand Down
4 changes: 2 additions & 2 deletions src/render/GLSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ class GLSurface {
void RecalculateMeshBVH(const std::string& shapeName);
void RecalculateMeshBVH(int shapeIndex);

void SetMeshVisibility(const std::string& name, bool visible = true);
void SetMeshVisibility(int shapeIndex, bool visible = true);
bool SetMeshVisibility(const std::string& name, bool visible = true);
bool SetMeshVisibility(int shapeIndex, bool visible = true);
void SetOverlayVisibility(const std::string& name, bool visible = true);
void SetActiveMeshesID(const std::vector<int>& shapeIndices);
void SetActiveMeshesID(const std::vector<std::string>& shapeNames);
Expand Down

0 comments on commit 9b70ce2

Please sign in to comment.