menus.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package main
  2. import (
  3. "red-green/door"
  4. "strings"
  5. )
  6. func MainMenu() door.Menu {
  7. // Make the main menu
  8. m := door.Menu{Panel: door.Panel{Width: 25,
  9. X: 5,
  10. Y: 5,
  11. Style: door.DOUBLE,
  12. Title: "[ Main Menu: ]",
  13. TitleOffset: 3,
  14. BorderColor: door.ColorText("BRI CYAN ON BLA")}}
  15. m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"),
  16. door.ColorText("BOLD BLUE"),
  17. door.ColorText("BOLD CYAN"),
  18. door.ColorText("BOLD BLUE"))
  19. m.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"),
  20. door.ColorText("BOLD WHI ON BLUE"),
  21. door.ColorText("BOLD YEL ON BLUE"),
  22. door.ColorText("BOLD CYAN ON BLUE"))
  23. m.AddSelection("P", "Play Cards")
  24. m.AddSelection("S", "View Scores")
  25. m.AddSelection("C", "Configure")
  26. m.AddSelection("H", "Help")
  27. m.AddSelection("A", "About this game")
  28. m.AddSelection("Q", "Quit")
  29. return m
  30. }
  31. func ConfigMenu() door.Menu {
  32. m := door.Menu{Panel: door.Panel{Width: 31,
  33. X: 5,
  34. Y: 5,
  35. Style: door.DOUBLE,
  36. Title: "[ Configuration Menu ]",
  37. TitleColor: door.ColorText("BRI CYAN ON BLUE"),
  38. BorderColor: door.ColorText("CYAN ON BLUE")}}
  39. m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"),
  40. door.ColorText("BOLD BLUE"),
  41. door.ColorText("BOLD CYAN"),
  42. door.ColorText("BOLD BLUE"))
  43. m.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"),
  44. door.ColorText("BOLD WHI ON BLUE"),
  45. door.ColorText("BOLD YEL ON BLUE"),
  46. door.ColorText("BOLD CYAN ON BLUE"))
  47. m.AddSelection("D", "Deck Colors")
  48. m.AddSelection("V", "View Settings")
  49. m.AddSelection("Q", "Quit")
  50. return m
  51. }
  52. var DeckColors []string
  53. func init() {
  54. DeckColors = []string{
  55. "All", "Brown", "Green", "Red", "Blue", "Cyan", "Magenta", "White"}
  56. }
  57. func MakeColorsRender(brackets string, text_color string, colors map[string]string) func(string) string {
  58. renderF := func(text string) string {
  59. words := find_words(text)
  60. var option bool = true
  61. var color_word bool = false
  62. var result string
  63. var last_color string
  64. var word_color string
  65. var words_id = 0
  66. word_pair := words[words_id]
  67. normal := colors["ALL"]
  68. for tpos, c := range text {
  69. if option {
  70. if c == '[' || c == ']' {
  71. if last_color != brackets {
  72. result += brackets
  73. last_color = brackets
  74. }
  75. if c == ']' {
  76. option = false
  77. }
  78. } else {
  79. if last_color != text_color {
  80. result += text_color
  81. last_color = text_color
  82. }
  83. }
  84. result += string(c)
  85. } else {
  86. // Out of the options
  87. if color_word {
  88. if tpos < word_pair[1] {
  89. if last_color != word_color {
  90. result += word_color
  91. last_color = word_color
  92. } else {
  93. color_word = false
  94. if last_color != normal {
  95. result += normal
  96. last_color = normal
  97. }
  98. }
  99. result += string(c)
  100. }
  101. } else {
  102. // look for COLOR word
  103. if tpos >= word_pair[1] {
  104. words_id++
  105. if words_id >= len(words) {
  106. word_pair = []int{999, 999}
  107. } else {
  108. word_pair = words[words_id]
  109. }
  110. }
  111. if word_pair[0] == tpos {
  112. // start of word
  113. possible := text[word_pair[0]:word_pair[1]]
  114. color_code, has := colors[strings.ToUpper(possible)]
  115. // log.Printf("Match %s / found %s %#v\n", possible, color_code, has)
  116. if has {
  117. word_color = color_code
  118. } else {
  119. word_color = colors["ALL"]
  120. }
  121. if last_color != word_color {
  122. result += word_color
  123. last_color = word_color
  124. }
  125. }
  126. result += string(c)
  127. }
  128. }
  129. }
  130. return result
  131. }
  132. return renderF
  133. }
  134. func DeckColorMenu(current string) door.Menu {
  135. m := door.Menu{Panel: door.Panel{Width: 31,
  136. X: 5,
  137. Y: 5,
  138. Style: door.DOUBLE,
  139. Title: "[ Deck Menu ]",
  140. TitleColor: door.ColorText("BRI CYAN ON BLUE"),
  141. BorderColor: door.ColorText("CYAN ON BLUE")}}
  142. unselectMap := map[string]string{"BLUE": door.ColorText("BRI BLUE ON BLUE"),
  143. "BROWN": door.ColorText("BROWN ON BLUE"),
  144. "RED": door.ColorText("BRI RED ON BLUE"),
  145. "CYAN": door.ColorText("CYAN ON BLUE"),
  146. "GREEN": door.ColorText("BRI GREEN ON BLUE"),
  147. "MAGENTA": door.ColorText("BRI MAGENTA ON BLUE"),
  148. "WHITE": door.ColorText("BRI WHITE ON BLUE"),
  149. "ALL": door.ColorText("BRI WHITE ON BLUE")}
  150. selectMap := map[string]string{"BLUE": door.ColorText("BRI BLUE ON BLACK"),
  151. "BROWN": door.ColorText("BROWN ON BLACK"),
  152. "RED": door.ColorText("BRI RED ON BLACK"),
  153. "CYAN": door.ColorText("CYAN ON BLACK"),
  154. "GREEN": door.ColorText("BRI GREEN ON BLACK"),
  155. "MAGENTA": door.ColorText("BRI MAGENTA ON BLACK"),
  156. "WHITE": door.ColorText("BRI WHITE ON BLACK"),
  157. "ALL": door.ColorText("BRI WHITE ON BLACK")}
  158. m.SelectedR = MakeColorsRender(door.ColorText("BOLD CYAN"),
  159. door.ColorText("BOLD BLUE"),
  160. selectMap)
  161. m.UnselectedR = MakeColorsRender(door.ColorText("BOLD YEL ON BLUE"),
  162. door.ColorText("BOLD WHI ON BLUE"),
  163. unselectMap)
  164. m.Chosen = 0
  165. for idx, color := range DeckColors {
  166. m.AddSelection(color[:1], color)
  167. if color == current {
  168. m.Chosen = idx
  169. }
  170. }
  171. return m
  172. }