package main import ( "red-green/door" "strings" ) func MainMenu() door.Menu { // Make the main menu m := door.Menu{Panel: door.Panel{Width: 25, X: 5, Y: 5, Style: door.DOUBLE, Title: "[ Main Menu: ]", TitleOffset: 3, BorderColor: door.ColorText("BRI CYAN ON BLA")}} m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"), door.ColorText("BOLD BLUE"), door.ColorText("BOLD CYAN"), door.ColorText("BOLD BLUE")) m.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"), door.ColorText("BOLD WHI ON BLUE"), door.ColorText("BOLD YEL ON BLUE"), door.ColorText("BOLD CYAN ON BLUE")) m.AddSelection("P", "Play Cards") m.AddSelection("S", "View Scores") m.AddSelection("C", "Configure") m.AddSelection("H", "Help") m.AddSelection("A", "About this game") m.AddSelection("Q", "Quit") return m } func ConfigMenu() door.Menu { m := door.Menu{Panel: door.Panel{Width: 31, X: 5, Y: 5, Style: door.DOUBLE, Title: "[ Configuration Menu ]", TitleColor: door.ColorText("BRI CYAN ON BLUE"), BorderColor: door.ColorText("CYAN ON BLUE")}} m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"), door.ColorText("BOLD BLUE"), door.ColorText("BOLD CYAN"), door.ColorText("BOLD BLUE")) m.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"), door.ColorText("BOLD WHI ON BLUE"), door.ColorText("BOLD YEL ON BLUE"), door.ColorText("BOLD CYAN ON BLUE")) m.AddSelection("D", "Deck Colors") m.AddSelection("V", "View Settings") m.AddSelection("Q", "Quit") return m } var DeckColors []string func init() { DeckColors = []string{ "All", "Brown", "Green", "Red", "Blue", "Cyan", "Magenta", "White"} } func MakeColorsRender(brackets string, text_color string, colors map[string]string) func(string) string { renderF := func(text string) string { words := find_words(text) var option bool = true var color_word bool = false var result string var last_color string var word_color string var words_id = 0 word_pair := words[words_id] normal := colors["ALL"] for tpos, c := range text { if option { if c == '[' || c == ']' { if last_color != brackets { result += brackets last_color = brackets } if c == ']' { option = false } } else { if last_color != text_color { result += text_color last_color = text_color } } result += string(c) } else { // Out of the options if color_word { if tpos < word_pair[1] { if last_color != word_color { result += word_color last_color = word_color } else { color_word = false if last_color != normal { result += normal last_color = normal } } result += string(c) } } else { // look for COLOR word if tpos >= word_pair[1] { words_id++ if words_id >= len(words) { word_pair = []int{999, 999} } else { word_pair = words[words_id] } } if word_pair[0] == tpos { // start of word possible := text[word_pair[0]:word_pair[1]] color_code, has := colors[strings.ToUpper(possible)] // log.Printf("Match %s / found %s %#v\n", possible, color_code, has) if has { word_color = color_code } else { word_color = colors["ALL"] } if last_color != word_color { result += word_color last_color = word_color } } result += string(c) } } } return result } return renderF } func DeckColorMenu(current string) door.Menu { m := door.Menu{Panel: door.Panel{Width: 31, X: 5, Y: 5, Style: door.DOUBLE, Title: "[ Deck Menu ]", TitleColor: door.ColorText("BRI CYAN ON BLUE"), BorderColor: door.ColorText("CYAN ON BLUE")}} unselectMap := map[string]string{"BLUE": door.ColorText("BRI BLUE ON BLUE"), "BROWN": door.ColorText("BROWN ON BLUE"), "RED": door.ColorText("BRI RED ON BLUE"), "CYAN": door.ColorText("CYAN ON BLUE"), "GREEN": door.ColorText("BRI GREEN ON BLUE"), "MAGENTA": door.ColorText("BRI MAGENTA ON BLUE"), "WHITE": door.ColorText("BRI WHITE ON BLUE"), "ALL": door.ColorText("BRI WHITE ON BLUE")} selectMap := map[string]string{"BLUE": door.ColorText("BRI BLUE ON BLACK"), "BROWN": door.ColorText("BROWN ON BLACK"), "RED": door.ColorText("BRI RED ON BLACK"), "CYAN": door.ColorText("CYAN ON BLACK"), "GREEN": door.ColorText("BRI GREEN ON BLACK"), "MAGENTA": door.ColorText("BRI MAGENTA ON BLACK"), "WHITE": door.ColorText("BRI WHITE ON BLACK"), "ALL": door.ColorText("BRI WHITE ON BLACK")} m.SelectedR = MakeColorsRender(door.ColorText("BOLD CYAN"), door.ColorText("BOLD BLUE"), selectMap) m.UnselectedR = MakeColorsRender(door.ColorText("BOLD YEL ON BLUE"), door.ColorText("BOLD WHI ON BLUE"), unselectMap) m.Chosen = 0 for idx, color := range DeckColors { m.AddSelection(color[:1], color) if color == current { m.Chosen = idx } } return m }