Skip to content

Commit 003a85a

Browse files
committed
Readded custom field drawing
1 parent c5f1ae3 commit 003a85a

10 files changed

Lines changed: 216 additions & 52 deletions

File tree

config/MasterTranslations.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,10 @@ The course is saved automatically on closing of the editor and overrides the sel
18141814
<Text language="de"><![CDATA[Randkurs]]></Text>
18151815
<Text language="en"><![CDATA[Custom field]]></Text>
18161816
</Translation>
1817+
<Translation name="CP_customFieldManager_fieldList">
1818+
<Text language="de"><![CDATA[Randkurse]]></Text>
1819+
<Text language="en"><![CDATA[Custom fields]]></Text>
1820+
</Translation>
18171821
<Translation name="CP_customFieldManager_confirm_save">
18181822
<Text language="de"><![CDATA[Möchtest du diesen benutzerdefinierten Randkurs als %s speichern?]]></Text>
18191823
<Text language="en"><![CDATA[Do you want to save the recorded course as custom field %s?]]></Text>

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">

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
@@ -818,7 +818,7 @@ function Polyline:setAttribute(ix, setter, ...)
818818
end
819819

820820
--- Remove all existing vertices
821-
---@param ix number optional start index
821+
---@param ix number|nil optional start index
822822
function Polyline:_reset(ix)
823823
for i = ix or 1, #self do
824824
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)