Skip to content

Commit

Permalink
refactor: added pragmas to showLootCommand procedure
Browse files Browse the repository at this point in the history
FossilOrigin-Name: ce8391929c2fe3f6f535f52514b72f241160179c97969f109531c4c4da90949f
  • Loading branch information
thindil committed Jul 29, 2024
1 parent fe95ad2 commit 49f4ec6
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions nim/src/ui/baseslootui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const defaultItemsSortOrder: ItemsSortOrders = none
var itemsSortOrder: ItemsSortOrders = defaultItemsSortOrder

proc showLootCommand(clientData: cint; interp: PInterp; argc: cint;
argv: cstringArray): TclResults {.exportc.} =
argv: cstringArray): TclResults {.sideEffect, raises: [], tags: [
RootEffect], exportc.} =
var lootFrame = mainPaned & ".lootframe"
let lootCanvas = lootFrame & ".canvas"
var label = lootCanvas & ".loot.options.typelabel"
Expand Down Expand Up @@ -67,16 +68,22 @@ proc showLootCommand(clientData: cint; interp: PInterp; argc: cint;
break
let
protoIndex = playerShip.cargo[index].protoIndex
itemType = (if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
itemType = try:
(if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
except:
return showError(message = "Can't get item type.")
if not itemsTypes.contains(sub = "{" & itemType & "}"):
itemsTypes.add(y = " {" & itemType & "}")
var
currentItemIndex = 1
indexesList: seq[Natural]
currentRow = 1
let
page = (if argc == 3: ($argv[2]).parseInt else: 1)
page = try:
(if argc == 3: ($argv[2]).parseInt else: 1)
except:
return showError(message = "Can't get page number.")
startRow = ((page - 1) * gameSettings.listsLimit) + 1
const tableTooltip = "Show item's description and actions"
for index in itemsIndexes:
Expand All @@ -89,8 +96,11 @@ proc showLootCommand(clientData: cint; interp: PInterp; argc: cint;
durability = playerShip.cargo[index].durability)
if baseCargoIndex > -1:
indexesList.add(y = baseCargoIndex)
let itemType = (if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
let itemType = try:
(if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
except:
return showError(message = "Can't get item type2.")
if argc > 1 and argv[1] != "All" and itemType != $argv[1]:
continue
if currentRow < startRow:
Expand Down Expand Up @@ -120,8 +130,11 @@ proc showLootCommand(clientData: cint; interp: PInterp; argc: cint;
for index in currentItemIndex .. itemsIndexes.high:
let
protoIndex = currentBaseCargo[itemsIndexes[index]].protoIndex
itemType = (if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
itemType = try:
(if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
except:
return showError(message = "Can't get item type3.")
if not itemsTypes.contains(sub = "{" & itemType & "}"):
itemsTypes.add(y = " {" & itemType & "}")
for index in currentItemIndex .. itemsIndexes.high:
Expand All @@ -131,14 +144,20 @@ proc showLootCommand(clientData: cint; interp: PInterp; argc: cint;
continue
let
protoIndex = currentBaseCargo[itemsIndexes[index]].protoIndex
itemType = (if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
itemType = try:
(if itemsList[protoIndex].showType.len == 0: itemsList[
protoIndex].itemType else: itemsList[protoIndex].showType)
except:
return showError(message = "Can't get item type4.")
if argc == 2 and argv[1] != "All" and itemType != $argv[1]:
continue
if currentRow < startRow:
currentRow.inc
continue
let itemName = itemsList[protoIndex].name
let itemName = try:
itemsList[protoIndex].name
except:
return showError(message = "Can't get item name.")
addButton(table = lootTable, text = itemName, tooltip = tableTooltip,
command = "ShowLootItemInfo -" & $(itemsIndexes[index] + 1), column = 1)
addButton(table = lootTable, text = itemType, tooltip = tableTooltip,
Expand Down Expand Up @@ -174,7 +193,10 @@ proc showLootCommand(clientData: cint; interp: PInterp; argc: cint;
tclEval(script = comboBox & " configure -values [list " & itemsTypes & "]")
if argc == 1:
tclEval(script = comboBox & " current 0")
var freeSpace = freeCargo(amount = 0)
var freeSpace = try:
freeCargo(amount = 0)
except:
return showError(message = "Can't count free space.")
if freeSpace < 0:
freeSpace = 0
let tradeInfo = "Free cargo space: " & $(freeSpace) & " kg."
Expand Down

0 comments on commit 49f4ec6

Please sign in to comment.