diff --git a/src/ArmorAddonOverrideService.cpp b/src/ArmorAddonOverrideService.cpp index 8e82385..752f6a5 100644 --- a/src/ArmorAddonOverrideService.cpp +++ b/src/ArmorAddonOverrideService.cpp @@ -199,11 +199,9 @@ void ArmorAddonOverrideService::setLocationBasedAutoSwitchEnabled(bool newValue) } void ArmorAddonOverrideService::setOutfitUsingLocation(LocationType location) { - if (locationBasedAutoSwitchEnabled) { - auto it = locationOutfits.find(location); - if (it != locationOutfits.end()) { - this->setOutfit(it->second.c_str()); - } + auto it = locationOutfits.find(location); + if (it != locationOutfits.end()) { + this->setOutfit(it->second.c_str()); } } diff --git a/src/OutfitSystem.cpp b/src/OutfitSystem.cpp index e0ad2d6..54d6076 100644 --- a/src/OutfitSystem.cpp +++ b/src/OutfitSystem.cpp @@ -587,9 +587,9 @@ UInt32 GetAutoSwitchLocationCount(VMClassRegistry* registry, UInt32 stackId, StaticFunctionTag*) { return 3; } - void SetOutfitUsingLocation(VMClassRegistry* registry, UInt32 stackId, StaticFunctionTag*, BGSLocation* location_skse) { - // NOTE: Location can be NULL. - auto location = (RE::BGSLocation*) location_skse; + LocationType identifyLocation(RE::BGSLocation* location) { + // Just a helper function to classify a location. + // TODO: Think of a better place than this since we're not exposing it to Papyrus. std::optional classifiedLocation; while (location) { std::set keywords; @@ -610,18 +610,27 @@ } location = location->parentLoc; } - + return classifiedLocation.value_or(LocationType::World); + } + UInt32 IdentifyLocationType(VMClassRegistry* registry, UInt32 stackId, StaticFunctionTag*, BGSLocation* location_skse) { + return static_cast(identifyLocation((RE::BGSLocation*) location_skse)); + } + void SetOutfitUsingLocation(VMClassRegistry* registry, UInt32 stackId, StaticFunctionTag*, BGSLocation* location_skse) { + // NOTE: Location can be NULL. auto& service = ArmorAddonOverrideService::GetInstance(); - // Debug notifications for location classification. if (service.locationBasedAutoSwitchEnabled) { - const char* locationName = locationTypeStrings[static_cast(classifiedLocation.value_or(LocationType::World))]; + auto location = identifyLocation((RE::BGSLocation*) location_skse); + // Debug notifications for location classification. + /* + const char* locationName = locationTypeStrings[static_cast(location)]; char message[100]; sprintf_s(message, "SOS: This location is a %s.", locationName); RE::DebugNotification(message, nullptr, false); + */ + service.setOutfitUsingLocation(location); } - service.setOutfitUsingLocation(classifiedLocation.value_or(LocationType::World)); } void SetLocationOutfit(VMClassRegistry* registry, UInt32 stackId, StaticFunctionTag*, UInt32 location, BSFixedString name) { if (strcmp(name.data, "") == 0) { @@ -878,10 +887,16 @@ bool OutfitSystem::RegisterPapyrus(VMClassRegistry* registry) { registry )); registry->RegisterFunction(new NativeFunction0( - "GetAutoSwitchLocationCount", - "SkyrimOutfitSystemNativeFuncs", - GetAutoSwitchLocationCount, - registry + "GetAutoSwitchLocationCount", + "SkyrimOutfitSystemNativeFuncs", + GetAutoSwitchLocationCount, + registry + )); + registry->RegisterFunction(new NativeFunction1( + "IdentifyLocationType", + "SkyrimOutfitSystemNativeFuncs", + IdentifyLocationType, + registry )); registry->RegisterFunction(new NativeFunction1( "SetOutfitUsingLocation", diff --git a/src/papyrus/skyoutsysmcm.psc b/src/papyrus/skyoutsysmcm.psc index d4c619a..7077b78 100644 --- a/src/papyrus/skyoutsysmcm.psc +++ b/src/papyrus/skyoutsysmcm.psc @@ -183,11 +183,12 @@ EndFunction Int iAutoswitchIndex = StringUtil.Substring(sState, 19) as Int If aiIndex == -1 ; user wants no outfit SkyrimOutfitSystemNativeFuncs.UnsetLocationOutfit(iAutoswitchIndex) + SetMenuOptionValueST("$SkyOutSys_AutoswitchEdit_None") Else ; set the requested outfit String sOutfitName = _sOutfitNames[aiIndex] SkyrimOutfitSystemNativeFuncs.SetLocationOutfit(iAutoswitchIndex, sOutfitName) + SetMenuOptionValueST(SkyrimOutfitSystemNativeFuncs.GetLocationOutfit(iAutoswitchIndex)) EndIf - SetMenuOptionValueST(SkyrimOutfitSystemNativeFuncs.GetLocationOutfit(iAutoswitchIndex)) Return EndIf EndEvent @@ -239,12 +240,17 @@ EndFunction AddHeaderOption("$SkyOutSys_MCMHeader_Autoswitch") Int iCount = SkyrimOutfitSystemNativeFuncs.GetAutoSwitchLocationCount() AddToggleOptionST("OPT_AutoswitchEnabled", "$SkyOutSys_Text_EnableAutoswitch", SkyrimOutfitSystemNativeFuncs.GetLocationBasedAutoSwitchEnabled()) - Int iIterator = 0 - While iIterator < iCount - String sLocationOutfit = SkyrimOutfitSystemNativeFuncs.GetLocationOutfit(iIterator) - AddMenuOptionST("OPT_AutoswitchEntry" + iIterator, "$SkyOutSys_Text_Autoswitch" + iIterator, sLocationOutfit) - iIterator = iIterator + 1 - EndWhile + If SkyrimOutfitSystemNativeFuncs.GetLocationBasedAutoSwitchEnabled() + Int iIterator = 0 + While iIterator < iCount + String sLocationOutfit = SkyrimOutfitSystemNativeFuncs.GetLocationOutfit(iIterator) + If sLocationOutfit == "" + sLocationOutfit = "$SkyOutSys_AutoswitchEdit_None" + EndIf + AddMenuOptionST("OPT_AutoswitchEntry" + iIterator, "$SkyOutSys_Text_Autoswitch" + iIterator, sLocationOutfit) + iIterator = iIterator + 1 + EndWhile + EndIf ;/EndBlock/; EndFunction @@ -270,6 +276,7 @@ EndFunction Event OnSelectST() SkyrimOutfitSystemNativeFuncs.SetLocationBasedAutoSwitchEnabled(!SkyrimOutfitSystemNativeFuncs.GetLocationBasedAutoSwitchEnabled()) SetToggleOptionValueST(SkyrimOutfitSystemNativeFuncs.GetLocationBasedAutoSwitchEnabled()) + ForcePageReset() EndEvent Event OnHighlightST() SetInfoText("$SkyOutSys_Desc_EnableAutoswitch") diff --git a/src/papyrus/skyoutsysquicksloteffect.psc b/src/papyrus/skyoutsysquicksloteffect.psc index d517794..acd54fd 100644 --- a/src/papyrus/skyoutsysquicksloteffect.psc +++ b/src/papyrus/skyoutsysquicksloteffect.psc @@ -25,6 +25,15 @@ Event OnEffectStart(Actor akCaster, Actor akTarget) Endif If result != "[DISMISS]" SkyrimOutfitSystemNativeFuncs.SetSelectedOutfit(result) + ; Update the autoswitch slot if + ; 1) autoswitching is enabled, + ; 2) the current location has an outfit assigned already, and + ; 3) if we have an outfit selected in this menu + Int playerLocationType = SkyrimOutfitSystemNativeFuncs.IdentifyLocationType(Game.GetPlayer().GetCurrentLocation()) + If SkyrimOutfitSystemNativeFuncs.GetLocationBasedAutoSwitchEnabled() && SkyrimOutfitSystemNativeFuncs.GetLocationOutfit(playerLocationType) != "" && result != "" + SkyrimOutfitSystemNativeFuncs.SetLocationOutfit(playerLocationType, result) + Debug.Notification("This outfit will be remembered for this location type.") + EndIf SkyrimOutfitSystemNativeFuncs.RefreshArmorFor(Game.GetPlayer()) Endif EndEvent diff --git a/src/papyrus/skyrimoutfitsystemnativefuncs.psc b/src/papyrus/skyrimoutfitsystemnativefuncs.psc index 40b903c..132c9d1 100644 --- a/src/papyrus/skyrimoutfitsystemnativefuncs.psc +++ b/src/papyrus/skyrimoutfitsystemnativefuncs.psc @@ -80,6 +80,7 @@ Bool Function OutfitExists (String asOutfitName) Global Native Function SetLocationBasedAutoSwitchEnabled (Bool abEnabled) Global Native Bool Function GetLocationBasedAutoSwitchEnabled () Global Native Int Function GetAutoSwitchLocationCount () Global Native +Int Function IdentifyLocationType (Location alLocation) Global Native Function SetOutfitUsingLocation (Location alLocation) Global Native Function SetLocationOutfit (Int aiLocationType, String asOutfitName) Global Native Function UnsetLocationOutfit (Int aiLocationType) Global Native