Reset MCM UI when StartMod fails

This commit is contained in:
Tyler Hallada 2020-10-16 20:20:51 -04:00
parent 561b9574b6
commit 2f61106649
4 changed files with 32 additions and 53 deletions

Binary file not shown.

Binary file not shown.

View File

@ -71,11 +71,25 @@ endState
state START_MOD state START_MOD
event OnSelectST() event OnSelectST()
if BR.StartMod() if BR.StartMod()
Debug.Notification("Starting mod...") int attempts = 0
modStarted = true while BR.ShopId == 0 && !BR.StartModFailed && attempts < 100
SetToggleOptionValueST(true, true) attempts += 1
SetOptionFlagsST(OPTION_FLAG_DISABLED, true) Utility.WaitMenuMode(0.1)
SetOptionFlagsST(OPTION_FLAG_DISABLED, true, "SERVER_URL_VALUE") endWhile
if attempts >= 100
Debug.Trace("BRMCMConfigMenu StartMod failed. ShopId still unset after 100 polls (10 seconds)")
endif
if BR.StartModFailed
Debug.Trace("BRMCMConfigMenu StartMod failed. BR.StartModFailed == true")
else
Debug.Trace("BRMCMConfigMenu StartMod succeeded")
modStarted = true
SetToggleOptionValueST(true, true)
SetOptionFlagsST(OPTION_FLAG_DISABLED, true)
SetOptionFlagsST(OPTION_FLAG_DISABLED, true, "SERVER_URL_VALUE")
endif
endif endif
ForcePageReset() ForcePageReset()
endEvent endEvent
@ -87,9 +101,7 @@ endState
state SAVE_REFS state SAVE_REFS
event OnSelectST() event OnSelectST()
if BR.SaveInteriorRefs() BR.SaveInteriorRefs()
Debug.Notification("Saving shop...")
endif
endEvent endEvent
event OnHighlightST() event OnHighlightST()
@ -99,9 +111,7 @@ endState
state LOAD_REFS state LOAD_REFS
event OnSelectST() event OnSelectST()
if BR.LoadInteriorRefs() BR.LoadInteriorRefs()
Debug.Notification("Loading shop...")
endif
endEvent endEvent
event OnHighlightST() event OnHighlightST()
@ -127,8 +137,4 @@ state LOAD_MERCH
event OnHighlightST() event OnHighlightST()
SetInfoText("Load shop merchandise onto the merchant shelf of the shop.") SetInfoText("Load shop merchandise onto the merchant shelf of the shop.")
endEvent endEvent
endState endState
event OnShopCreate(int result)
Debug.Trace("BRMCMConfigMenu OnShopCreate result: " + result)
endEvent

View File

@ -11,6 +11,7 @@ int property ShopId auto
int property InteriorRefListId = 29 auto ; TODO: temp fixing to id 20 int property InteriorRefListId = 29 auto ; TODO: temp fixing to id 20
int property MerchandiseListId = 2 auto ; TODO: temp fixing to id 2 int property MerchandiseListId = 2 auto ; TODO: temp fixing to id 2
ObjectReference property ShopXMarker auto ObjectReference property ShopXMarker auto
bool property StartModFailed = false auto
UILIB_1 property UILib auto UILIB_1 property UILib auto
int function GetVersion() int function GetVersion()
@ -35,10 +36,12 @@ function Maintenance()
endFunction endFunction
bool function StartMod() bool function StartMod()
debug.Trace("BRQuestScript StartMod") Debug.Trace("BRQuestScript StartMod")
StartModFailed = false
bool result = BRClient.StatusCheck(ApiUrl, self) bool result = BRClient.StatusCheck(ApiUrl, self)
if !result if !result
Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl) Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl)
StartModFailed = true
endif endif
return result return result
endFunction endFunction
@ -53,9 +56,11 @@ event OnStatusCheck(bool result)
bool ownerResult = BROwner.Create(ApiUrl, ApiKey, playerName, ModVersion, self) bool ownerResult = BROwner.Create(ApiUrl, ApiKey, playerName, ModVersion, self)
if !ownerResult if !ownerResult
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
StartModFailed = true
endif endif
else else
Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl) Debug.MessageBox("Failed to initialize Bazaar Realm client. The API server might be down: " + ApiUrl)
StartModFailed = true
endif endif
endEvent endEvent
@ -67,9 +72,11 @@ event OnCreateOwner(int result)
bool shopResult = BRShop.Create(ApiUrl, ApiKey, playerName + "'s Shop", "", self) bool shopResult = BRShop.Create(ApiUrl, ApiKey, playerName + "'s Shop", "", self)
if !shopResult if !shopResult
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
StartModFailed = true
endif endif
else else
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
StartModFailed = true
endif endif
endEvent endEvent
@ -80,48 +87,13 @@ event OnCreateShop(int result)
Debug.Notification("Initialized Bazaar Realm client") Debug.Notification("Initialized Bazaar Realm client")
else else
Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to initialize Bazaar Realm client. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
StartModFailed = true
endif endif
endEvent endEvent
bool function SaveInteriorRefs() bool function SaveInteriorRefs()
; TODO: this should not save anything if player is not currently in their shop ; TODO: this should not save anything if player is not currently in their shop
bool result = BRInteriorRefList.Create(ApiUrl, ApiKey, ShopId, self) bool result = BRInteriorRefList.Create(ApiUrl, ApiKey, ShopId, self)
; Int numRefs = currentCell.GetNumRefs()
; debug.Trace("Num of refs in current cell: " + numRefs)
; Int refIndex = 0
; while refIndex <= numRefs
; ObjectReference ref = currentCell.GetNthRef(refIndex)
; ; if ref != None && ref.IsEnabled()
; ; Form a_form = ref.GetBaseObject()
; ; debug.Trace("Ref " + refIndex + ": " + ref.GetDisplayName())
; ; debug.Trace("Ref position: " + ref.X + ", " + ref.Y + ", " + ref.Z)
; ; debug.Trace("Ref angle: " + ref.getAngleX() + ", " + ref.getAngleY() + ", " + ref.getAngleZ())
; ; debug.Trace("Ref scale: " + ref.GetScale())
; ; debug.Trace("Ref Base Object Name: " + a_form.GetName() + " (" + a_form.GetType() + ")")
; ; Int formId = a_form.GetFormID()
; ; if (formId < 0)
; ; ; GetFormId is broken for light mods, so we have to fix this ourselves
; ; formId = formId + 2147483647 ; formId + INT_MAX
; ; debug.Trace("Ref (light) form id: " + formId)
; ; Int localFormId = Math.LogicalAnd(formId, 4095) + 1 ; (formId & 0xfff) + 1
; ; debug.Trace("Ref (light) local form id: " + localFormId)
; ; Int modIndex = Math.LogicalAnd(Math.RightShift(formId, 12), 4095) ; (formId >> 12) & 0xfff
; ; debug.Trace("Light mod index: " + modIndex)
; ; String modName = Game.GetLightModName(modIndex)
; ; debug.Trace("Light mod name: " + modName)
; ; else
; ; debug.Trace("Ref form id: " + formId)
; ; Int localFormId = Math.LogicalAnd(formId, 16777215); formId & 0xffffff
; ; debug.Trace("Ref local form id: " + localFormId)
; ; Int modIndex = Math.RightShift(formId, 24)
; ; debug.Trace("Mod index: " + modIndex)
; ; String modName = Game.GetModName(modIndex)
; ; debug.Trace("Mod name: " + modName)
; ; endIf
; ; endIf
; debug.Trace("Ref " + refIndex)
; refIndex += 1
; endWhile
if result if result
return true return true
else else
@ -147,6 +119,7 @@ bool function LoadInteriorRefs()
Debug.MessageBox("Failed to load shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.") Debug.MessageBox("Failed to load shop. Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE.")
endif endif
Debug.Trace("ClearCell result: " + result) Debug.Trace("ClearCell result: " + result)
result = BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, ShopXMarker, self) result = BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, ShopXMarker, self)
if result if result
return true return true