Add shop name & desc update, better error handling

This commit is contained in:
Tyler Hallada 2020-10-18 02:33:26 -04:00
parent 2e0a283ce5
commit cd9d11edfd
4 changed files with 186 additions and 29 deletions

View File

@ -22,20 +22,31 @@ event OnPageReset(string page)
if modStarted if modStarted
AddTextOptionST("API_KEY", "Reveal API key", "") AddTextOptionST("API_KEY", "Reveal API key", "")
endif endif
SetCursorPosition(7)
SetCursorPosition(5)
if modStarted if modStarted
AddToggleOptionST("START_MOD", "Mod Started", modStarted, OPTION_FLAG_DISABLED) AddToggleOptionST("START_MOD", "Mod Started", modStarted, OPTION_FLAG_DISABLED)
else else
AddToggleOptionST("START_MOD", "Start Mod", modStarted) AddToggleOptionST("START_MOD", "Start Mod", modStarted)
endif endif
AddHeaderOption("Shop Actions")
SetCursorPosition(10) SetCursorPosition(8)
AddTextOptionST("SAVE_REFS", "Save current shop state", "") if modStarted
AddTextOptionST("LOAD_REFS", "Load saved shop state", "") AddHeaderOption("Shop Config")
AddTextOptionST("LIST_MERCH", "Show shop merchandise", "") SetCursorPosition(10)
AddTextOptionST("LOAD_MERCH", "Load shop merchandise", "") AddTextOptionST("SHOP_NAME_LABEL", "Shop name: ", "", OPTION_FLAG_DISABLED)
AddInputOptionST("SHOP_NAME", "", BR.ShopName)
AddTextOptionST("SHOP_DESC_LABEL", "Shop description: ", "", OPTION_FLAG_DISABLED)
AddInputOptionST("SHOP_DESC", "", BR.ShopDescription)
AddTextOptionST("LOAD_SHOP_CONFIG", "Load shop config from server", "")
SetCursorPosition(18)
AddHeaderOption("Shop Actions")
SetCursorPosition(20)
AddTextOptionST("SAVE_REFS", "Save current shop state", "")
AddTextOptionST("LOAD_REFS", "Load saved shop state", "")
endif
endEvent endEvent
state SERVER_URL_VALUE state SERVER_URL_VALUE
@ -119,22 +130,114 @@ state LOAD_REFS
endEvent endEvent
endState endState
state LIST_MERCH state SHOP_NAME
event OnSelectST() event OnInputOpenST()
BR.ListMerchandise() SetInputDialogStartText(BR.ShopName)
endEvent
event OnInputAcceptST(string textInput)
Debug.Trace("BRMCMConfigMenu BRQuest properties: ShopId: " + BR.ShopId + " ShopName: " + BR.ShopName + " ShopDescription: " + BR.ShopDescription)
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, textInput, BR.ShopDescription)
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100
attempts += 1
Utility.WaitMenuMode(0.1)
endWhile
if attempts >= 100
Debug.Trace("BRMCMConfigMenu BR.UpdateShop failed. BR.UpdateShopComplete still unset after 100 polls (10 seconds)")
endif
SetInputOptionValueST(BR.ShopName)
endEvent endEvent
event OnHighlightST() event OnHighlightST()
SetInfoText("Open a list of every item currently up for sale in your shop's merchandise inventory.") SetInfoText("The name of your shop. This is displayed to other players in the shop menu.")
endEvent
event OnDefaultST()
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, Game.GetPlayer().GetBaseObject().GetName() + "'s Shop", BR.ShopDescription)
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100
attempts += 1
Utility.WaitMenuMode(0.1)
endWhile
if attempts >= 100
Debug.Trace("BRMCMConfigMenu BR.UpdateShop failed. BR.UpdateShopComplete still unset after 100 polls (10 seconds)")
endif
SetInputOptionValueST(BR.ShopName)
endEvent endEvent
endState endState
state LOAD_MERCH state SHOP_DESC
event OnSelectST() event OnInputOpenST()
BR.LoadMerchandise() SetInputDialogStartText(BR.ShopDescription)
endEvent
event OnInputAcceptST(string textInput)
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, BR.ShopName, textInput)
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100
attempts += 1
Utility.WaitMenuMode(0.1)
endWhile
if attempts >= 100
Debug.Trace("BRMCMConfigMenu BR.UpdateShop failed. BR.UpdateShopComplete still unset after 100 polls (10 seconds)")
endif
SetInputOptionValueST(BR.ShopDescription)
endEvent endEvent
event OnHighlightST() event OnHighlightST()
SetInfoText("Load shop merchandise onto the merchant shelf of the shop.") SetInfoText("The description of your shop. This is displayed to other players in the shop menu. This is a useful place to advertise what your shop sells.")
endEvent
event OnDefaultST()
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, BR.ShopName, "")
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100
attempts += 1
Utility.WaitMenuMode(0.1)
endWhile
if attempts >= 100
Debug.Trace("BRMCMConfigMenu BR.UpdateShop failed. BR.UpdateShopComplete still unset after 100 polls (10 seconds)")
endif
SetInputOptionValueST(BR.ShopDescription)
endEvent
endState
state LOAD_SHOP_CONFIG
event OnSelectST()
SetTextOptionValueST("Fetching...")
BR.GetShop(BR.ShopId)
int attempts = 0
while !BR.GetShopComplete && attempts < 100
attempts += 1
Utility.WaitMenuMode(0.1)
endWhile
if attempts >= 100
Debug.Trace("BRMCMConfigMenu BR.GetShop failed. BR.GetShopComplete still unset after 100 polls (10 seconds)")
endif
ForcePageReset()
endEvent
event OnHighlightST()
SetInfoText("Overwrites the shop name and description with values saved on the server. Run this after updating any of your shop config values on the website.")
endEvent endEvent
endState endState

View File

@ -1,3 +1,4 @@
scriptname BROwner scriptname BROwner
bool function Create(string apiUrl, string apiKey, string name, int modVersion, quest quest) global native bool function Create(string apiUrl, string apiKey, string name, int modVersion, quest quest) global native
bool function Update(string apiUrl, string apiKey, int id, string name, int modVersion, quest quest) global native

View File

@ -7,11 +7,15 @@ actor property PlayerRef auto
int property OwnerId auto int property OwnerId auto
; TODO: need to be able to create multiple shops ; TODO: need to be able to create multiple shops
int property ShopId auto int property ShopId auto
string property ShopName auto
string property ShopDescription auto
; TODO: loop up interior refs by shop id instead of saving this ; TODO: loop up interior refs by shop id instead of saving this
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 bool property StartModFailed = false auto
bool property UpdateShopComplete = false auto
bool property GetShopComplete = false auto
UILIB_1 property UILib auto UILIB_1 property UILib auto
int function GetVersion() int function GetVersion()
@ -82,15 +86,18 @@ event OnCreateOwner(int result)
endif endif
endEvent endEvent
event OnCreateShop(int result) event OnCreateShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnCreateShop result: " + result) Debug.Trace("BRQuestScript OnCreateShopSucess id: " + id + " name: " + name + " description: " + description)
if result > -1 ShopId = id
ShopId = result ShopName = name
Debug.Notification("Initialized Bazaar Realm client") ShopDescription = description
else Debug.Notification("Initialized Bazaar Realm client")
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.") endEvent
StartModFailed = true
endif event OnCreateShopFail(string error)
Debug.Trace("BRQuestScript OnCreateShopFail error: " + error)
Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\n" + error + "\n\nPlease 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
endEvent endEvent
bool function SaveInteriorRefs() bool function SaveInteriorRefs()
@ -152,6 +159,50 @@ int function ListMerchandise()
UILib.ShowNotification("Chose " + options[selectedIndex], "#74C56D") UILib.ShowNotification("Chose " + options[selectedIndex], "#74C56D")
endFunction endFunction
bool function LoadMerchandise() function UpdateShop(int id, string name, string description)
Debug.MessageBox("This no longer does anything, sorry.") Debug.Trace("BRQuestScript UpdateShop id: " + id + " name: " + name + " description: " + description)
endFunction UpdateShopComplete = false
bool result = BRShop.Update(ApiUrl, ApiKey, id, name, description, self)
if !result
Debug.MessageBox("Failed to update 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.")
UpdateShopComplete = true
endif
endFunction
event OnUpdateShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnUpdateShopSucess id: " + id + " name: " + name + " description: " + description)
ShopId = id
ShopName = name
ShopDescription = description
UpdateShopComplete = true
endEvent
event OnUpdateShopFail(string error)
Debug.Trace("BRQuestScript OnUpdateShopFail error: " + error)
Debug.MessageBox("Failed to update shop.\n\n" + error + "\n\nPlease 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.")
UpdateShopComplete = true
endEvent
function GetShop(int id)
Debug.Trace("BRQuestScript GetShop id: " + id)
GetShopComplete = false
bool result = BRShop.Get(ApiUrl, ApiKey, id, self)
if !result
Debug.MessageBox("Failed to get 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.")
GetShopComplete = true
endif
endFunction
event OnGetShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnGetShopSucess id: " + id + " name: " + name + " description: " + description)
ShopId = id
ShopName = name
ShopDescription = description
GetShopComplete = true
endEvent
event OnGetShopFail(string error)
Debug.Trace("BRQuestScript OnGetShopFail error: " + error)
Debug.MessageBox("Failed to get shop.\n\n" + error + "\n\nPlease 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.")
GetShopComplete = true
endEvent

View File

@ -1,3 +1,5 @@
scriptname BRShop scriptname BRShop
bool function Create(string apiUrl, string apiKey, string name, string description = "", quest quest) global native bool function Create(string apiUrl, string apiKey, string name, string description = "", quest quest) global native
bool function Update(string apiUrl, string apiKey, int id, string name, string description = "", quest quest) global native
bool function Get(string apiUrl, string apiKey, int id, quest quest) global native