From 610daaf09a1bd6ee00562d52a570a97190c1fc2c Mon Sep 17 00:00:00 2001 From: David Schwietering Date: Wed, 18 Dec 2024 18:52:39 +0100 Subject: [PATCH 1/3] Fixed info text hud position saving --- scripts/gui/hud/CpHudInfoTexts.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/gui/hud/CpHudInfoTexts.lua b/scripts/gui/hud/CpHudInfoTexts.lua index b4db1d187..5df49fb24 100644 --- a/scripts/gui/hud/CpHudInfoTexts.lua +++ b/scripts/gui/hud/CpHudInfoTexts.lua @@ -226,9 +226,7 @@ function CpHudInfoTexts.loadFromXmlFile(xmlFile,baseKey) local posX = xmlFile:getValue(baseKey..CpHudInfoTexts.xmlKey.."#posX") local posY = xmlFile:getValue(baseKey..CpHudInfoTexts.xmlKey.."#posY") if posX ~= nil and posY ~= nil then - CpHudInfoTexts.savedPositions = { - posX, posY - } + g_Courseplay.infoTextsHud:moveToPosition(nil, posX, posY) end end From 76e4924a359e4b6e7c7c6e801d2872b92e8c1639 Mon Sep 17 00:00:00 2001 From: David Schwietering Date: Wed, 18 Dec 2024 19:32:24 +0100 Subject: [PATCH 2/3] Fixes hud movement save bug --- Courseplay.lua | 10 ++-- scripts/gui/hud/CpBaseHud.lua | 10 ++-- scripts/gui/hud/CpHudInfoTexts.lua | 57 ++++++++++----------- scripts/gui/pages/CpGlobalSettingsFrame.lua | 1 + 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Courseplay.lua b/Courseplay.lua index 7e220d65e..78d34e144 100644 --- a/Courseplay.lua +++ b/Courseplay.lua @@ -39,7 +39,7 @@ function Courseplay:loadUserSettings() self.globalSettings:loadFromXMLFile(xmlFile, self.xmlKey) g_cpInGameMenu:loadFromXMLFile(xmlFile, self.xmlKey) CpBaseHud.loadFromXmlFile(xmlFile, self.xmlKey) - CpHudInfoTexts.loadFromXmlFile(xmlFile, self.xmlKey) + self.infoTextsHud:loadFromXmlFile(xmlFile, self.xmlKey) xmlFile:save() xmlFile:delete() else @@ -53,11 +53,11 @@ function Courseplay:saveUserSettings() if xmlFile then self.globalSettings:saveUserSettingsToXmlFile(xmlFile, self.xmlKey) CpBaseHud.saveToXmlFile(xmlFile, self.xmlKey) - CpHudInfoTexts.saveToXmlFile(xmlFile, self.xmlKey) + self.infoTextsHud:saveToXmlFile(xmlFile, self.xmlKey) if self.currentVersion then - xmlFile:setValue(self.baseXmlKey.."#lastVersion", self.currentVersion) + xmlFile:setValue(self.baseXmlKey .. "#lastVersion", self.currentVersion) end - g_cpInGameMenu:saveToXMLFile(xmlFile, g_Courseplay.xmlKey) + g_cpInGameMenu:saveToXMLFile(xmlFile, self.xmlKey) xmlFile:save() xmlFile:delete() end @@ -130,8 +130,6 @@ end function Courseplay:setupGui() CpInGameMenu.setupGui(self.courseStorage) - - self.infoTextsHud = CpHudInfoTexts() -- TODO_25 diff --git a/scripts/gui/hud/CpBaseHud.lua b/scripts/gui/hud/CpBaseHud.lua index f3729960f..8d0f69407 100644 --- a/scripts/gui/hud/CpBaseHud.lua +++ b/scripts/gui/hud/CpBaseHud.lua @@ -109,7 +109,10 @@ function CpBaseHud:init(vehicle) self.baseHud = CpHudMoveableElement.new(background) self.baseHud:setPosition(CpBaseHud.x, CpBaseHud.y) self.baseHud:setDimension(self.width, self.height) - self.baseHud:setCallback("onMove", self, self.moveToPosition) + self.baseHud:setCallback("onMove", self, function (self, _, x, y) + self.x = x + self.y = y + end) self.fieldworkLayout = self:addHudPage(CpFieldWorkHudPageElement, vehicle) @@ -438,9 +441,8 @@ function CpBaseHud:addLineTextButtonWithIncrementalButtons(parent, line, textSiz end -function CpBaseHud:moveToPosition(element, x, y) - CpBaseHud.x = x - CpBaseHud.y = y +function CpBaseHud:moveToPosition(x, y) + self.baseHud:moveTo(x, y) end function CpBaseHud:openClose(open) diff --git a/scripts/gui/hud/CpHudInfoTexts.lua b/scripts/gui/hud/CpHudInfoTexts.lua index 5df49fb24..c31dd4b50 100644 --- a/scripts/gui/hud/CpHudInfoTexts.lua +++ b/scripts/gui/hud/CpHudInfoTexts.lua @@ -34,22 +34,15 @@ CpHudInfoTexts.OFF_COLOR = {0.2, 0.2, 0.2, 0.9} CpHudInfoTexts.SELECTED_COLOR = {0, 0.6, 0, 0.9} CpHudInfoTexts.xmlKey = "HudInfoTexts" -function CpHudInfoTexts.registerXmlSchema(xmlSchema,baseKey) - xmlSchema:register(XMLValueType.FLOAT,baseKey..CpHudInfoTexts.xmlKey.."#posX","Hud position x.") - xmlSchema:register(XMLValueType.FLOAT,baseKey..CpHudInfoTexts.xmlKey.."#posY","Hud position y.") +function CpHudInfoTexts.registerXmlSchema(xmlSchema, baseKey) + xmlSchema:register(XMLValueType.FLOAT, baseKey .. CpHudInfoTexts.xmlKey .. "#posX", "Hud position x") + xmlSchema:register(XMLValueType.FLOAT, baseKey .. CpHudInfoTexts.xmlKey .. "#posY", "Hud position y") end function CpHudInfoTexts:init() self.uiScale = g_gameSettings:getValue("uiScale") - - - if CpHudInfoTexts.savedPositions then - CpHudInfoTexts.x, CpHudInfoTexts.y = unpack(CpHudInfoTexts.savedPositions) - CpHudInfoTexts.savedPositions = nil - end - if CpHudInfoTexts.x == nil or CpHudInfoTexts.y == nil then - CpHudInfoTexts.x, CpHudInfoTexts.y = getNormalizedScreenValues(self.basePosition.x, self.basePosition.y) - end + + self.x, self.y = getNormalizedScreenValues(self.basePosition.x, self.basePosition.y) self.width, self.height = getNormalizedScreenValues(self.baseSize.x, self.baseSize.y) @@ -63,9 +56,12 @@ function CpHudInfoTexts:init() background:setAlignment(Overlay.ALIGN_VERTICAL_TOP, Overlay.ALIGN_HORIZONTAL_LEFT) --- Base hud element. self.baseHud = CpHudMoveableElement.new(background) - self.baseHud:setPosition(CpHudInfoTexts.x, CpHudInfoTexts.y) + self.baseHud:setPosition(self.x, self.y) self.baseHud:setDimension(self.width, self.height) - self.baseHud:setCallback("onMove", self, self.moveToPosition) + self.baseHud:setCallback("onMove", self, function(self, _, x, y) + self.x = x + self.y = y + end) local headerHeight = self.hMargin/2 local headerBackground = Overlay.new(g_baseUIFilename, 0, 0, self.width, headerHeight) @@ -74,19 +70,19 @@ function CpHudInfoTexts:init() headerBackground:setAlignment(Overlay.ALIGN_VERTICAL_TOP, Overlay.ALIGN_HORIZONTAL_LEFT) local topElement = CpHudElement.new(headerBackground, self.baseHud) - topElement:setPosition(CpHudInfoTexts.x, CpHudInfoTexts.y) + topElement:setPosition(self.x, self.y) topElement:setDimension(self.width, headerHeight) - local leftTopText = CpTextHudElement.new(self.baseHud, CpHudInfoTexts.x + self.wMargin, CpHudInfoTexts.y - headerHeight + self.hMargin/16, self.titleFontSize) + local leftTopText = CpTextHudElement.new(self.baseHud, self.x + self.wMargin, self.y - headerHeight + self.hMargin/16, self.titleFontSize) leftTopText:setTextDetails("Courseplay") - local rightTopText = CpTextHudElement.new(self.baseHud, CpHudInfoTexts.x + self.width - self.wMargin, CpHudInfoTexts.y - headerHeight + self.hMargin/16, self.titleFontSize, RenderText.ALIGN_RIGHT) + local rightTopText = CpTextHudElement.new(self.baseHud, self.x + self.width - self.wMargin, self.y - headerHeight + self.hMargin/16, self.titleFontSize, RenderText.ALIGN_RIGHT) rightTopText:setTextDetails(g_Courseplay.currentVersion) local width, height = getNormalizedScreenValues(20, 20) - local x = CpHudInfoTexts.x + self.wMargin + local x = self.x + self.wMargin local dx = x + self.wMargin + width - local y = CpHudInfoTexts.y - self.hMargin - headerHeight + self.lineHeight + local y = self.y - self.hMargin - headerHeight + self.lineHeight self.infoTextsElements = {} for i=1, self.maxLines do y = y - self.lineHeight @@ -118,9 +114,8 @@ function CpHudInfoTexts:mouseEvent(posX, posY, isDown, isUp, button) end end -function CpHudInfoTexts:moveToPosition(element, x, y) - CpHudInfoTexts.x = x - CpHudInfoTexts.y = y +function CpHudInfoTexts:moveToPosition(x, y) + self.baseHud:moveTo(x, y) end function CpHudInfoTexts:draw() @@ -210,23 +205,23 @@ function CpHudInfoTexts:delete() end function CpHudInfoTexts:debug(str,...) - CpUtil.debugFormat(CpDebug.DBG_HUD,"Info text hud "..str,...) + CpUtil.debugFormat(CpDebug.DBG_HUD, "Info text hud " .. str, ...) end --- Saves hud position. -function CpHudInfoTexts.saveToXmlFile(xmlFile,baseKey) - if CpHudInfoTexts.x ~= nil and CpHudInfoTexts.y ~= nil then - xmlFile:setValue(baseKey..CpHudInfoTexts.xmlKey.."#posX",CpHudInfoTexts.x) - xmlFile:setValue(baseKey..CpHudInfoTexts.xmlKey.."#posY",CpHudInfoTexts.y) +function CpHudInfoTexts:saveToXmlFile(xmlFile, baseKey) + if self.x ~= nil and self.y ~= nil then + xmlFile:setValue(baseKey .. self.xmlKey .. "#posX", self.x) + xmlFile:setValue(baseKey .. self.xmlKey .. "#posY", self.y) end end --- Loads hud position. -function CpHudInfoTexts.loadFromXmlFile(xmlFile,baseKey) - local posX = xmlFile:getValue(baseKey..CpHudInfoTexts.xmlKey.."#posX") - local posY = xmlFile:getValue(baseKey..CpHudInfoTexts.xmlKey.."#posY") +function CpHudInfoTexts:loadFromXmlFile(xmlFile, baseKey) + local posX = xmlFile:getValue(baseKey .. self.xmlKey .. "#posX") + local posY = xmlFile:getValue(baseKey .. self.xmlKey .. "#posY") if posX ~= nil and posY ~= nil then - g_Courseplay.infoTextsHud:moveToPosition(nil, posX, posY) + self:moveToPosition(posX, posY) end end diff --git a/scripts/gui/pages/CpGlobalSettingsFrame.lua b/scripts/gui/pages/CpGlobalSettingsFrame.lua index de3bdc2cc..198d013d7 100644 --- a/scripts/gui/pages/CpGlobalSettingsFrame.lua +++ b/scripts/gui/pages/CpGlobalSettingsFrame.lua @@ -116,5 +116,6 @@ function CpGlobalSettingsFrame:updateSubCategoryPages(state) self.subCategoryPages[state]:setVisible(true) self.subCategoryTabs[state]:setSelected(true) local layout = self.subCategoryPages[state]:getDescendantByName("layout") + CpSettingsUtil.updateGuiElementsBoundToSettings(layout) self.settingsSlider:setDataElement(layout) end From 6741c3d7f180dbe16f8ccd0cba53faf4ca351726 Mon Sep 17 00:00:00 2001 From: David Schwietering Date: Wed, 18 Dec 2024 19:43:13 +0100 Subject: [PATCH 3/3] Stupid mistake .. --- scripts/gui/hud/CpBaseHud.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/gui/hud/CpBaseHud.lua b/scripts/gui/hud/CpBaseHud.lua index 8d0f69407..507b199c9 100644 --- a/scripts/gui/hud/CpBaseHud.lua +++ b/scripts/gui/hud/CpBaseHud.lua @@ -110,8 +110,8 @@ function CpBaseHud:init(vehicle) self.baseHud:setPosition(CpBaseHud.x, CpBaseHud.y) self.baseHud:setDimension(self.width, self.height) self.baseHud:setCallback("onMove", self, function (self, _, x, y) - self.x = x - self.y = y + CpBaseHud.x = x + CpBaseHud.y = y end) self.fieldworkLayout = self:addHudPage(CpFieldWorkHudPageElement, vehicle)