Skip to content

Commit c643bbc

Browse files
Add level, progress, restockMessageEnabled to MerchantWindowDsl
1 parent 6865178 commit c643bbc

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/dsl/MerchantWindowDsl.kt

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import xyz.xenondevs.invui.dsl.property.ProviderDslProperty
1313
import xyz.xenondevs.invui.window.MerchantWindow
1414
import xyz.xenondevs.invui.window.setAvailable
1515
import xyz.xenondevs.invui.window.setDiscount
16+
import xyz.xenondevs.invui.window.setLevel
17+
import xyz.xenondevs.invui.window.setProgress
18+
import xyz.xenondevs.invui.window.setRestockMessageEnabled
1619
import xyz.xenondevs.invui.window.setTrades
1720
import kotlin.contracts.InvocationKind
1821
import kotlin.contracts.contract
@@ -77,7 +80,7 @@ inline fun trade(trade: TradeDsl.() -> Unit): MerchantWindow.Trade {
7780
/**
7881
* DSL scope for configuring a [MerchantWindow].
7982
*
80-
* Extends [SplitWindowDsl] with merchant-specific properties: [trades] to define available
83+
* Extends [SplitWindowDsl] with merchant-specific properties like [trades] to define available
8184
* trades and [selectedTrade] to observe which trade the player has selected.
8285
*
8386
* ```
@@ -134,6 +137,43 @@ sealed interface MerchantWindowDsl : SplitWindowDsl {
134137
*/
135138
val trades: ProviderDslProperty<List<MerchantWindow.Trade>>
136139

140+
/**
141+
* The merchant's level, displayed after the [title][WindowDsl.title] using the translation
142+
* `merchant.level.<level>`. The following levels exist:
143+
* 1 (Novice), 2 (Apprentice), 3 (Journeyman), 4 (Expert), 5 (Master).
144+
*
145+
* If set to `<= 0`, no level name and an always-empty progress bar will be displayed.
146+
* If set to `> 5`, no level name and no progress bar will be displayed.
147+
*
148+
* Defaults to `0`. Can be set to a static value or bound to a [Provider]:
149+
* ```
150+
* level by 3 // Journeyman
151+
* ```
152+
*/
153+
val level: ProviderDslProperty<Int>
154+
155+
/**
156+
* The progress of the merchant's experience bar, from `0.0` to `1.0`.
157+
* If set to any value `< 0`, the progress bar and the merchant level name will be hidden.
158+
*
159+
* Defaults to `-1.0` (hidden). Can be set to a static value or bound to a [Provider]:
160+
* ```
161+
* progress by 0.5
162+
* ```
163+
*/
164+
val progress: ProviderDslProperty<Double>
165+
166+
/**
167+
* Whether the message "Villagers restock up to two times per day" is displayed when hovering
168+
* over the arrow of disabled trades.
169+
*
170+
* Defaults to `false`. Can be set to a static value or bound to a [Provider]:
171+
* ```
172+
* restockMessageEnabled by true
173+
* ```
174+
*/
175+
val restockMessageEnabled: ProviderDslProperty<Boolean>
176+
137177
/**
138178
* A read-only [Provider] that tracks the index of the currently selected trade (zero-based),
139179
* or `-1` if no trade is selected. Updates automatically as the player selects trades.
@@ -225,10 +265,19 @@ internal class MerchantWindowDslImpl(
225265
) : AbstractSplitWindowDsl<MerchantWindow, MerchantWindow.Builder>(viewer), MerchantWindowDsl {
226266

227267
private var _trades = provider(emptyList<MerchantWindow.Trade>())
268+
private var _level = provider(0)
269+
private var _progress = provider(-1.0)
270+
private var _restockMessageEnabled = provider(false)
228271

229272
override val upperGui = GuiDslProperty(3, 1)
230273
override val trades: ProviderDslProperty<List<MerchantWindow.Trade>>
231274
get() = ProviderDslProperty(::_trades)
275+
override val level: ProviderDslProperty<Int>
276+
get() = ProviderDslProperty(::_level)
277+
override val progress: ProviderDslProperty<Double>
278+
get() = ProviderDslProperty(::_progress)
279+
override val restockMessageEnabled: ProviderDslProperty<Boolean>
280+
get() = ProviderDslProperty(::_restockMessageEnabled)
232281
override val selectedTrade = mutableProvider(-1)
233282

234283
override fun createBuilder() = MerchantWindow.builder()
@@ -238,6 +287,9 @@ internal class MerchantWindowDslImpl(
238287
builder.apply {
239288
setUpperGui(upperGui.value)
240289
setTrades(_trades)
290+
setLevel(_level)
291+
setProgress(_progress)
292+
setRestockMessageEnabled(_restockMessageEnabled)
241293
addTradeSelectHandler { _, trade -> selectedTrade.set(trade) }
242294
}
243295
}

0 commit comments

Comments
 (0)