Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/assets/_data/raw/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ You can change this decision later.

##menu.tier : tier
##menu.back : Back
##menu.exit : Exit
##menu.lobby_back : Done

##menu.options.gameplay : Gameplay
##menu.options.sound : Sound
##menu.options.graphics : Graphics
##menu.options.extra : Extra
##menu.options.controls : Controls
##menu.options.continue : Continue

##menu.terminal : Terminal
##menu.terminal.command_output_label : Command output
Expand Down
2 changes: 2 additions & 0 deletions src/assets/_data/raw/ru.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@

##menu.tier : тир
##menu.back : Назад
##menu.exit : Выйти
##menu.lobby_back : Назад в Меню

##menu.options.gameplay : Геймплей
##menu.options.sound : Звук
##menu.options.graphics : Графика
##menu.options.extra : Дополнительно
##menu.options.controls : Управление
##menu.options.continue : Продолжить

##menu.terminal : Терминал
##menu.terminal.command_output_label : Вывод команды
Expand Down
8 changes: 7 additions & 1 deletion src/scenes/menus/lobbymenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/quasilyte/ge"
"github.com/quasilyte/ge/xslices"

"github.com/quasilyte/roboden-game/assets"
"github.com/quasilyte/roboden-game/controls"
"github.com/quasilyte/roboden-game/descriptions"
Expand Down Expand Up @@ -218,7 +219,12 @@ func (c *LobbyMenuController) createButtonsPanel(uiResources *eui.Resources) *wi
}

c.config.Finalize()
c.scene.Context().ChangeScene(staging.NewController(c.state, c.config.Clone(), NewLobbyMenuController(c.state, c.mode)))

optController := NewStagingOptionsController(c.state)
stagingController := staging.NewController(c.state, c.config.Clone(), optController)
optController.WithBackController(stagingController)

c.scene.Context().ChangeScene(stagingController)
}))

panel.AddChild(eui.NewButton(uiResources, c.scene, d.Get("menu.back"), func() {
Expand Down
12 changes: 12 additions & 0 deletions src/scenes/menus/options_soundmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ type OptionsSoundMenuController struct {
state *session.State

scene *ge.Scene

backController ge.SceneController
}

func NewOptionsSoundMenuController(state *session.State) *OptionsSoundMenuController {
return &OptionsSoundMenuController{state: state}
}

func (c *OptionsSoundMenuController) WithBackController(controller ge.SceneController) *OptionsSoundMenuController {
c.backController = controller
return c
}

func (c *OptionsSoundMenuController) Init(scene *ge.Scene) {
c.scene = scene
c.initUI()
Expand Down Expand Up @@ -93,5 +100,10 @@ func (c *OptionsSoundMenuController) initUI() {

func (c *OptionsSoundMenuController) back() {
c.scene.Context().SaveGameData("save", c.state.Persistent)

if c.backController != nil {
c.scene.Context().ChangeScene(c.backController)
return
}
c.scene.Context().ChangeScene(NewOptionsController(c.state))
}
103 changes: 103 additions & 0 deletions src/scenes/menus/staging_optionsmenu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package menus

import (
"github.com/ebitenui/ebitenui/widget"
"github.com/quasilyte/ge"
"github.com/quasilyte/ge/xslices"

"github.com/quasilyte/roboden-game/assets"
"github.com/quasilyte/roboden-game/controls"
"github.com/quasilyte/roboden-game/gameui/eui"
"github.com/quasilyte/roboden-game/scenes/staging"
"github.com/quasilyte/roboden-game/session"
)

type StagingOptionsMenuController struct {
state *session.State

scene *ge.Scene

backController *staging.Controller
}

func NewStagingOptionsController(state *session.State) *StagingOptionsMenuController {
return &StagingOptionsMenuController{state: state}
}

func (c *StagingOptionsMenuController) WithBackController(controller *staging.Controller) *StagingOptionsMenuController {
c.backController = controller
return c
}

func (c *StagingOptionsMenuController) Init(scene *ge.Scene) {
c.scene = scene
c.initUI()
}

func (c *StagingOptionsMenuController) Update(delta float64) {
if c.state.CombinedInput.ActionIsJustPressed(controls.ActionBack) {
c.back()
return
}
}

func (c *StagingOptionsMenuController) initUI() {
eui.AddBackground(c.backController.RenderDemoFrame(), c.scene)
uiResources := c.state.Resources.UI

root := eui.NewAnchorContainer()
rowContainer := eui.NewRowLayoutContainerWithMinWidth(400, 10, nil)
root.AddChild(rowContainer)

d := c.scene.Dict()
titleLabel := eui.NewCenteredLabel(d.Get("menu.main.settings"), assets.BitmapFont3)
rowContainer.AddChild(titleLabel)

options := &c.state.Persistent.Settings

if c.backController != nil {
rowContainer.AddChild(eui.NewButton(uiResources, c.scene, d.Get("menu.options.continue"), func() {
c.scene.Context().ChangeScene(c.backController)
}))
}

rowContainer.AddChild(eui.NewButton(uiResources, c.scene, d.Get("menu.options.sound"), func() {
c.scene.Context().ChangeScene(NewOptionsSoundMenuController(c.state).WithBackController(c))
}))

{
langOptions := []string{
"en",
"ru",
}
langIndex := xslices.Index(langOptions, options.Lang)
rowContainer.AddChild(eui.NewSelectButton(eui.SelectButtonConfig{
Scene: c.scene,
Resources: uiResources,
Input: c.state.CombinedInput,
Value: &langIndex,
Label: "Language/Язык",
ValueNames: langOptions,
OnPressed: func() {
options.Lang = langOptions[langIndex]
c.state.ReloadLanguage(c.scene.Context())
c.scene.Context().ChangeScene(c)
},
}))
}

rowContainer.AddChild(eui.NewSeparator(widget.RowLayoutData{Stretch: true}))

rowContainer.AddChild(eui.NewButton(uiResources, c.scene, d.Get("menu.exit"), func() {
c.scene.Context().ChangeScene(NewMainMenuController(c.state))
}))

uiObject := eui.NewSceneObject(root)
c.scene.AddGraphics(uiObject)
c.scene.AddObject(uiObject)
}

func (c *StagingOptionsMenuController) back() {
c.scene.Context().SaveGameData("save", c.state.Persistent)
c.scene.Context().ChangeScene(c.backController)
}
43 changes: 21 additions & 22 deletions src/scenes/staging/staging_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ func (c *Controller) doInit(scene *ge.Scene) {
}

func (c *Controller) Init(scene *ge.Scene) {
if c.world != nil {
c.continueScene(scene)
return
}

c.doInit(scene)
runtime.GC()
}
Expand Down Expand Up @@ -646,7 +651,7 @@ func (c *Controller) createPlayers() {
c.onPausePressed()
})
human.EventExitPressed.Connect(c, func(gsignal.Void) {
c.onExitButtonClicked()
c.onMenuButtonClicked()
})
if human.CanPing() {
human.EventPing.Connect(c, func(pingPos gmath.Vec) {
Expand Down Expand Up @@ -685,26 +690,9 @@ func (c *Controller) onVictoryTrigger(gsignal.Void) {
c.victory()
}

func (c *Controller) onExitButtonClicked() {
if len(c.exitNotices) != 0 {
c.leaveScene(c.backController)
return
}
if c.transitionQueued {
return
}

d := c.scene.Dict()
for _, cam := range c.world.cameras {
cam.UI.Visible = true
c.nodeRunner.SetPaused(true)
exitNotice := newScreenTutorialHintNode(cam, gmath.Vec{}, gmath.Vec{}, d.Get("game.exit.notice", c.world.inputMode))
c.exitNotices = append(c.exitNotices, exitNotice)
c.scene.AddObject(exitNotice)
noticeSize := gmath.Vec{X: exitNotice.width, Y: exitNotice.height}
noticeCenterPos := cam.Rect.Center().Sub(noticeSize.Mulf(0.5))
exitNotice.SetPos(noticeCenterPos)
}
func (c *Controller) onMenuButtonClicked() {
c.nodeRunner.SetPaused(true)
c.leaveScene(c.backController)
}

func (c *Controller) canBuildHere(pos gmath.Vec, turret bool) bool {
Expand Down Expand Up @@ -1208,7 +1196,7 @@ func (c *Controller) handleInput() {
}

if c.sharedActionIsJustPressed(controls.ActionBack) {
c.onExitButtonClicked()
c.onMenuButtonClicked()
return
}

Expand Down Expand Up @@ -1383,3 +1371,14 @@ func (c *Controller) leaveScene(controller ge.SceneController) {
c.scene.Audio().PauseCurrentMusic()
c.scene.Context().ChangeScene(controller)
}

func (c *Controller) continueScene(scene *ge.Scene) {
c.scene.Audio().ContinueCurrentMusic()

for _, cam := range c.world.cameras {
scene.AddGraphics(cam)
}
c.nodeRunner.SetPaused(false)

*c.scene = *scene
}