Skip to content

Commit

Permalink
Merge pull request #1316 from Courseplay/CopyCourseHudBtn
Browse files Browse the repository at this point in the history
Copy course hud btn
  • Loading branch information
Tensuko committed Apr 4, 2022
2 parents b163997 + a80e448 commit 776eabd
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 66 deletions.
1 change: 1 addition & 0 deletions config/VehicleSettingDisplaySetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-->

<Settings title="CP_vehicle_setting_display">
<Setting type="vehicleSettings" name = "showCourse" />
<Setting type="jobParameters" name = "startAt" />
<Setting type="jobParameters" name = "laneOffset" />
<Setting type="courseGeneratorSettings" name = "workWidth" />
Expand Down
Binary file modified img/helpmenu/minihudhelp.dds
Binary file not shown.
Binary file modified img/ui_courseplay.dds
Binary file not shown.
147 changes: 135 additions & 12 deletions scripts/gui/hud/CpBaseHud.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
--- TODO: Make the hud static and only one instance.
--- Apply the update only when data has changed.
---@class CpBaseHud
CpBaseHud = CpObject()

CpBaseHud.OFF_COLOR = {0.2, 0.2, 0.2, 0.9}

CpBaseHud.RECORDER_ON_COLOR = {1, 0, 0, 0.9}
CpBaseHud.ON_COLOR = {0, 0.6, 0, 0.9}

CpBaseHud.SEMI_ON_COLOR = {0.6, 0.6, 0, 0.9}
CpBaseHud.WHITE_COLOR = {1, 1, 1, 0.9}

CpBaseHud.colorHeader = {
Expand Down Expand Up @@ -35,6 +37,18 @@ CpBaseHud.uvs = {
minusSymbol = {
{128, 512, 128, 128}
},
leftArrowSymbol = {
{384, 512, 128, 128}
},
rightArrowSymbol = {
{512, 512, 128, 128}
},
pasteSymbol = {
{255, 639, 128, 128}
},
copySymbol = {
{127, 637, 128, 128}
},
exitSymbol = {
{148, 184, 32, 32}
},
Expand All @@ -44,11 +58,17 @@ CpBaseHud.uvs = {
clearCourseSymbol = {
{40, 256, 32, 32}
},
eye = {
{148, 148, 32, 32}
}
}

CpBaseHud.xmlKey = "Hud"

CpBaseHud.automaticText = g_i18n:getText("CP_automatic")
CpBaseHud.copyText = g_i18n:getText("CP_copy")

CpBaseHud.courseCache = nil

function CpBaseHud.registerXmlSchema(xmlSchema, baseKey)
xmlSchema:register(XMLValueType.FLOAT, baseKey..CpBaseHud.xmlKey.."#posX", "Hud position x.")
Expand Down Expand Up @@ -222,7 +242,21 @@ function CpBaseHud:init(vehicle)
end
end)


--- Toggle waypoint visibility.
local width, height = getNormalizedScreenValues(20, 20)
local imageFilename = Utils.getFilename('img/iconSprite.dds', g_Courseplay.BASE_DIRECTORY)
local courseVisibilityOverlay = Overlay.new(imageFilename, 0, 0, width, height)
courseVisibilityOverlay:setAlignment(Overlay.ALIGN_VERTICAL_BOTTOM, Overlay.ALIGN_HORIZONTAL_RIGHT)
courseVisibilityOverlay:setUVs(GuiUtils.getUVs(unpack(self.uvs.eye), {256, 512}))
courseVisibilityOverlay:setColor(unpack(CpBaseHud.OFF_COLOR))
self.courseVisibilityBtn = CpHudButtonElement.new(courseVisibilityOverlay, self.baseHud)
local _, y = unpack(self.lines[6].right)
y = y - self.hMargin/16
x = x - width - self.wMargin/4
self.courseVisibilityBtn:setPosition(x, y)
self.courseVisibilityBtn:setCallback("onClickPrimary", self.vehicle, function (vehicle)
vehicle:getCpSettings().showCourse:setNextItem()
end)

--- Lane offset
self.laneOffsetBtn = self:addRightLineTextButton(self.baseHud, 5, self.defaultFontSize,
Expand All @@ -248,9 +282,8 @@ function CpBaseHud:init(vehicle)
self.toolOffsetXBtn = self:addLineTextButton(self.baseHud, 2, self.defaultFontSize,
self.vehicle:getCpSettings().toolOffsetX)

--- Tool offset z
self.toolOffsetZBtn = self:addLineTextButton(self.baseHud, 1, self.defaultFontSize,
self.vehicle:getCpSettings().toolOffsetZ)
--- Copy course btn.
self:addCopyCourseBtn(1)

---- Disables zoom, while mouse is over the cp hud.
local function disableCameraZoomOverHud(vehicle, superFunc, ...)
Expand Down Expand Up @@ -298,7 +331,8 @@ function CpBaseHud:addLineTextButton(parent, line, textSize, setting)

local x, y = unpack(self.lines[line].left)
local dx, dy = unpack(self.lines[line].right)
local element = CpHudSettingElement.new(parent, x, y, dx, dy,
local btnYOffset = self.hMargin*0.1
local element = CpHudSettingElement.new(parent, x, y, dx, y - btnYOffset,
incrementalOverlay, decrementalOverlay, textSize)

local callbackIncremental = {
Expand Down Expand Up @@ -336,6 +370,61 @@ function CpBaseHud:addLineTextButton(parent, line, textSize, setting)
return element
end

--- Setup for the copy course btn.
function CpBaseHud:addCopyCourseBtn(line)
local imageFilename = Utils.getFilename('img/ui_courseplay.dds', g_Courseplay.BASE_DIRECTORY)
local imageFilename2 = Utils.getFilename('img/iconSprite.dds', g_Courseplay.BASE_DIRECTORY)
--- Copy course btn.
self.copyCourseElements = {}
self.copyCourseIx = 1
self.courseVehicles = {}
local leftX, leftY = unpack(self.lines[line].left)
local rightX, rightY = unpack(self.lines[line].right)
local btnYOffset = self.hMargin*0.2

local width, height = getNormalizedScreenValues(22, 22)

local copyOverlay = Overlay.new(imageFilename, 0, 0, width, height)
copyOverlay:setUVs(GuiUtils.getUVs(unpack(self.uvs.copySymbol)))
copyOverlay:setColor(unpack(self.OFF_COLOR))
copyOverlay:setAlignment(Overlay.ALIGN_VERTICAL_BOTTOM, Overlay.ALIGN_HORIZONTAL_RIGHT)

local pasteOverlay = Overlay.new(imageFilename, 0, 0, width, height)
pasteOverlay:setUVs(GuiUtils.getUVs(unpack(self.uvs.pasteSymbol)))
pasteOverlay:setColor(unpack(self.OFF_COLOR))
pasteOverlay:setAlignment(Overlay.ALIGN_VERTICAL_BOTTOM, Overlay.ALIGN_HORIZONTAL_RIGHT)

local clearCourseOverlay = Overlay.new(imageFilename2, 0, 0, width, height)
clearCourseOverlay:setAlignment(Overlay.ALIGN_VERTICAL_BOTTOM, Overlay.ALIGN_HORIZONTAL_RIGHT)
clearCourseOverlay:setUVs(GuiUtils.getUVs(unpack(self.uvs.clearCourseSymbol), {256, 512}))
clearCourseOverlay:setColor(unpack(self.OFF_COLOR))

self.copyButton = CpHudButtonElement.new(copyOverlay, self.baseHud)
self.copyButton:setPosition(rightX, rightY-btnYOffset)
self.copyButton:setCallback("onClickPrimary", self.vehicle, function (vehicle)
if not CpBaseHud.courseCache and self.vehicle:hasCpCourse() then
CpBaseHud.courseCache = self.vehicle:getFieldWorkCourse()
end
end)

self.pasteButton = CpHudButtonElement.new(pasteOverlay, self.baseHud)
self.pasteButton:setPosition(rightX, rightY-btnYOffset)
self.pasteButton:setCallback("onClickPrimary", self.vehicle, function (vehicle)
if CpBaseHud.courseCache and not self.vehicle:hasCpCourse() then
self.vehicle:cpCopyCourse(CpBaseHud.courseCache)
end
end)

self.clearCacheBtn = CpHudButtonElement.new(clearCourseOverlay, self.baseHud)
self.clearCacheBtn:setPosition(rightX - width - self.wMargin/2, rightY - btnYOffset)
self.clearCacheBtn:setCallback("onClickPrimary", self.vehicle, function (vehicle)
CpBaseHud.courseCache = nil
end)

self.copyCacheText = CpTextHudElement.new(self.baseHud, leftX, leftY,self.defaultFontSize)

end

function CpBaseHud:moveToPosition(element, x, y)
CpBaseHud.x = x
CpBaseHud.y = y
Expand Down Expand Up @@ -368,8 +457,7 @@ end

---@param status CpStatus
function CpBaseHud:draw(status)

--- Set variable data.
--- Set variable data.
self.courseNameBtn:setTextDetails(self.vehicle:getCurrentCpCourseName())
self.vehicleNameBtn:setTextDetails(self.vehicle:getName())
if self.vehicle:hasCpCourse() then
Expand Down Expand Up @@ -412,14 +500,49 @@ function CpBaseHud:draw(status)
self.toolOffsetXBtn:setTextDetails(toolOffsetX:getTitle(), text)
self.toolOffsetXBtn:setDisabled(toolOffsetX:getIsDisabled())

local toolOffsetZ = self.vehicle:getCpSettings().toolOffsetZ
text = toolOffsetZ:getIsDisabled() and CpBaseHud.automaticText or toolOffsetZ:getString()
self.toolOffsetZBtn:setTextDetails(toolOffsetZ:getTitle(), text)
self.toolOffsetZBtn:setDisabled(toolOffsetZ:getIsDisabled())

if self.vehicle:hasCpCourse() then
self.courseVisibilityBtn:setVisible(true)
local value = self.vehicle:getCpSettings().showCourse:getValue()
if value == CpVehicleSettings.SHOW_COURSE_DEACTIVATED then
self.courseVisibilityBtn:setColor(unpack(CpBaseHud.OFF_COLOR))
elseif value == CpVehicleSettings.SHOW_COURSE_START_STOP then
self.courseVisibilityBtn:setColor(unpack(CpBaseHud.SEMI_ON_COLOR))
else
self.courseVisibilityBtn:setColor(unpack(CpBaseHud.ON_COLOR))
end
else
self.courseVisibilityBtn:setVisible(false)
end

self:updateCopyBtn(status)


self.baseHud:draw()
end

function CpBaseHud:updateCopyBtn(status)
if self.courseCache then
local courseName = CpCourseManager.getCourseName(self.courseCache)
self.copyCacheText:setTextDetails(self.copyText .. courseName)
self.clearCacheBtn:setVisible(true)
self.pasteButton:setVisible(true)
self.copyButton:setVisible(false)
if self.vehicle:hasCpCourse() then
self.copyCacheText:setTextColorChannels(unpack(self.OFF_COLOR))
self.pasteButton:setColor(unpack(self.OFF_COLOR))
else
self.copyCacheText:setTextColorChannels(unpack(self.WHITE_COLOR))
self.pasteButton:setColor(unpack(self.ON_COLOR))
end
else
self.copyCacheText:setTextDetails("")
self.clearCacheBtn:setVisible(false)
self.pasteButton:setVisible(false)
self.copyButton:setVisible(self.vehicle:hasCpCourse())
end
end

function CpBaseHud:delete()
self.baseHud:delete()
end
Expand Down
6 changes: 3 additions & 3 deletions scripts/gui/hud/HudElements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ end
---@class CpHudSettingElement : CpTextHudElement
CpHudSettingElement = {}
local CpHudSettingElement_mt = Class(CpHudSettingElement, CpHudButtonElement)
function CpHudSettingElement.new(parentHudElement, posX, posY, maxPosX, maxPosY, incrementalOverlay, decrementalOverlay,
function CpHudSettingElement.new(parentHudElement, posX, posY, maxPosX, posBtnY, incrementalOverlay, decrementalOverlay,
textSize, textAlignment, textColor, textBold, customMt)
if customMt == nil then
customMt = CpHudSettingElement_mt
Expand All @@ -386,14 +386,14 @@ function CpHudSettingElement.new(parentHudElement, posX, posY, maxPosX, maxPosY,
self.labelElement:setTextDetails("Label")

self.incrementalElement = CpHudButtonElement.new(incrementalOverlay, parentHudElement)
self.incrementalElement:setPosition(maxPosX,maxPosY)
self.incrementalElement:setPosition(maxPosX, posBtnY)
local w = self.incrementalElement:getWidth()
local x = maxPosX - w*1.5
self.textElement = CpTextHudElement.new(parentHudElement, x, posY, textSize-2,RenderText.ALIGN_RIGHT)
self.textElement:setTextDetails("100.00")
w = self.textElement:getWidth()
self.decrementalElement = CpHudButtonElement.new(decrementalOverlay, parentHudElement)
self.decrementalElement:setPosition(x-w*1.5, posY)
self.decrementalElement:setPosition(x-w*1.5, posBtnY)

return self
end
Expand Down
8 changes: 8 additions & 0 deletions scripts/specializations/CpCourseManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function CpCourseManager.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, 'addCpCourse', CpCourseManager.addCourse)
SpecializationUtil.registerFunction(vehicleType, 'getCpCourses', CpCourseManager.getCourses)
SpecializationUtil.registerFunction(vehicleType, 'hasCpCourse', CpCourseManager.hasCourse)
SpecializationUtil.registerFunction(vehicleType, 'cpCopyCourse', CpCourseManager.cpCopyCourse)

SpecializationUtil.registerFunction(vehicleType, 'appendLoadedCpCourse', CpCourseManager.appendLoadedCourse)
SpecializationUtil.registerFunction(vehicleType, 'saveCpCourses', CpCourseManager.saveCourses)
Expand Down Expand Up @@ -190,6 +191,13 @@ function CpCourseManager:setFieldWorkCourse(course)
course:setVehicle(self)
end

--- Copy the fieldwork course from another vehicle.
function CpCourseManager:cpCopyCourse(course)
if course then
self:setFieldWorkCourse(course:copy())
end
end

function CpCourseManager:setCoursesFromNetworkEvent(courses)
CpCourseManager.resetCourses(self)
CpCourseManager.addCourse(self,courses[1],true)
Expand Down
9 changes: 7 additions & 2 deletions translations/translation_br.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<text name="CP_automatic" text="automático" />
<text name="CP_unit_meter" text="m" />
<text name="CP_unit_foot" text="ft" />
<text name="CP_copy" text="Copy course: "/>

<!-- User info text -->
<text name="CP_infoText" text="Courseplay(%s): Para ajuda, reportar bug ou notas de patch, favor visitar: https://github.com/Courseplay/Courseplay_FS22." />
Expand Down Expand Up @@ -453,12 +454,16 @@ F: Clicar neste ícone abre o menu de configurações globais.
G: Fecha o HUD.
H: Diminuir ou aumentar a largura de trabalho. Uma linha vermelha no seu veículo mostra o valor atual.
I: Valor para deslocamento horizontal, + esquerda, - direita.
J: Valor para deslocamento vertical, + para trás, - para frente.
K, L e M: Clicar no texto irá redefinir suas alterações para os valores padrão.
J: Copy and paste a course to a different vehicle.
Once the copy button was pressed, then the course can be pasted into a vehicle without a course when the icon turns green.
K e L: Clicar no texto irá redefinir suas alterações para os valores padrão.
M: Shows the copied course.
N: Esta área mostra o deslocamento da pista se você tiver uma rota multi implementos carregado para comboio.
Clicar no texto alterna as posições.
O: Iniciar/parar a gravação de campos customizados.
P: Remove a rota do veículo.
Q: Changes the course visibility between: on, off and start/stop only.
R: Removes the copied course from the clipboard.
"/>
<!--CustomField-->
<text name="CP_help_page_customField_title" text="Campo Customizado"/>
Expand Down
9 changes: 7 additions & 2 deletions translations/translation_cs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<text name="CP_automatic" text="自动" />
<text name="CP_unit_meter" text="" />
<text name="CP_unit_foot" text="英尺" />
<text name="CP_copy" text="Copy course: "/>

<!-- User info text -->
<text name="CP_infoText" text="Courseplay(%s):如需帮助、错误报告或查看更新说明,请访问: https://github.com/Courseplay/Courseplay_FS22." />
Expand Down Expand Up @@ -452,11 +453,15 @@ F:点击图标打开常规设置页面。
G:关闭HUD。
H:减少和增加工作宽度。车辆上的红线显示当前设置。
I:横向调整值,+左,-右。
J:纵向调整值,+向后,-向前。
K、 L和M:点击文本将重置对自动值的更改。
J: Copy and paste a course to a different vehicle.
Once the copy button was pressed, then the course can be pasted into a vehicle without a course when the icon turns green.
K 和 L:点击文本将重置对自动值的更改。
M: Shows the copied course.
N:如果你加载了多工具任务,该区域显示车道位置。单击文本可切换位置。
O:开始/停止录制自定义田间任务。
P:从车辆上移除路线
Q: Changes the course visibility between: on, off and start/stop only.
R: Removes the copied course from the clipboard.
"/>
<!--CustomField-->
<text name="CP_help_page_customField_title" text="自定义田地"/>
Expand Down
9 changes: 7 additions & 2 deletions translations/translation_ct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<text name="CP_automatic" text="auto" />
<text name="CP_unit_meter" text="m" />
<text name="CP_unit_foot" text="ft" />
<text name="CP_copy" text="Copy course: "/>

<!-- User info text -->
<text name="CP_infoText" text="Courseplay(%s): For help, bug reports or patch notes, please visit: https://github.com/Courseplay/Courseplay_FS22." />
Expand Down Expand Up @@ -451,11 +452,15 @@ F: Clicking on the icon opens the general settings page.
G: Closes the HUD.
H: Decrease and increase the working width. A red line on your vehicle shows the current setting.
I: Value for horizontal offset, + left, - right.
J: Value for vertical offset, + backward, - forward.
K, L and M: Clicking on the text will reset your changes to the auto values.
J: Copy and paste a course to a different vehicle.
Once the copy button was pressed, then the course can be pasted into a vehicle without a course when the icon turns green.
K and L: Clicking on the text will reset your changes to the auto values.
M: Shows the copied course.
N: This area shows the lane offset if you have a multitool course loaded. Clicking on the text toggles the positions.
O: Start/stop recording a custom field course.
P: Removes course from vehicle
Q: Changes the course visibility between: on, off and start/stop only.
R: Removes the copied course from the clipboard.
"/>
<!--CustomField-->
<text name="CP_help_page_customField_title" text="Custom Fields"/>
Expand Down
9 changes: 7 additions & 2 deletions translations/translation_cz.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<text name="CP_automatic" text="auto" />
<text name="CP_unit_meter" text="m" />
<text name="CP_unit_foot" text="ft" />
<text name="CP_copy" text="Copy course: "/>

<!-- User info text -->
<text name="CP_infoText" text="Courseplay(%s): Pro pomoc, chyby nebo poznámky o opravách se prosím navštivte: https://github.com/Courseplay/Courseplay_FS22. Překlad: SniperKittenCZ" />
Expand Down Expand Up @@ -450,11 +451,15 @@ F: Kliknutím na ikonu se otevře stránka obecných nastavení.
G: Zavře Hud.
H: Snižte a zvětšete pracovní šířku. Červená čára na vašem vozidle ukazuje aktuální nastavení.
I: Hodnota pro horizontální posun, + vlevo, - vpravo.
J: Hodnota pro vertikální posun, + dozadu, - dopředu.
K, L a M: Kliknutím na text resetujete změny na automatické hodnoty.
J: Copy and paste a course to a different vehicle.
Once the copy button was pressed, then the course can be pasted into a vehicle without a course when the icon turns green.
K a L: Kliknutím na text resetujete změny na automatické hodnoty.
M: Shows the copied course.
N: Tato oblast zobrazuje odsazení jízdního pruhu, pokud máte načtený kurz s více nástroji. Kliknutím na text přepnete pozice.
O: Spuštění/zastavení záznamu vlastní trasy na poli.
P: Odstraňuje trasu z vozidla
Q: Changes the course visibility between: on, off and start/stop only.
R: Removes the copied course from the clipboard.
"/>
<!--CustomField-->
<text name="CP_help_page_customField_title" text="Vlastní pole"/>
Expand Down
Loading

0 comments on commit 776eabd

Please sign in to comment.