Skip to content

Commit 9939793

Browse files
authored
Merge pull request #825 from Courseplay/draw-custom-field
Readded custom field drawing
2 parents 7a9d463 + 3e16407 commit 9939793

39 files changed

Lines changed: 448 additions & 185 deletions

config/HelpMenu.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,10 @@
191191
</paragraph>
192192
<paragraph>
193193
<text text="$l10n_CP_help_page_customFieldDone_text"/>
194-
<image filename="img/helpmenu/donecustomhelp.dds" size="1024 1024" uvs="0px 0px 765px 510px" aspectRatio="0.66"/>
195194
</paragraph>
196195
<paragraph>
197196
<text text="$l10n_CP_help_page_customFieldDraw_text"/>
198-
<image filename="img/helpmenu/drawcustomhelp.dds" size="1024 1024" uvs="0px 0px 765px 510px" aspectRatio="0.66"/>
197+
<image filename="img/helpmenu/customfield.dds" size="1024 1024" uvs="0px 0px 765px 510px" aspectRatio="0.66"/>
199198
</paragraph>
200199
</page>
201200
<!--Courseplay Multitool and Convoy-->

config/MasterTranslations.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,10 @@ The course is saved automatically on closing of the editor and overrides the sel
18301830
<Text language="de"><![CDATA[Randkurs]]></Text>
18311831
<Text language="en"><![CDATA[Custom field]]></Text>
18321832
</Translation>
1833+
<Translation name="CP_customFieldManager_fieldList">
1834+
<Text language="de"><![CDATA[Randkurse]]></Text>
1835+
<Text language="en"><![CDATA[Custom fields]]></Text>
1836+
</Translation>
18331837
<Translation name="CP_customFieldManager_confirm_save">
18341838
<Text language="de"><![CDATA[Möchtest du diesen benutzerdefinierten Randkurs als %s speichern?]]></Text>
18351839
<Text language="en"><![CDATA[Do you want to save the recorded course as custom field %s?]]></Text>
@@ -2478,19 +2482,24 @@ By clicking on the name you will get the option to either delete, rename or edit
24782482
</Translation>
24792483
<Translation name="CP_help_page_customFieldDraw_text">
24802484
<Text language="de"><![CDATA[
2481-
Die zweite Option ist das Zeichnen im Helfermenü.
2482-
Dazu darfst du kein Fahrzeug ausgewählt haben (Linksklick irgendwo auf der Karte) und du bekommst die Option, einen Randkurs zu zeichnen.
2483-
Wenn du das Zeichnen gestartet hast, wird der Text "Zeichne einen Randkurs" angezeigt.
2485+
Die zweite Option ist das Zeichnen im CP Helfermenü.
2486+
Start der Aufzeichnung geht mit dem Button unten links oder der entsprechenden Taste.
2487+
Wenn du das Zeichnen gestartet hast, wird der Text 'Zeichne einen Randkurs' angezeigt.
24842488
Mit der rechten Maustaste kannst du jetzt den ersten Punkt setzen.
2489+
Mit der shift-Taste lässt sich die Linie im 90° Winkel gehalten.
24852490
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.
2491+
Nach der zweiten Linie wird der Randkurs automatisch geschlossen. Du kannst trotzdem weitere Linien hinzufügen um das Feld genauer zu definieren.
2492+
Es wird keine letzte Linie zum Startpunkt benötigt, da diese automatisch direkt zum start erzeugt wird.
24862493
]]></Text>
24872494
<Text language="en"><![CDATA[
2488-
The second option is to draw the custom field on the map of the AI menu.
2489-
If no hotspot is selected, you can press the draw custom field button below.
2495+
The second option is to draw the custom field on the map of the CP AI menu.
2496+
To start the drawing, hit they button on the bottom left corner or hit corresponding key.
24902497
After that a text appears on the top of your screen.
24912498
Start by clicking the right mouse button for setting the start position.
2499+
By holding the shift key, the line will be set straight in 90° angles.
24922500
The next clicks will create lines to the previous click.
2493-
Click the save button at the bottom to finish drawing the field.
2501+
Once you draw a second line, the course will be automatically closed. You can still draw more lines to define the field even further.
2502+
You don't need to draw the last line to the start, as it gets generated automatically straight to the start.
24942503
]]></Text>
24952504
</Translation>
24962505
<Translation name="CP_help_page_multiConvoy_title">

config/gui/pages/CourseGeneratorFrame.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<RoundCorner profile="fs25_subCategorySelectorDot" />
3535
<RoundCorner profile="fs25_subCategorySelectorDot" />
3636
<RoundCorner profile="fs25_subCategorySelectorDot" />
37+
<RoundCorner profile="fs25_subCategorySelectorDot" />
3738
</BoxLayout>
3839
<GuiElement profile="fs25_subCategoryListContainer" id="filterListContainer">
3940
<SmoothList profile="fs25_mapList" id="filterList" focusInit="onOpen"
@@ -138,6 +139,34 @@
138139
<Slider profile="fs25_listSlider" dataElementId="activeWorkerList" />
139140
</ThreePartBitmap>
140141
</GuiElement>
142+
<GuiElement profile="fs25_subCategoryListContainer" id="customFieldListContainer">
143+
<SmoothList profile="fs25_mapList" id="customFieldList" focusInit="onOpen"
144+
listSectionHeader="section" startClipperElementName="startClipper"
145+
endClipperElementName="endClipper" onClick="onClickList">
146+
<ListItem profile="fs25_mapListItem">
147+
<Bitmap profile="fs25_mapListItemIconBg" name="iconBg" />
148+
<Bitmap profile="fs25_mapListColorTemplate" name="colorTemplate" />
149+
<Bitmap profile="fs25_mapListItemIcon" name="icon" />
150+
<Text profile="fs25_mapListItemName" name="name" />
151+
</ListItem>
152+
<ListItem profile="fs25_subCategoryListSectionHeader" name="section">
153+
<Text profile="fs25_subCategoryListSectionHeaderTitle" name="title" />
154+
</ListItem>
155+
</SmoothList>
156+
<Bitmap profile="fs25_subCategoryStartClipper" name="startClipper" />
157+
<Bitmap profile="fs25_subCategoryStopClipper" position="0px 60px" name="endClipper" />
158+
<ThreePartBitmap profile="fs25_subCategoryListSliderBox" absoluteSizeOffset="0px 60px">
159+
<Slider profile="fs25_listSlider" dataElementId="customFieldList" />
160+
</ThreePartBitmap>
161+
<GuiElement profile="fs25_mapButtonContainer" id="buttonDrawCustomField"
162+
width="340px" position="-10px 0px">
163+
<ThreePartBitmap profile="fs25_mapButtonBgLight" />
164+
<Text profile="fs25_mapButtonText" name="text"
165+
text="$l10n_CP_customFieldManager_draw" textOffset="15px 0px" />
166+
<Button profile="fs25_mapButtonAction1" name="button"
167+
onClick="onClickDrawCustomField" />
168+
</GuiElement>
169+
</GuiElement>
141170
</Bitmap>
142171
</GuiElement>
143172
<GuiElement profile="cpMenuContainer">
@@ -159,6 +188,10 @@
159188
<Text profile="fs25_shopBalance" text="$l10n_ui_balance:" />
160189
<Text profile="fs25_shopMoney" id="currentBalanceText" />
161190
</BoxLayout> -->
191+
<GuiElement id="customFieldStatusMessage">
192+
<Text profile="cpAIStatusText" text="$l10n_CP_customFieldManager_draw_header"/>
193+
<Text profile="cpAIStatusText" text="$l10n_CP_customFieldManager_draw_sub_header" position="-300px -30px" />
194+
</GuiElement>
162195
<Text profile="cpAIStatusText" id="statusMessage" />
163196
</GuiElement>
164197
<GuiElement profile="fs25_mapContextBoxContainer" newLayer="true">

img/helpmenu/customfield.dds

512 KB
Binary file not shown.

scripts/field/CustomField.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ function CustomField:setVertices(vertices)
5454
self.vertices = vertices
5555
end
5656

57+
---@return CustomFieldHotspot
58+
function CustomField:getHotspot()
59+
return self.fieldHotspot
60+
end
61+
5762
function CustomField:delete()
5863
if self.fieldHotspot then
5964
g_currentMission:removeMapHotspot(self.fieldHotspot)

scripts/field/CustomFieldManager.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ function CustomFieldManager:init(fileSystem)
3737
self:load()
3838
end
3939

40+
---@return number
41+
function CustomFieldManager:getNumFields()
42+
return #self.fields
43+
end
44+
45+
---@param index number
46+
---@return CustomField|nil
47+
function CustomFieldManager:getFieldByIndex(index)
48+
return self.fields[index]
49+
end
50+
4051
function CustomFieldManager:load()
4152
self.fields = {}
4253
self.fileSystem:refresh()
@@ -71,6 +82,17 @@ function CustomFieldManager:getNewFieldNumber()
7182
return ix
7283
end
7384

85+
---@param polygon Polygon
86+
function CustomFieldManager:addFieldFromPolygon(polygon)
87+
local waypoints = {}
88+
polygon:calculateProperties()
89+
polygon:splitEdges(5)
90+
for _, v in polygon:vertices() do
91+
table.insert(waypoints, Waypoint.initFromGeneratedWp(v))
92+
end
93+
self:addField(waypoints)
94+
end
95+
7496
--- Creates a new custom field from a given vertices table.
7597
---@param waypoints table
7698
function CustomFieldManager:addField(waypoints)
@@ -147,6 +169,7 @@ function CustomFieldManager:onClickSaveDialog(clickOk, field)
147169
fieldValid = true
148170
table.insert(self.fields, field)
149171
self.fileSystem:refresh()
172+
g_messageCenter:publish(MessageType.CP_CUSTOM_FIELD_CHANGED)
150173
else
151174
CpUtil.info("Failed to create custom Field: %s", field:getName())
152175
end
@@ -255,5 +278,6 @@ end
255278

256279
-- for reload only:
257280
if g_customFieldManager then
281+
---@type CustomFieldManager
258282
g_customFieldManager = CustomFieldManager(FileSystem(g_Courseplay.customFieldDir, g_currentMission.missionInfo.mapId))
259283
end

scripts/geometry/Polygon.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ end
5959
--- ( 3, nil) -> 3, 4, 5, 1, 2
6060
--- ( 3, 1) -> 3, 4, 5, 1
6161
--- ( 1, 3) -> 1, 2, 3
62-
---@param from number index of first vertex
63-
---@param to number index of last vertex
64-
---@param step number step (1 or -1 only), direction of iteration
62+
---@param from number|nil index of first vertex
63+
---@param to number|nil index of last vertex
64+
---@param step number|nil step (1 or -1 only), direction of iteration
6565
---@return number, Vertex, Vertex, Vertex the index, the vertex at index, the previous, and the next vertex.
6666
--- previous and next may be nil
6767
function Polygon:vertices(from, to, step)

scripts/geometry/Polyline.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ function Polyline:setAttribute(ix, setter, ...)
825825
end
826826

827827
--- Remove all existing vertices
828-
---@param ix number optional start index
828+
---@param ix number|nil optional start index
829829
function Polyline:_reset(ix)
830830
for i = ix or 1, #self do
831831
self[i] = nil

scripts/gui/CustomFieldHotspot.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
--- Custom field hotspot that can be clicked for deleting of the field course.
2+
---@class CustomFieldHotspot
23
CustomFieldHotspot = {}
34
CustomFieldHotspot.CATEGORY = 200
45
CustomFieldHotspot.SLICE_ID = "gui.ingameMap_other"

0 commit comments

Comments
 (0)