Skip to content

Commit

Permalink
Fix stage deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Artyom Shalkhakov committed Feb 6, 2025
1 parent ded186c commit 76bddbf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
47 changes: 38 additions & 9 deletions neo/tools/imgui/particleeditor/ParticleEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ void ParticleEditor::Draw()
if ( removeStagePressed ) {
RemoveStage();
}
RemoveStageThink();
ImGui::SameLine();
bool hideStagePressed = ImGui::Button( "H" );
ImGui::SetItemTooltip( "Hide the selected stage" );
Expand Down Expand Up @@ -1129,23 +1130,51 @@ void ParticleEditor::RemoveStage() {
return;
}

if ( !ImGui::InputMessageBox( "Are you sure you want to remove this stage?", "Remove Stage", true ) ) {
ImGui::OpenPopup( "Remove stage?" );
}

void ParticleEditor::RemoveStageThink()
{
bool accepted = false;
bool canceled = false;

if ( ImGui::BeginPopupModal( "Remove stage?", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) {
ImGui::TextColored( ImVec4( 1, 0, 0, 1 ), "Are you sure you want to remove this stage?" );

if ( ImGui::Button( "OK" ) ) {
accepted = true;
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if ( ImGui::Button( "Cancel" ) ) {
canceled = true;
ImGui::CloseCurrentPopup();
}

ImGui::EndPopup();
}

if ( canceled ) {
return;
}
if ( !accepted ) {
return;
}

idDeclParticle *idp = GetCurParticle();
if ( idp == NULL ) {
return;
}

int index = listStagesSel;
if ( index >= 0 ) {
int newIndex = listStagesItemData.First( index );
if ( newIndex >= 0 && newIndex < idp->stages.Num() ) {
listStages.RemoveIndex( index );
listStagesItemData.Remove( index, newIndex );
listStagesSel = index;
idp->stages.RemoveIndex( newIndex );
index += ( index >= 1 ) ? -1 : 1;
newIndex = comboParticle.FindIndex( idp->GetName() );
EnumParticles();
if ( newIndex >= 0 ) {
comboParticleSel = newIndex;
}
OnCbnSelchangeComboParticles();
listStagesSel = index;
ShowCurrentStage();
}
}
Expand Down Expand Up @@ -1188,7 +1217,7 @@ idParticleStage *ParticleEditor::GetCurStage() {
idDeclParticle *idp = GetCurParticle();
int sel = listStagesSel;
int index = listStagesItemData.First( sel );
if ( idp == NULL || sel == -1 || index >= idp->stages.Num() ) {
if ( idp == NULL || index < 0 || index >= idp->stages.Num() ) {
return NULL;
}
return idp->stages[index];
Expand Down
1 change: 1 addition & 0 deletions neo/tools/imgui/particleeditor/ParticleEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class ParticleEditor {
void EnumParticles();
void AddStage( bool clone );
void RemoveStage();
void RemoveStageThink();
void ShowStage();
void HideStage();
idDeclParticle * GetCurParticle();
Expand Down

0 comments on commit 76bddbf

Please sign in to comment.