Skip to content

Commit 2dd892e

Browse files
committed
Fix iOS virtual controller layout editing
1 parent 891d131 commit 2dd892e

3 files changed

Lines changed: 19 additions & 22 deletions

File tree

app/src/main/swift/Models/PadLayoutStore.swift

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,21 @@ final class PadLayoutStore: @unchecked Sendable {
154154

155155
func setControlVisible(_ id: String, visible: Bool) {
156156
if visible {
157-
controlVisibility.removeValue(forKey: id)
157+
let group = groupID(for: id)
158+
if id == group {
159+
controlVisibility.removeValue(forKey: id)
160+
} else if let groupVisible = controlVisibility[group], !groupVisible {
161+
controlVisibility[id] = true
162+
} else {
163+
controlVisibility.removeValue(forKey: id)
164+
}
158165
} else {
159166
controlVisibility[id] = false
160167
}
161168
}
162169

163170
func resetControlVisibility() {
164171
controlVisibility.removeAll()
165-
save()
166172
}
167173

168174
// MARK: - INI persistence
@@ -180,17 +186,25 @@ final class PadLayoutStore: @unchecked Sendable {
180186
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/Landscape", key: "\(id)_scale", value: Float(pos.scale))
181187
}
182188
}
183-
// Per-button positions are only written if they have been moved by the user.
189+
// Per-button positions: write override if present, sentinel -1 otherwise.
184190
for id in Self.perButtonIDs {
185191
if let pos = perButtonPortrait[id] {
186192
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_x", value: Float(pos.x))
187193
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_y", value: Float(pos.y))
188194
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_scale", value: Float(pos.scale))
195+
} else {
196+
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_x", value: -1.0)
197+
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_y", value: -1.0)
198+
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_scale", value: -1.0)
189199
}
190200
if let pos = perButtonLandscape[id] {
191201
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_x", value: Float(pos.x))
192202
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_y", value: Float(pos.y))
193203
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_scale", value: Float(pos.scale))
204+
} else {
205+
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_x", value: -1.0)
206+
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_y", value: -1.0)
207+
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_scale", value: -1.0)
194208
}
195209
}
196210
// Visibility: `0` = hidden, `1` = visible. Absent means visible (default).
@@ -291,12 +305,10 @@ final class PadLayoutStore: @unchecked Sendable {
291305

292306
func resetPortrait() {
293307
portrait = Self.defaultPortrait
294-
save()
295308
}
296309

297310
func resetLandscape() {
298311
landscape = Self.defaultLandscape
299-
save()
300312
}
301313

302314
func reset(isLandscape: Bool) {
@@ -307,38 +319,23 @@ final class PadLayoutStore: @unchecked Sendable {
307319
if isLandscape {
308320
for id in ["triangle", "circle", "square", "cross"] {
309321
perButtonLandscape.removeValue(forKey: id)
310-
// Overwrite INI keys with sentinel so stale keys do not reload after restart.
311-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_x", value: -1.0)
312-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_y", value: -1.0)
313-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_scale", value: -1.0)
314322
}
315323
} else {
316324
for id in ["triangle", "circle", "square", "cross"] {
317325
perButtonPortrait.removeValue(forKey: id)
318-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_x", value: -1.0)
319-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_y", value: -1.0)
320-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_scale", value: -1.0)
321326
}
322327
}
323-
save()
324328
}
325329

326330
func resetPerButtonDPad(isLandscape: Bool) {
327331
if isLandscape {
328332
for id in ["up", "down", "left", "right"] {
329333
perButtonLandscape.removeValue(forKey: id)
330-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_x", value: -1.0)
331-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_y", value: -1.0)
332-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonLandscape", key: "\(id)_scale", value: -1.0)
333334
}
334335
} else {
335336
for id in ["up", "down", "left", "right"] {
336337
perButtonPortrait.removeValue(forKey: id)
337-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_x", value: -1.0)
338-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_y", value: -1.0)
339-
ARMSX2Bridge.setINIFloat("ARMSX2iOS/PadLayout/PerButtonPortrait", key: "\(id)_scale", value: -1.0)
340338
}
341339
}
342-
save()
343340
}
344341
}

app/src/main/swift/Views/GameScreenView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct GameScreenView: View {
9696
}
9797
menuButtonOverlay(isLandscape: false)
9898
}
99+
.ignoresSafeArea()
99100
}
100101
}
101102
.preference(key: GameScreenSizePreferenceKey.self, value: geo.size)

app/src/main/swift/Views/Settings/PadLayoutEditView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ private struct DraggableButton: View {
535535
}
536536

537537
var body: some View {
538-
let groupID = layout.groupID(for: id)
539-
let isVisible = layout.isControlVisible(groupID)
538+
let isVisible = layout.isControlVisible(id)
540539
ZStack {
541540
RoundedRectangle(cornerRadius: 6)
542541
.fill(.white.opacity(0.05))

0 commit comments

Comments
 (0)