Skip to content

Commit

Permalink
Use user-friendly quantity instead of internal counter
Browse files Browse the repository at this point in the history
Also, refactor the way header text is built
  • Loading branch information
TymurGubayev committed Nov 7, 2023
1 parent 77ab5b9 commit 597c48a
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions gui/job-details.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,45 @@ local function describe_item_traits(iobj)
return table.concat(line1, ', ')
end

local function GetHeader(iobj, items, i, is_active_job)
local q = iobj.quantity
if iobj.min_dimension > 0 then
local q1 = q / iobj.min_dimension
q = math.floor(q1) -- this makes it an int, removing `.0` from `1.0` when converted to string
if q1 ~= q then
-- round to 1 decimal point
q = math.floor(q1 * 10) / 10
end
end

local head = 'Item '..(i+1)
if is_active_job then
head = head..': '..(items[i] or 0)..' of '..q
else
head = head..' (quantity: '..q..')'
end

-- if iobj.min_dimension > 0 then
-- head = head .. ' (size '..iobj.min_dimension..')'
-- end

return head
end

function JobDetails:initListChoices()
local headers = {}
local job_items
local items = {}
local is_active_job = false
if self:isManagerOrder() then
if not self.job.items then
self.list:setChoices({})
return
end

job_items = self.job.items
for i,iobj in ipairs(job_items) do
local head = 'Item '..(i+1)..' x'..iobj.quantity
if iobj.min_dimension > 0 then
head = head .. ' (size '..iobj.min_dimension..')'
end

headers[i] = head
end
else
local items = {}
is_active_job = true

for i,ref in ipairs(self.job.items) do
local idx = ref.job_item_idx
if idx >= 0 then
Expand All @@ -223,14 +242,11 @@ function JobDetails:initListChoices()
end

job_items = self.job.job_items
for i,iobj in ipairs(job_items) do
local head = 'Item '..(i+1)..': '..(items[i] or 0)..' of '..iobj.quantity
if iobj.min_dimension > 0 then
head = head .. ' (size '..iobj.min_dimension..')'
end
end

headers[i] = head
end
local headers = {}
for i,iobj in ipairs(job_items) do
headers[i] = GetHeader(iobj, items, i, is_active_job)
end

local choices = {}
Expand Down

0 comments on commit 597c48a

Please sign in to comment.