Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/HelpMenu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,10 @@
</paragraph>
<paragraph>
<text text="$l10n_CP_help_page_customFieldDone_text"/>
<image filename="img/helpmenu/donecustomhelp.dds" size="1024 1024" uvs="0px 0px 765px 510px" aspectRatio="0.66"/>
</paragraph>
<paragraph>
<text text="$l10n_CP_help_page_customFieldDraw_text"/>
<image filename="img/helpmenu/drawcustomhelp.dds" size="1024 1024" uvs="0px 0px 765px 510px" aspectRatio="0.66"/>
<image filename="img/helpmenu/customfield.dds" size="1024 1024" uvs="0px 0px 765px 510px" aspectRatio="0.66"/>
</paragraph>
</page>
<!--Courseplay Multitool and Convoy-->
Expand Down
21 changes: 15 additions & 6 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,10 @@ The course is saved automatically on closing of the editor and overrides the sel
<Text language="de"><![CDATA[Randkurs]]></Text>
<Text language="en"><![CDATA[Custom field]]></Text>
</Translation>
<Translation name="CP_customFieldManager_fieldList">
<Text language="de"><![CDATA[Randkurse]]></Text>
<Text language="en"><![CDATA[Custom fields]]></Text>
</Translation>
<Translation name="CP_customFieldManager_confirm_save">
<Text language="de"><![CDATA[Möchtest du diesen benutzerdefinierten Randkurs als %s speichern?]]></Text>
<Text language="en"><![CDATA[Do you want to save the recorded course as custom field %s?]]></Text>
Expand Down Expand Up @@ -2462,19 +2466,24 @@ By clicking on the name you will get the option to either delete, rename or edit
</Translation>
<Translation name="CP_help_page_customFieldDraw_text">
<Text language="de"><![CDATA[
Die zweite Option ist das Zeichnen im Helfermenü.
Dazu darfst du kein Fahrzeug ausgewählt haben (Linksklick irgendwo auf der Karte) und du bekommst die Option, einen Randkurs zu zeichnen.
Wenn du das Zeichnen gestartet hast, wird der Text "Zeichne einen Randkurs" angezeigt.
Die zweite Option ist das Zeichnen im CP Helfermenü.
Start der Aufzeichnung geht mit dem Button unten links oder der entsprechenden Taste.
Wenn du das Zeichnen gestartet hast, wird der Text 'Zeichne einen Randkurs' angezeigt.
Mit der rechten Maustaste kannst du jetzt den ersten Punkt setzen.
Mit der shift-Taste lässt sich die Linie im 90° Winkel gehalten.
Mit einem weiteren Rechtsklick wird eine Linie von deinem ersten zum zweiten Punkt gezogen, der zweite Punkt ist nun wieder der Startpunkt für die nächste Linie.
Nach der zweiten Linie wird der Randkurs automatisch geschlossen. Du kannst trotzdem weitere Linien hinzufügen um das Feld genauer zu definieren.
Es wird keine letzte Linie zum Startpunkt benötigt, da diese automatisch direkt zum start erzeugt wird.
]]></Text>
<Text language="en"><![CDATA[
The second option is to draw the custom field on the map of the AI menu.
If no hotspot is selected, you can press the draw custom field button below.
The second option is to draw the custom field on the map of the CP AI menu.
To start the drawing, hit they button on the bottom left corner or hit corresponding key.
After that a text appears on the top of your screen.
Start by clicking the right mouse button for setting the start position.
By holding the shift key, the line will be set straight in 90° angles.
The next clicks will create lines to the previous click.
Click the save button at the bottom to finish drawing the field.
Once you draw a second line, the course will be automatically closed. You can still draw more lines to define the field even further.
You don't need to draw the last line to the start, as it gets generated automatically straight to the start.
]]></Text>
</Translation>
<Translation name="CP_help_page_multiConvoy_title">
Expand Down
33 changes: 33 additions & 0 deletions config/gui/pages/CourseGeneratorFrame.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<RoundCorner profile="fs25_subCategorySelectorDot" />
<RoundCorner profile="fs25_subCategorySelectorDot" />
<RoundCorner profile="fs25_subCategorySelectorDot" />
<RoundCorner profile="fs25_subCategorySelectorDot" />
</BoxLayout>
<GuiElement profile="fs25_subCategoryListContainer" id="filterListContainer">
<SmoothList profile="fs25_mapList" id="filterList" focusInit="onOpen"
Expand Down Expand Up @@ -138,6 +139,34 @@
<Slider profile="fs25_listSlider" dataElementId="activeWorkerList" />
</ThreePartBitmap>
</GuiElement>
<GuiElement profile="fs25_subCategoryListContainer" id="customFieldListContainer">
<SmoothList profile="fs25_mapList" id="customFieldList" focusInit="onOpen"
listSectionHeader="section" startClipperElementName="startClipper"
endClipperElementName="endClipper" onClick="onClickList">
<ListItem profile="fs25_mapListItem">
<Bitmap profile="fs25_mapListItemIconBg" name="iconBg" />
<Bitmap profile="fs25_mapListColorTemplate" name="colorTemplate" />
<Bitmap profile="fs25_mapListItemIcon" name="icon" />
<Text profile="fs25_mapListItemName" name="name" />
</ListItem>
<ListItem profile="fs25_subCategoryListSectionHeader" name="section">
<Text profile="fs25_subCategoryListSectionHeaderTitle" name="title" />
</ListItem>
</SmoothList>
<Bitmap profile="fs25_subCategoryStartClipper" name="startClipper" />
<Bitmap profile="fs25_subCategoryStopClipper" position="0px 60px" name="endClipper" />
<ThreePartBitmap profile="fs25_subCategoryListSliderBox" absoluteSizeOffset="0px 60px">
<Slider profile="fs25_listSlider" dataElementId="customFieldList" />
</ThreePartBitmap>
<GuiElement profile="fs25_mapButtonContainer" id="buttonDrawCustomField"
width="340px" position="-10px 0px">
<ThreePartBitmap profile="fs25_mapButtonBgLight" />
<Text profile="fs25_mapButtonText" name="text"
text="$l10n_CP_customFieldManager_draw" textOffset="15px 0px" />
<Button profile="fs25_mapButtonAction1" name="button"
onClick="onClickDrawCustomField" />
</GuiElement>
</GuiElement>
</Bitmap>
</GuiElement>
<GuiElement profile="cpMenuContainer">
Expand All @@ -159,6 +188,10 @@
<Text profile="fs25_shopBalance" text="$l10n_ui_balance:" />
<Text profile="fs25_shopMoney" id="currentBalanceText" />
</BoxLayout> -->
<GuiElement id="customFieldStatusMessage">
<Text profile="cpAIStatusText" text="$l10n_CP_customFieldManager_draw_header"/>
<Text profile="cpAIStatusText" text="$l10n_CP_customFieldManager_draw_sub_header" position="-300px -30px" />
</GuiElement>
<Text profile="cpAIStatusText" id="statusMessage" />
</GuiElement>
<GuiElement profile="fs25_mapContextBoxContainer" newLayer="true">
Expand Down
Binary file added img/helpmenu/customfield.dds
Binary file not shown.
5 changes: 5 additions & 0 deletions scripts/field/CustomField.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ function CustomField:setVertices(vertices)
self.vertices = vertices
end

---@return CustomFieldHotspot
function CustomField:getHotspot()
return self.fieldHotspot
end

function CustomField:delete()
if self.fieldHotspot then
g_currentMission:removeMapHotspot(self.fieldHotspot)
Expand Down
24 changes: 24 additions & 0 deletions scripts/field/CustomFieldManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ function CustomFieldManager:init(fileSystem)
self:load()
end

---@return number
function CustomFieldManager:getNumFields()
return #self.fields
end

---@param index number
---@return CustomField|nil
function CustomFieldManager:getFieldByIndex(index)
return self.fields[index]
end

function CustomFieldManager:load()
self.fields = {}
self.fileSystem:refresh()
Expand Down Expand Up @@ -71,6 +82,17 @@ function CustomFieldManager:getNewFieldNumber()
return ix
end

---@param polygon Polygon
function CustomFieldManager:addFieldFromPolygon(polygon)
local waypoints = {}
polygon:calculateProperties()
polygon:splitEdges(5)
for _, v in polygon:vertices() do
table.insert(waypoints, Waypoint.initFromGeneratedWp(v))
end
self:addField(waypoints)
end

--- Creates a new custom field from a given vertices table.
---@param waypoints table
function CustomFieldManager:addField(waypoints)
Expand Down Expand Up @@ -147,6 +169,7 @@ function CustomFieldManager:onClickSaveDialog(clickOk, field)
fieldValid = true
table.insert(self.fields, field)
self.fileSystem:refresh()
g_messageCenter:publish(MessageType.CP_CUSTOM_FIELD_CHANGED)
else
CpUtil.info("Failed to create custom Field: %s", field:getName())
end
Expand Down Expand Up @@ -255,5 +278,6 @@ end

-- for reload only:
if g_customFieldManager then
---@type CustomFieldManager
g_customFieldManager = CustomFieldManager(FileSystem(g_Courseplay.customFieldDir, g_currentMission.missionInfo.mapId))
end
6 changes: 3 additions & 3 deletions scripts/geometry/Polygon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ end
--- ( 3, nil) -> 3, 4, 5, 1, 2
--- ( 3, 1) -> 3, 4, 5, 1
--- ( 1, 3) -> 1, 2, 3
---@param from number index of first vertex
---@param to number index of last vertex
---@param step number step (1 or -1 only), direction of iteration
---@param from number|nil index of first vertex
---@param to number|nil index of last vertex
---@param step number|nil step (1 or -1 only), direction of iteration
---@return number, Vertex, Vertex, Vertex the index, the vertex at index, the previous, and the next vertex.
--- previous and next may be nil
function Polygon:vertices(from, to, step)
Expand Down
2 changes: 1 addition & 1 deletion scripts/geometry/Polyline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ function Polyline:setAttribute(ix, setter, ...)
end

--- Remove all existing vertices
---@param ix number optional start index
---@param ix number|nil optional start index
function Polyline:_reset(ix)
for i = ix or 1, #self do
self[i] = nil
Expand Down
1 change: 1 addition & 0 deletions scripts/gui/CustomFieldHotspot.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--- Custom field hotspot that can be clicked for deleting of the field course.
---@class CustomFieldHotspot
CustomFieldHotspot = {}
CustomFieldHotspot.CATEGORY = 200
CustomFieldHotspot.SLICE_ID = "gui.ingameMap_other"
Expand Down
Loading
Loading