Skip to content

Commit

Permalink
Add ability to setup Secondary Skills in Witch's Hut inside the Editor (
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub authored Dec 22, 2024
1 parent cb90152 commit c649579
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 123 deletions.
2 changes: 2 additions & 0 deletions VisualStudio/fheroes2/sources.props
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<ClCompile Include="src\fheroes2\editor\editor_options.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_rumor_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_save_map_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_secondary_skill_selection.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_spell_selection.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_sphinx_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_ui_helper.cpp" />
Expand Down Expand Up @@ -328,6 +329,7 @@
<ClInclude Include="src\fheroes2\editor\editor_options.h" />
<ClInclude Include="src\fheroes2\editor\editor_rumor_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_save_map_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_secondary_skill_selection.h" />
<ClInclude Include="src\fheroes2\editor\editor_spell_selection.h" />
<ClInclude Include="src\fheroes2\editor\editor_sphinx_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_ui_helper.h" />
Expand Down
45 changes: 32 additions & 13 deletions src/fheroes2/editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "editor_map_specs_window.h"
#include "editor_object_popup_window.h"
#include "editor_save_map_window.h"
#include "editor_secondary_skill_selection.h"
#include "editor_spell_selection.h"
#include "editor_sphinx_window.h"
#include "game.h"
Expand Down Expand Up @@ -352,7 +353,7 @@ namespace
mapFormat.adventureMapEventMetadata.erase( objectIter->id );
break;
case MP2::OBJ_PYRAMID:
mapFormat.spellObjectMetadata.erase( objectIter->id );
mapFormat.selectionObjectMetadata.erase( objectIter->id );
break;
case MP2::OBJ_SIGN:
assert( mapFormat.signMetadata.find( objectIter->id ) != mapFormat.signMetadata.end() );
Expand All @@ -362,6 +363,9 @@ namespace
assert( mapFormat.sphinxMetadata.find( objectIter->id ) != mapFormat.sphinxMetadata.end() );
mapFormat.sphinxMetadata.erase( objectIter->id );
break;
case MP2::OBJ_WITCHS_HUT:
mapFormat.selectionObjectMetadata.erase( objectIter->id );
break;
default:
break;
}
Expand Down Expand Up @@ -424,7 +428,7 @@ namespace
case MP2::OBJ_SHRINE_SECOND_CIRCLE:
case MP2::OBJ_SHRINE_THIRD_CIRCLE:
// We cannot assert non-existing metadata as these objects could have been created by an older Editor version.
mapFormat.spellObjectMetadata.erase( objectIter->id );
mapFormat.selectionObjectMetadata.erase( objectIter->id );
break;
default:
break;
Expand Down Expand Up @@ -1410,11 +1414,11 @@ namespace Interface
}
}
else if ( objectType == MP2::OBJ_SHRINE_FIRST_CIRCLE || objectType == MP2::OBJ_SHRINE_SECOND_CIRCLE || objectType == MP2::OBJ_SHRINE_THIRD_CIRCLE ) {
if ( _mapFormat.spellObjectMetadata.find( object.id ) == _mapFormat.spellObjectMetadata.end() ) {
_mapFormat.spellObjectMetadata[object.id] = {};
if ( _mapFormat.selectionObjectMetadata.find( object.id ) == _mapFormat.selectionObjectMetadata.end() ) {
_mapFormat.selectionObjectMetadata[object.id] = {};
}

auto & originalMetadata = _mapFormat.spellObjectMetadata[object.id];
auto & originalMetadata = _mapFormat.selectionObjectMetadata[object.id];
auto newMetadata = originalMetadata;

int spellLevel = 0;
Expand All @@ -1432,23 +1436,38 @@ namespace Interface
spellLevel = 1;
}

if ( Editor::openSpellSelectionWindow( MP2::StringObject( objectType ), spellLevel, newMetadata.allowedSpells )
&& originalMetadata.allowedSpells != newMetadata.allowedSpells ) {
if ( Editor::openSpellSelectionWindow( MP2::StringObject( objectType ), spellLevel, newMetadata.selectedItems )
&& originalMetadata.selectedItems != newMetadata.selectedItems ) {
fheroes2::ActionCreator action( _historyManager, _mapFormat );
originalMetadata = std::move( newMetadata );
action.commit();
}
}
else if ( objectType == MP2::OBJ_WITCHS_HUT ) {
if ( _mapFormat.selectionObjectMetadata.find( object.id ) == _mapFormat.selectionObjectMetadata.end() ) {
_mapFormat.selectionObjectMetadata[object.id] = {};
}

auto & originalMetadata = _mapFormat.selectionObjectMetadata[object.id];
auto newMetadata = originalMetadata;

if ( Editor::openSecondarySkillSelectionWindow( MP2::StringObject( objectType ), 1, newMetadata.selectedItems )
&& originalMetadata.selectedItems != newMetadata.selectedItems ) {
fheroes2::ActionCreator action( _historyManager, _mapFormat );
originalMetadata = std::move( newMetadata );
action.commit();
}
}
else if ( objectType == MP2::OBJ_PYRAMID ) {
if ( _mapFormat.spellObjectMetadata.find( object.id ) == _mapFormat.spellObjectMetadata.end() ) {
_mapFormat.spellObjectMetadata[object.id] = {};
if ( _mapFormat.selectionObjectMetadata.find( object.id ) == _mapFormat.selectionObjectMetadata.end() ) {
_mapFormat.selectionObjectMetadata[object.id] = {};
}

auto & originalMetadata = _mapFormat.spellObjectMetadata[object.id];
auto & originalMetadata = _mapFormat.selectionObjectMetadata[object.id];
auto newMetadata = originalMetadata;

if ( Editor::openSpellSelectionWindow( MP2::StringObject( objectType ), 5, newMetadata.allowedSpells )
&& originalMetadata.allowedSpells != newMetadata.allowedSpells ) {
if ( Editor::openSpellSelectionWindow( MP2::StringObject( objectType ), 5, newMetadata.selectedItems )
&& originalMetadata.selectedItems != newMetadata.selectedItems ) {
fheroes2::ActionCreator action( _historyManager, _mapFormat );
originalMetadata = std::move( newMetadata );
action.commit();
Expand Down Expand Up @@ -2135,7 +2154,7 @@ namespace Interface
++objectsReplaced;
}

if ( replaceKey( _mapFormat.spellObjectMetadata, object.id, newObjectUID ) ) {
if ( replaceKey( _mapFormat.selectionObjectMetadata, object.id, newObjectUID ) ) {
++objectsReplaced;
}

Expand Down
Loading

0 comments on commit c649579

Please sign in to comment.