Panel display, MultiMessage.

This commit is contained in:
Kistaro Windrider 2023-04-02 00:20:37 -07:00
parent 3eb087201f
commit a62de999ea
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8
2 changed files with 43 additions and 2 deletions

View File

@ -1,6 +1,9 @@
package cardsim package cardsim
import "fmt" import (
"fmt"
"strings"
)
// Message is an opaque interface representing a displayable message. // Message is an opaque interface representing a displayable message.
// Using an interface here allows for implementation of new message display // Using an interface here allows for implementation of new message display
@ -56,3 +59,19 @@ func IsSpecialMessage(m Message, s *SpecialMessage) bool {
} }
return false return false
} }
// MultiMessage is a sequence of messages treated like one message.
type MultiMessage []Message
func (m MultiMessage) String() string {
s := make([]string, len(m))
for i, msg := range m {
if msg == nil {
s[i] = ""
continue
}
s[i] = msg.String()
continue
}
return strings.Join(s, "\n")
}

View File

@ -63,7 +63,7 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int,
if needsDivider { if needsDivider {
divider() divider()
} }
displayPrompt(p) displayOnePanel(p, p.Prompt)
actionsOffset := displayStatsMenu(p) actionsOffset := displayStatsMenu(p)
handOffset := displayPermanentActionsMenu(p, actionsOffset) handOffset := displayPermanentActionsMenu(p, actionsOffset)
max := displayHandMenu(p, handOffset) max := displayHandMenu(p, handOffset)
@ -143,3 +143,25 @@ func confirmQuit() {
os.Exit(0) os.Exit(0)
} }
} }
func displayOnePanel[C StatsCollection](p *Player[C], panel InfoPanel[C]) error {
var errs ErrorCollector
t, err := panel.Title(p)
if IsSeriousError(err) {
return err
}
errs.Add(err)
ts := t.String()
if len(ts) > 0 {
fmt.Println(ts)
fmt.Println(strings.Repeat("-", len(ts)))
fmt.Println()
}
m, err := panel.Info(p)
errs.Add(err)
if IsSeriousError(err) {
return errs.Emit()
}
displayAndWait(MultiMessage(m))
return errs.Emit()
}