1package app23import (4 "github.com/FelineStateMachine/puzzletea/ui"56 "charm.land/bubbles/v2/key"7 tea "charm.land/bubbletea/v2"8)910type mainMenuScreen struct {11 width int12 height int13 menu ui.MainMenu14}1516func (s mainMenuScreen) State() viewState { return mainMenuView }1718func (s mainMenuScreen) Resize(width, height int) screenModel {19 s.width = width20 s.height = height21 return s22}2324func (s mainMenuScreen) Update(msg tea.Msg) (screenModel, tea.Cmd, screenAction) {25 updateMainMenuCursor(msg, &s.menu)26 keyMsg, ok := msg.(tea.KeyPressMsg)27 if !ok || !key.Matches(keyMsg, rootKeys.Enter) {28 return s, nil, nil29 }3031 switch s.menu.SelectedAction() {32 case mainMenuActionPlay:33 return s, nil, openPlayMenuAction{}34 case mainMenuActionExport:35 return s, nil, openExportAction{}36 case mainMenuActionStats:37 return s, nil, openStatsAction{}38 case mainMenuActionOptions:39 return s, nil, openOptionsMenuAction{}40 case mainMenuActionQuit:41 return s, nil, quitAction{}42 default:43 return s, nil, nil44 }45}4647func (s mainMenuScreen) View(notice noticeState) string {48 return centerContentWithNotice(s.width, s.height, notice, s.menu.View())49}5051func (s mainMenuScreen) Apply(m model) model {52 m.state = mainMenuView53 m.nav.mainMenu = s.menu54 return m55}5657type playMenuScreen struct {58 width int59 height int60 menu ui.MainMenu61}6263func (s playMenuScreen) State() viewState { return playMenuView }6465func (s playMenuScreen) Resize(width, height int) screenModel {66 s.width = width67 s.height = height68 return s69}7071func (s playMenuScreen) Update(msg tea.Msg) (screenModel, tea.Cmd, screenAction) {72 updateMainMenuCursor(msg, &s.menu)73 keyMsg, ok := msg.(tea.KeyPressMsg)74 if !ok {75 return s, nil, nil76 }7778 switch {79 case key.Matches(keyMsg, rootKeys.Enter):80 switch s.menu.SelectedAction() {81 case playMenuActionCreate:82 return s, nil, openGameSelectAction{}83 case playMenuActionContinue:84 return s, nil, openContinueAction{}85 case playMenuActionDaily:86 return s, nil, openDailyAction{}87 case playMenuActionWeekly:88 return s, nil, openWeeklyAction{}89 case playMenuActionSeeded:90 return s, nil, openSeedInputAction{}91 }92 case key.Matches(keyMsg, rootKeys.Escape):93 return s, nil, backAction{target: mainMenuView}94 }9596 return s, nil, nil97}9899func (s playMenuScreen) View(notice noticeState) string {100 return centerContentWithNotice(s.width, s.height, notice, s.menu.ViewAsPanel("Play"))101}102103func (s playMenuScreen) Apply(m model) model {104 m.state = playMenuView105 m.nav.playMenu = s.menu106 return m107}108109type optionsMenuScreen struct {110 width int111 height int112 menu ui.MainMenu113}114115func (s optionsMenuScreen) State() viewState { return optionsMenuView }116117func (s optionsMenuScreen) Resize(width, height int) screenModel {118 s.width = width119 s.height = height120 return s121}122123func (s optionsMenuScreen) Update(msg tea.Msg) (screenModel, tea.Cmd, screenAction) {124 updateMainMenuCursor(msg, &s.menu)125 keyMsg, ok := msg.(tea.KeyPressMsg)126 if !ok {127 return s, nil, nil128 }129130 switch {131 case key.Matches(keyMsg, rootKeys.Enter):132 switch s.menu.SelectedAction() {133 case optionsMenuActionTheme:134 return s, nil, openThemeSelectAction{}135 case optionsMenuActionGuides:136 return s, nil, openHelpSelectAction{}137 }138 case key.Matches(keyMsg, rootKeys.Escape):139 return s, nil, backAction{target: mainMenuView}140 }141142 return s, nil, nil143}144145func (s optionsMenuScreen) View(notice noticeState) string {146 items := s.menu.RenderItems() + "\n\n" + ui.DimItemStyle().Render("- Dami")147 return renderPanelView(s.width, s.height, notice, "Options", items, "↑/↓ navigate • enter select • esc back")148}149150func (s optionsMenuScreen) Apply(m model) model {151 m.state = optionsMenuView152 m.nav.optionsMenu = s.menu153 return m154}