-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a6e806
commit 689ecf4
Showing
12 changed files
with
168 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 0 additions & 106 deletions
106
roguelike/src/main/scala/roguelike/components/windows/LevelUp.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
roguelike/src/main/scala/roguelike/windows/LevelUpWindow.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package roguelike.windows | ||
|
||
import indigo.* | ||
import roguelike.GameEvent | ||
import roguelike.model.GameWindowContext | ||
import roguelikestarterkit.* | ||
|
||
object LevelUpWindow: | ||
|
||
val windowId: WindowId = WindowId("Level up") | ||
|
||
private val windowSize = Dimensions(40, 10) | ||
|
||
def window( | ||
screenSize: Dimensions, | ||
charSheet: CharSheet | ||
): WindowModel[LevelUpMenu, GameWindowContext] = | ||
WindowModel( | ||
windowId, | ||
charSheet, | ||
LevelUpMenu.initial(charSheet) | ||
) | ||
.withTitle("Level Up!") | ||
.moveTo(((screenSize - windowSize) / 2).toCoords) | ||
.resizeTo(windowSize) | ||
|
||
final case class LevelUpMenu(components: ComponentGroup[GameWindowContext]) | ||
object LevelUpMenu: | ||
|
||
def initial(charSheet: CharSheet): LevelUpMenu = | ||
val buttonTheme = | ||
Button.Theme( | ||
charSheet, | ||
RGBA.Silver -> RGBA.Black, | ||
RGBA.White -> RGBA.Black, | ||
RGBA.Black -> RGBA.White | ||
) | ||
|
||
LevelUpMenu( | ||
ComponentGroup(Bounds(0, 0, 16, 1)) | ||
.withLayout(ComponentLayout.Vertical()) | ||
.add( | ||
Label("Congratulations! You level up!", Label.Theme(charSheet)), | ||
Label("Select an attribute to increase.", Label.Theme(charSheet)), | ||
Label("", Label.Theme(charSheet)) | ||
) | ||
.add( | ||
Button( | ||
(ctx: GameWindowContext) => | ||
s"[1] Constitution (+20 HP, from ${ctx.player.fighter.maxHp})", | ||
buttonTheme | ||
).onClick( | ||
GameEvent.ModifyMaxHp(20), | ||
GameEvent.WindowEvent(WindowManagerCommand.CloseAll) | ||
), | ||
Button( | ||
(ctx: GameWindowContext) => | ||
s"[2] Strength (+1 attack, from ${ctx.player.fighter.power})", | ||
buttonTheme | ||
).onClick( | ||
GameEvent.ModifyPower(1), | ||
GameEvent.WindowEvent(WindowManagerCommand.CloseAll) | ||
), | ||
Button( | ||
(ctx: GameWindowContext) => | ||
s"[3] Agility (+1 defense, from ${ctx.player.fighter.defense})", | ||
buttonTheme | ||
).onClick( | ||
GameEvent.ModifyDefense(1), | ||
GameEvent.WindowEvent(WindowManagerCommand.CloseAll) | ||
) | ||
) | ||
) | ||
|
||
given (using | ||
cg: WindowContent[ComponentGroup[GameWindowContext], GameWindowContext] | ||
): WindowContent[LevelUpMenu, GameWindowContext] with | ||
|
||
def updateModel( | ||
context: UiContext[GameWindowContext], | ||
model: LevelUpMenu | ||
): GlobalEvent => Outcome[LevelUpMenu] = | ||
|
||
// Constitution | ||
case KeyboardEvent.KeyUp(Key.KEY_1) => | ||
Outcome( | ||
model, | ||
Batch(GameEvent.ModifyMaxHp(20), GameEvent.WindowEvent(WindowManagerCommand.CloseAll)) | ||
) | ||
|
||
// Strength | ||
case KeyboardEvent.KeyUp(Key.KEY_2) => | ||
Outcome( | ||
model, | ||
Batch(GameEvent.ModifyPower(1), GameEvent.WindowEvent(WindowManagerCommand.CloseAll)) | ||
) | ||
|
||
// Agility | ||
case KeyboardEvent.KeyUp(Key.KEY_3) => | ||
Outcome( | ||
model, | ||
Batch(GameEvent.ModifyDefense(1), GameEvent.WindowEvent(WindowManagerCommand.CloseAll)) | ||
) | ||
|
||
case e => | ||
cg.updateModel(context, model.components)(e).map { c => | ||
model.copy(components = c) | ||
} | ||
|
||
def present( | ||
context: UiContext[GameWindowContext], | ||
model: LevelUpMenu | ||
): Outcome[Layer] = | ||
cg.present(context, model.components) | ||
|
||
def cascade(model: LevelUpMenu, newBounds: Bounds): LevelUpMenu = | ||
model.copy(components = cg.cascade(model.components, newBounds)) | ||
|
||
def refresh(model: LevelUpMenu): LevelUpMenu = | ||
model.copy(components = cg.refresh(model.components)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters