From 05f40073cf3d52bfe6a520148977ef63d91dbab0 Mon Sep 17 00:00:00 2001 From: vakhoir Date: Tue, 25 Feb 2020 21:30:48 +0100 Subject: [PATCH] Job list stub --- .../modules/DeliverPackage/DeliverPackage.lua | 16 +- data/pigui/libs/debug.lua | 20 +- data/pigui/libs/list.lua | 81 +++---- data/pigui/modules/info-view/04-missions.lua | 223 ++++++++++++++++-- 4 files changed, 263 insertions(+), 77 deletions(-) diff --git a/data/modules/DeliverPackage/DeliverPackage.lua b/data/modules/DeliverPackage/DeliverPackage.lua index 11e294f15d1..3d7ee3d0116 100644 --- a/data/modules/DeliverPackage/DeliverPackage.lua +++ b/data/modules/DeliverPackage/DeliverPackage.lua @@ -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)) diff --git a/data/pigui/libs/debug.lua b/data/pigui/libs/debug.lua index bb4f772c084..6ea518b14d4 100644 --- a/data/pigui/libs/debug.lua +++ b/data/pigui/libs/debug.lua @@ -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 @@ -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) @@ -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 @@ -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() @@ -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() diff --git a/data/pigui/libs/list.lua b/data/pigui/libs/list.lua index de0b261c56e..deab9c69dbd 100644 --- a/data/pigui/libs/list.lua +++ b/data/pigui/libs/list.lua @@ -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, @@ -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, @@ -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, }, } @@ -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 diff --git a/data/pigui/modules/info-view/04-missions.lua b/data/pigui/modules/info-view/04-missions.lua index 39e389f165a..c3282b39013 100644 --- a/data/pigui/modules/info-view/04-missions.lua +++ b/data/pigui/modules/info-view/04-missions.lua @@ -1,27 +1,210 @@ -- Copyright © 2008-2020 Pioneer Developers. See AUTHORS.txt for details -- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt -local ui = require 'pigui' -local InfoView = require 'pigui.views.info-view' local Lang = require 'Lang' -local Debug = require 'pigui.libs.debug' +local Game = require 'Game' +local Format = require 'Format' +local SpaceStation = require 'SpaceStation' +local Character = require 'Character' +local InfoFace = require 'ui.PiguiFace' + +local InfoView = require 'pigui.views.info-view' +local ModalWindow = require 'pigui.libs.modal-win' +local List = require 'pigui.libs.list' +local PiImage = require 'ui.PiImage' +local ui = require 'pigui' +local pionillium = ui.fonts.pionillium +local orbiteer = ui.fonts.orbiteer local l = Lang.GetResource("ui-core") -local view -view = { - id = "missions", - name = l.MISSIONS, - icon = ui.theme.icons.star, - showView = false, - draw = function() - Debug:render() - end, - refresh = function() - Debug = require 'pigui.libs.debug' - view.showView = Debug.showView - Debug.scrollPos = 0 - end, -} - -InfoView:registerView(view) +local colors = ui.theme.colors +local missionDetailsBg = Color(12, 29, 52) + +local vZero = Vector2(0,0) +local adTextColor = colors.white +local searchFlags = ui.WindowFlags {} +local containerFlags = ui.WindowFlags {"AlwaysUseWindowPadding"} +local entryFlags = ui.WindowFlags {"AlwaysUseWindowPadding", "AlwaysAutoResize"} +local widgetSizes = ui.rescaleUI({ + iconSize = Vector2(20, 20), + chatButtonBase = Vector2(0, 24), + chatButtonSize = Vector2(0, 24), + itemSpacing = Vector2(18, 4), + bbContainerSize = Vector2(0, 0), + bbSearchSize = Vector2(0, 0), + bbPadding = Vector2(14, 11), + innerPadding = Vector2(0, 3), + popupSize = Vector2(1200, 0), + popupBig = Vector2(1200, 0), + popupSmall = Vector2(500, 0), + missionDesc = { + -- distLength = ui.calcTextSize(string.format('%.2f %s', 99999, l.LY)) + distLength = 150, + } +}, Vector2(1600, 900)) + + +local selectedItem +local clientFace +local textWrapWidth = 100 +local scrollPosPrev = 0.0 +local scrollPos = 0.0 + +local icons = {} +local currentIconSize = Vector2(0,0) + +local function adActive(ref, ad) + return not ((type(ad.isEnabled) == "function" and not ad.isEnabled(ref)) or Game.paused) +end + +local jobList = List.New("JobList", false, { + size = Vector2(ui.screenWidth * 0.5, 0), + style = { + windowPadding = widgetSizes.innerPadding, + --itemSpacing = Vector2(6, 20), + flags = ui.WindowFlags {"AlwaysUseWindowPadding", "NoScrollbar"}, + }, + beforeItems = function(self) + local sc = math.ceil(-ui.getScrollY()* 100 / ui.getScrollMaxY()) + if scrollPosPrev ~= sc then + scrollPos = sc + elseif scrollPosPrev ~= scrollPos then + ui.setScrollY(math.ceil(-scrollPos/100 * ui.getScrollMaxY())) + end + + scrollPosPrev = scrollPos + end, + beforeRenderItem = function(self, item, key) + 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) + local icon = item.icon or "default" + + if(icons[icon] == nil) then + icons[icon] = PiImage.New("icons/bbs/" .. icon .. ".png") + currentIconSize = icons[icon].texture.size + end + + ui.group(function() + ui.withStyleColorsAndVars({}, {}, function() + ui.dummy(Vector2(0,0)) + + local rightAlignPos = ui.getContentRegion().x - currentIconSize.x - widgetSizes.itemSpacing.x + ui.text(string.upper(item:GetTypeDescription())) + + ui.sameLine(rightAlignPos) + icons[icon]:Draw(widgetSizes.iconSize) + + local dist = Game.system and string.format('%.2f %s', Game.system:DistanceTo(item.location) or "???", l.LY) + rightAlignPos = rightAlignPos - widgetSizes.missionDesc.distLength - widgetSizes.itemSpacing.x + ui.sameLine(rightAlignPos) + ui.text(string.upper(dist)) + + rightAlignPos = rightAlignPos - widgetSizes.missionDesc.distLength - widgetSizes.itemSpacing.x + local days = string.format(l.D_DAYS_LEFT, math.max(0, (item.due - Game.time) / (24*60*60))) + ui.sameLine(rightAlignPos) + ui.text(days) + + + ui.text(item.description or '') + end) + end) + end, + afterRenderItem = function(self, item, key) + ui.dummy(vZero) + end, + onClickItem = function(self, item, key) + if Game.paused then + return + end + + selectedItem = item + clientFace = InfoFace.New(item.client, {windowPadding = widgetSizes.windowPadding, itemSpacing = widgetSizes.itemSpacing, size = widgetSizes.faceSize}) + end, + sortingFunction = function(s1,s2) return s1.description < s2.description end +}) + + +local function refresh() + selectedItem = nil + for ref,mission in pairs(Character.persistent.player.missions) do + for k, v in pairs(mission) do + print(k,v) + end + jobList.items[ref] = mission + end + + --[[ + local station = Game.player:GetDockedWith() + local ads = SpaceStation.adverts[station] + jobList.items = {} + + for ref,ad in pairs(ads) do + if searchText == "" + or searchText ~= "" and string.find( + string.lower(ad.description), + string.lower(searchText), + 1, true) + then + jobList.items[ref] = ad + end + end + ]]-- +end + +local function renderView() + ui.withFont(pionillium.large.name, pionillium.large.size, function() + ui.withStyleVars({WindowPadding = widgetSizes.bbPadding}, function() + ui.child("MissionsContainer", vZero, containerFlags, function() + --print("start", scrollPos) + scrollPos = ui.vSliderInt('###MissionsScrollbar', Vector2(10, ui.getContentRegion().y), scrollPosPrev, -100, 0, "") + ui.sameLine() + ui.child("MissionList", Vector2(ui.screenWidth * 0.5, 0), searchFlags, function() + ui.text("Filter") + ui.sameLine() + ui.text("Sort:") + ui.sameLine() + ui.text("Due") + ui.sameLine() + ui.text("Dist") + ui.sameLine() + ui.text("Importance") + ui.sameLine() + ui.text("Type none") + ui.pushTextWrapPos(textWrapWidth) + jobList:Render() + --print("end", scrollPos) + ui.popTextWrapPos() + end) + + if selectedItem then + ui.sameLine() + ui.withStyleColorsAndVars({ChildWindowBg = missionDetailsBg},{WindowPadding = widgetSizes.bbPadding}, function() + ui.child("MissionDetails", vZero, searchFlags, function() + clientFace:render() + end) + end) + end + end) + end) + end) +end + +InfoView:registerView({ + id = "missions", + name = l.MISSIONS, + icon = ui.theme.icons.star, + showView = true, + draw = renderView, + refresh = function() + refresh() + end, +})