Skip to content

Commit

Permalink
Job list stub
Browse files Browse the repository at this point in the history
  • Loading branch information
vakhoir committed Feb 25, 2020
1 parent 7015838 commit 05f4007
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 77 deletions.
16 changes: 9 additions & 7 deletions data/modules/DeliverPackage/DeliverPackage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ local onChat = function (form, ref, option)
ads[ref] = nil

local mission = {
type = "Delivery",
client = ad.client,
location = ad.location,
risk = ad.risk,
reward = ad.reward,
due = ad.due,
flavour = ad.flavour
type = "Delivery",
client = ad.client,
location = ad.location,
risk = ad.risk,
reward = ad.reward,
due = ad.due,
flavour = ad.flavour,
description = ad.desc,
icon = ad.urgency >= 0.8 and "delivery_urgent" or "delivery",
}

table.insert(missions,Mission.New(mission))
Expand Down
20 changes: 12 additions & 8 deletions data/pigui/libs/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ local jobList = List.New("JobList", false, {
flags = ui.WindowFlags {"AlwaysUseWindowPadding", "NoScrollbar"},
},
beforeItems = function(self)
--scrollPos = math.ceil(-scrollPos * ui.getScrollMaxY())

local sc = math.ceil(-ui.getScrollY()* 100 / ui.getScrollMaxY())
if scrollPosPrev ~= sc then
scrollPos = sc
Expand All @@ -71,9 +69,13 @@ local jobList = List.New("JobList", false, {
scrollPosPrev = scrollPos
end,
beforeRenderItem = function(self, item, key)
if self.itemsMeta and self.itemsMeta[key] ~= nil then
ui.addRectFilled(self.itemsMeta[key].min, self.itemsMeta[key].max, Color(8, 19, 40, 230), 0, 0)
ui.addRect(self.itemsMeta[key].min, self.itemsMeta[key].max, Color(25, 64, 90, 230), 0, 0, 2)
if self.itemsMeta[key] ~= nil and self.itemsMeta[key].min and self.itemsMeta[key].max then
if self.highlightedItem == key then
ui.addRectFilled(self.itemsMeta[key].min, self.itemsMeta[key].max, self.style.highlightColor, 0, 0)
else
ui.addRectFilled(self.itemsMeta[key].min, self.itemsMeta[key].max, Color(8, 19, 40), 0, 0)
end
ui.addRect(self.itemsMeta[key].min, self.itemsMeta[key].max, Color(25, 64, 90), 0, 0, 2)
end
end,
renderItem = function(self, item, key)
Expand Down Expand Up @@ -103,6 +105,9 @@ local jobList = List.New("JobList", false, {
end)
end)
end,
afterRenderItem = function(self, item, key)
ui.dummy(vZero)
end,
onClickItem = function(self, item, key)
local station = Game.player:GetDockedWith()
local ref = key
Expand All @@ -111,12 +116,11 @@ local jobList = List.New("JobList", false, {
if Game.paused then
return
end

print('click')
end,
sortingFunction = function(s1,s2) return s1.description < s2.description end
})


local function refresh()

local station = Game.player:GetDockedWith()
Expand All @@ -138,7 +142,7 @@ end
local function drawCommoditytView()
ui.withFont(pionillium.large.name, pionillium.large.size, function()
ui.withStyleVars({WindowPadding = widgetSizes.bbPadding}, function()
ui.child("BulletinBoardContainer", widgetSizes.bbContainerSize(0, ui.getContentRegion().y - StationView.style.height), containerFlags, function()
ui.child("BulletinBoardContainer", vZero, containerFlags, function()
--print("start", scrollPos)
scrollPos = ui.vSliderInt('###BulletinBoardScrollbar', Vector2(10, ui.getContentRegion().y), scrollPosPrev, -100, 0, "")
ui.sameLine()
Expand Down
81 changes: 39 additions & 42 deletions data/pigui/libs/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ local ModalWindow = require 'pigui.libs.modal-win'
local vZero = Vector2(0, 0)

local defaultFuncs = {
beforeItems = function()
beforeItems = function(self)

end,
canDisplayItem = function()
canDisplayItem = function(self, item, key)

end,
beforeRenderItem = function()
beforeRenderItem = function(self, item, key)

end,
renderItem = function()
renderItem = function(self, item, key)

end,
afterRenderItem = function()

afterRenderItem = function(self, item, key)
ui.dummy(vZero)
end,
onMouseOverItem = function()

isMouseOverItem = function(self, item, key)
return (ui.isWindowHovered() and ui.isMouseHoveringRect(self.itemsMeta[key].min, self.itemsMeta[key].max, false))
end,
onMouseOverItem = function(self, item, key)
self.clearHighlight = false
self.highlightedItem = key
end,
onClickItem = function()
onClickItem = function(self, item, key)

end,
afterItems = function()
afterItems = function(self)

end,

Expand Down Expand Up @@ -60,6 +64,9 @@ function ListWidget.New(id, title, config)
end),
title = title,
items = {},
itemsMeta = {},
highlightedItem = nil,
clearHighlight = true,
scrollReset = false,
itemTypes = config.itemTypes or {},
columnCount = config.columnCount or 0,
Expand All @@ -75,14 +82,15 @@ function ListWidget.New(id, title, config)
},
},
funcs = {
beforeItems = config.beforeItems or function() end,
beforeItems = config.beforeItems or defaultFuncs.beforeItems,
canDisplayItem = config.canDisplayItem or defaultFuncs.canDisplayItem,
beforeRenderItem = config.beforeRenderItem or function() end,
beforeRenderItem = config.beforeRenderItem or defaultFuncs.beforeRenderItem,
renderItem = config.renderItem or defaultFuncs.renderItem,
afterRenderItem = config.afterRenderItem or function() ui.dummy(vZero) end,
afterRenderItem = config.afterRenderItem or defaultFuncs.afterRenderItem,
isMouseOverItem = config.isMouseOverItem or defaultFuncs.isMouseOverItem,
onMouseOverItem = config.onMouseOverItem or defaultFuncs.onMouseOverItem,
onClickItem = config.onClickItem or defaultFuncs.onClickItem,
afterItems = config.afterItems or function() end,
afterItems = config.afterItems or defaultFuncs.afterItems,
sortingFunction = config.sortingFunction or defaultFuncs.sortingFunction,
},
}
Expand All @@ -98,50 +106,39 @@ end
function ListWidget:Render()
ui.withStyleColorsAndVars(self.style.styleColors, self.style.styleVars, function()
ui.child("List##" .. self.id, self.style.size, self.style.flags, function()
local startPos
local endPos

local contentRegion = ui.getContentRegion()

self.contentRegion = ui.getContentRegion()
self.clearHighlight = true
self.funcs.beforeItems(self)

self.highlightStart = nil
self.highlightEnd = nil

for key, item in pairs(self.items) do
self.funcs.beforeRenderItem(self, item, key)
if self.itemsMeta[key] == nil then
self.itemsMeta[key] = {}
end

self.itemsMeta[key].min = ui.getCursorScreenPos()
self.itemsMeta[key].min.x = self.itemsMeta[key].min.x - self.style.styleVars.WindowPadding.x / 2

startPos = ui.getCursorScreenPos()
startPos.x = startPos.x - self.style.styleVars.WindowPadding.x / 2
self.funcs.beforeRenderItem(self, item, key)

self.funcs.renderItem(self, item, key)

endPos = ui.getCursorScreenPos()
endPos.x = endPos.x + contentRegion.x + self.style.styleVars.WindowPadding.x / 2
self.itemsMeta[key].max = ui.getCursorScreenPos()
self.itemsMeta[key].max.x = self.itemsMeta[key].max.x + self.contentRegion.x + self.style.styleVars.WindowPadding.x / 2

self.funcs.afterRenderItem(self, item, key)

if self.itemsMeta == nil then
self.itemsMeta = {}
end

if self.itemsMeta[key] == nil then
self.itemsMeta[key] = {}
end

self.itemsMeta[key].min = startPos
self.itemsMeta[key].max = endPos

if ui.isWindowHovered() and ui.isMouseHoveringRect(startPos, endPos, false) then
if self.funcs.isMouseOverItem(self, item, key) then
self.funcs.onMouseOverItem(self, item, key)
if ui.isMouseClicked(0) then
self.funcs.onClickItem(self, item, key)
end

self.highlightStart = startPos
self.highlightEnd = endPos
end
end

self.funcs.afterItems(self)
if self.clearHighlight then
self.highlightedItem = nil
end
end)
end)
end
Expand Down
Loading

0 comments on commit 05f4007

Please sign in to comment.