Skip to content

Commit 325e745

Browse files
committed
start work on the enroute list
Signed-off-by: Octol1ttle <[email protected]>
1 parent 99a49cb commit 325e745

File tree

15 files changed

+80
-60
lines changed

15 files changed

+80
-60
lines changed

src/main/kotlin/ru/octol1ttle/flightassistant/FlightAssistantFabric.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ package ru.octol1ttle.flightassistant
33
//? if fabric {
44
import dev.architectury.registry.client.keymappings.KeyMappingRegistry
55
import net.fabricmc.api.ClientModInitializer
6-
import net.minecraft.client.KeyMapping
76
import nl.enjarai.doabarrelroll.compat.flightassistant.DaBRCompatFA
87

98
object FlightAssistantFabric : ClientModInitializer {
109
override fun onInitializeClient() {
1110
FlightAssistant.init()
1211
DaBRCompatFA.init()
13-
for (keyMapping: KeyMapping in FAKeyMappings.keyMappings) {
14-
KeyMappingRegistry.register(keyMapping)
15-
}
12+
FAKeyMappings.keyMappings.forEach(KeyMappingRegistry::register)
1613
}
1714
}
1815
//?}

src/main/kotlin/ru/octol1ttle/flightassistant/config/FAConfigScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import ru.octol1ttle.flightassistant.config.options.DisplayOptions
99
import ru.octol1ttle.flightassistant.config.options.GlobalOptions
1010
import ru.octol1ttle.flightassistant.config.options.SafetyOptions
1111

12-
@Suppress("UnusedVariable", "unused") object FAConfigScreen {
12+
object FAConfigScreen {
13+
@Suppress("unused", "UnusedVariable")
1314
fun generate(parent: Screen?): Screen {
1415
return YetAnotherConfigLib(FlightAssistant.MOD_ID) {
1516
val global: ConfigCategory by registerGlobalOptions(

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/ComputerHost.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,8 @@ internal object ComputerHost : ModuleController<Computer>, ComputerBus {
9292
internal fun sendRegistrationEvent() {
9393
registerBuiltin()
9494
ComputerRegistrationCallback.EVENT.invoker().register(this, this::register)
95-
for (computer: Computer in computers.values) {
96-
computer.subscribeToEvents()
97-
}
98-
for (computer: Computer in computers.values) {
99-
computer.invokeEvents()
100-
}
95+
computers.values.forEach(Computer::subscribeToEvents)
96+
computers.values.forEach(Computer::invokeEvents)
10197

10298
logRegisterComplete()
10399
}

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/safety/AlertComputer.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ class AlertComputer(computers: ComputerBus, private val soundManager: SoundManag
189189

190190
categories.sortBy { it.getHighestPriority() ?: Int.MAX_VALUE }
191191

192-
for (list: ChangeTrackingArrayList<Alert> in alertLists.values) {
193-
list.startTracking()
194-
}
192+
alertLists.values.forEach(ChangeTrackingArrayList<*>::startTracking)
195193

196194
for (alert: Alert in categories.flatMap { it.activeAlerts } ) {
197195
alertLists.computeIfAbsent(alert.data) { return@computeIfAbsent ChangeTrackingArrayList<Alert>() }.add(alert)

src/main/kotlin/ru/octol1ttle/flightassistant/screen/FlightAssistantSetupScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ru.octol1ttle.flightassistant.screen
22

3+
import dev.architectury.platform.Platform
34
import net.minecraft.client.gui.components.Button
45
import net.minecraft.client.gui.components.StringWidget
56
import net.minecraft.network.chat.CommonComponents
@@ -40,10 +41,10 @@ class FlightAssistantSetupScreen : FABaseScreen(Component.translatable("menu.fli
4041
}.pos(this.centerX - 160, this.centerY + 20).width(100).build())
4142
this.addRenderableWidget(Button.builder(Component.translatable("menu.flightassistant.fms.enroute")) {
4243
this.minecraft!!.setScreen(EnrouteScreen())
43-
}.pos(this.centerX - 50, this.centerY + 20).width(100).build()).active = false
44+
}.pos(this.centerX - 50, this.centerY + 20).width(100).build()).active = Platform.isDevelopmentEnvironment()
4445
this.addRenderableWidget(Button.builder(Component.translatable("menu.flightassistant.fms.arrival")) {
4546
//this.minecraft!!.setScreen(FlightPlanScreen())
46-
}.pos(this.centerX + 60, this.centerY + 20).width(100).build()).active = false
47+
}.pos(this.centerX + 60, this.centerY + 20).width(100).build()).active = Platform.isDevelopmentEnvironment()
4748

4849
this.addRenderableWidget(Button.builder(Component.translatable("menu.flightassistant.config")) {
4950
this.minecraft!!.setScreen(FAConfigScreen.generate(null))

src/main/kotlin/ru/octol1ttle/flightassistant/screen/components/CycleTextOnlyButton.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CycleTextOnlyButton<E : NameableEnum>(x: Int, y: Int, private val entries:
2828
val message: Component = TextOnlyButton.getMessageComponent(this)
2929

3030
this.width = font.width(message)
31-
guiGraphics.drawString(font, message, this.x, this.y, 0xFFFFFFFF.toInt())
31+
guiGraphics.drawString(font, message, this.x, this.y, ChatFormatting.WHITE.color!!)
3232
}
3333

3434
override fun onPress() {

src/main/kotlin/ru/octol1ttle/flightassistant/screen/components/FABaseList.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import net.minecraft.client.gui.components.ContainerObjectSelectionList
44
import ru.octol1ttle.flightassistant.FlightAssistant.mc
55

66
abstract class FABaseList<E : ContainerObjectSelectionList.Entry<E>>
7-
(width: Int, height: Int, y0: Int, @Suppress("UNUSED_PARAMETER", "KotlinRedundantDiagnosticSuppress") y1: Int, itemHeight: Int)
8-
: ContainerObjectSelectionList<E>(mc, width, height, y0, /*? if <1.21 {*/ y1, /*?}*/ itemHeight) {
7+
(y0: Int, y1: Int, width: Int, itemHeight: Int) : ContainerObjectSelectionList<E>(mc, width, y1 - y0, y0, /*? if <1.21 {*/ y1, /*?}*/ itemHeight) {
98
init {
109
//? if <1.21 {
1110
setRenderBackground(false)

src/main/kotlin/ru/octol1ttle/flightassistant/screen/fms/departure/DepartureScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DepartureScreen : FABaseScreen(Component.translatable("menu.flightassistan
5555
}
5656

5757
companion object {
58-
var lastState: DepartureScreenState = DepartureScreenState()
59-
var state: DepartureScreenState = DepartureScreenState()
58+
private var lastState: DepartureScreenState = DepartureScreenState()
59+
private var state: DepartureScreenState = DepartureScreenState()
6060
}
6161
}

src/main/kotlin/ru/octol1ttle/flightassistant/screen/fms/enroute/EnrouteScreen.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package ru.octol1ttle.flightassistant.screen.fms.enroute
22

3+
import kotlin.math.max
4+
import kotlin.math.min
5+
import net.minecraft.ChatFormatting
36
import net.minecraft.client.gui.GuiGraphics
47
import net.minecraft.client.gui.components.Button
58
import net.minecraft.client.gui.components.StringWidget
69
import net.minecraft.network.chat.CommonComponents
710
import net.minecraft.network.chat.Component
11+
import net.minecraft.network.chat.Component.literal
12+
import net.minecraft.network.chat.Component.translatable
813
import ru.octol1ttle.flightassistant.screen.FABaseScreen
14+
import ru.octol1ttle.flightassistant.screen.components.SmartStringWidget
915

1016
class EnrouteScreen : FABaseScreen(Component.translatable("menu.flightassistant.fms.enroute")) {
1117
private lateinit var discardChanges: Button
@@ -15,6 +21,14 @@ class EnrouteScreen : FABaseScreen(Component.translatable("menu.flightassistant.
1521

1622
this.addRenderableWidget(StringWidget(0, 7, this.width, 9, this.title, this.font))
1723

24+
val columnsSizeWithMargin: Float = COLUMNS.size + HOVERING_COLUMNS_MARGIN
25+
val optimumColumnsSize: Float = (if (this.width / columnsSizeWithMargin >= 75) columnsSizeWithMargin else COLUMNS.size.toFloat())
26+
COLUMNS.forEachIndexed { i, component ->
27+
this.addRenderableWidget(SmartStringWidget((this.width * (max(0.4f, i.toFloat()) / optimumColumnsSize)).toInt(), Y0, component).setColor(ChatFormatting.GRAY.color!!))
28+
}
29+
30+
this.addRenderableWidget(EnrouteWaypointsList(0, Y0 + 10, this.height - Y0 * 2, this.width, optimumColumnsSize))
31+
1832
discardChanges = this.addRenderableWidget(Button.builder(Component.translatable("menu.flightassistant.fms.discard_changes")) { _: Button? ->
1933
state = lastState.copy()
2034
this.rebuildWidgets()
@@ -34,7 +48,13 @@ class EnrouteScreen : FABaseScreen(Component.translatable("menu.flightassistant.
3448
}
3549

3650
companion object {
37-
var lastState: EnrouteScreenState = EnrouteScreenState()
38-
var state: EnrouteScreenState = EnrouteScreenState()
51+
private const val X0: Int = 15
52+
private const val Y0: Int = 30
53+
54+
private val COLUMNS: Array<Component> = arrayOf(literal("#"), literal("X"), literal("Z"), translatable("short.flightassistant.altitude"), translatable("short.flightassistant.speed"), translatable("short.flightassistant.distance"), translatable("short.flightassistant.time"))
55+
private const val HOVERING_COLUMNS_MARGIN: Float = 1.5f
56+
57+
private var lastState: EnrouteScreenState = EnrouteScreenState()
58+
private var state: EnrouteScreenState = EnrouteScreenState()
3959
}
4060
}

src/main/kotlin/ru/octol1ttle/flightassistant/screen/fms/enroute/EnrouteScreenState.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package ru.octol1ttle.flightassistant.screen.fms.enroute
33
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
44

55
class EnrouteScreenState(
6-
val waypoints: MutableList<EnrouteWaypointState> = ArrayList()
6+
val waypoints: MutableList<Waypoint> = ArrayList()
77
) {
88
fun save(flightPlan: FlightPlanComputer) {
9-
TODO()
109
}
1110

1211
fun load(flightPlan: FlightPlanComputer) {
13-
TODO()
1412
}
1513

1614
fun copy(): EnrouteScreenState {
@@ -21,7 +19,7 @@ class EnrouteScreenState(
2119
return this.waypoints.size == other.waypoints.size && this.waypoints.all { other.waypoints.contains(it) }
2220
}
2321

24-
data class EnrouteWaypointState(val coordinatesX: Int = 0, val coordinatesZ: Int = 0, val altitude: Int = 0, val speed: Int = 0) {
22+
data class Waypoint(val coordinatesX: Int = 0, val coordinatesZ: Int = 0, val altitude: Int = 0, val speed: Int = 0) {
2523
fun toEnrouteWaypoint() {
2624
TODO()
2725
}

0 commit comments

Comments
 (0)