Ver código fonte

Fixed menu 2&8 navigation. Keys case insensitive.

Steve Thielemann 3 anos atrás
pai
commit
326696fb62
2 arquivos alterados com 29 adições e 29 exclusões
  1. 21 19
      door/menu.go
  2. 8 10
      testdoor/testdoor.go

+ 21 - 19
door/menu.go

@@ -114,7 +114,7 @@ func (m *Menu) Choose(d *Door) int {
 
 		updated = false
 
-		var event int = d.WaitKey(Inactivity, 0)
+		var event int = d.Key()
 
 		if event < 0 {
 			return event
@@ -130,26 +130,25 @@ func (m *Menu) Choose(d *Door) int {
 		}
 
 		switch event {
-		case '2':
+		case '8':
 			if use_numberpad {
-				if m.Chosen > 0 {
-					m.Chosen--
-					updated = true
-				}
+				goto use8
 			}
+			break
+		use8:
+			fallthrough
 		case XKEY_UP_ARROW:
 			if m.Chosen > 0 {
 				m.Chosen--
 				updated = true
 			}
-		case '8':
+		case '2':
 			if use_numberpad {
-				if m.Chosen < len(m.Lines)-1 {
-					m.Chosen++
-					updated = true
-				}
-
+				goto use2
 			}
+			break
+		use2:
+			fallthrough
 		case XKEY_DOWN_ARROW:
 			if m.Chosen < len(m.Lines)-1 {
 				m.Chosen++
@@ -170,15 +169,18 @@ func (m *Menu) Choose(d *Door) int {
 			return m.Chosen + 1
 		default:
 			// Is the key in the list of options?
-			for x, option := range m.MenuOptions {
-				if int(option.Ch) == event {
-					if m.Chosen == x {
-						return x + 1
+			if event < 0x1000 {
+				for x, option := range m.MenuOptions {
+					if unicode.ToUpper(rune(option.Ch)) == unicode.ToUpper(rune(event)) {
+						if m.Chosen == x {
+							return x + 1
+						}
+
+						updated = true
+						m.Chosen = x
+						update_and_exit = true
 					}
 				}
-				updated = true
-				m.Chosen = x
-				update_and_exit = true
 			}
 		}
 

+ 8 - 10
testdoor/testdoor.go

@@ -21,7 +21,7 @@ func main() {
 	bold := door.Color(1, 37, 40)
 	bolder := door.ColorText("BLI BOLD YEL ON BLUE")
 	d.Write("Welcome to " + bolder + "door32.sys" + reset + door.CRNL + "..." + door.CRNL)
-	key := d.WaitKey(door.Inactivity, 0)
+	key := d.Key()
 	message := fmt.Sprintf("Key %s%d / %x%s"+door.CRNL, bold, key, key, reset)
 	d.Write(message)
 	b := door.Box{20, 1}
@@ -92,7 +92,7 @@ func main() {
 	}
 
 	d.Write(door.Reset + door.CRNL + "Press a key to continue...")
-	d.WaitKey(120, 0)
+	d.Key()
 	d.Write(door.CRNL)
 
 	m := door.Menu{Panel: door.Panel{Width: 25,
@@ -123,17 +123,12 @@ func main() {
 		test.RenderF = m.UnselectedR
 		d.Write(test.Output() + door.Reset + door.CRNL)
 		d.Write(door.Reset + door.CRNL + "Press a key to continue...")
-		d.WaitKey(120, 0)
+		d.Key()
 	*/
 
 	d.Write(door.Clrscr)
 
-	_ = m.Choose(&d)
-
-	// d.Write(m.Output())
-	// d.WaitKey(120, 0)
-
-	d.Write(door.Reset + door.CRNL + door.CRNL)
+	item := m.Choose(&d)
 
 	SPACE := [...]string{
 		"\x1b[?7h\x1b[255D\x1b[0;1;32m\xdc\x1b[42m\xb2\xb2\xb2\xb2\xdb\x1b[40m\xdc \x1b[42m\xb1\xb1\xb2\xb2\xdb\xdb\x1b[4C\xb1\xb2\xb2\xdb\x1b[4C\xb1\xb2\xb2\xdb\xdb\x1b[3C\xb1\xb2\xb2\xdb\xdb\x1b[11C\xb1\xb2\xb2\xdb\x1b[4C\xb1\xb2\xb2\xdb\xdb\x1b[3C\xb1\xb2\xb2\xdb\xdb\x1b[40m",
@@ -157,8 +152,11 @@ func main() {
 		}
 	}
 
+	d.Write(door.Reset + door.CRNL + door.CRNL)
+	d.Write(fmt.Sprintf("You chose %d from the menu."+door.CRNL, item))
+
 	d.Write(door.Reset + door.CRNL + "Press a key to continue...")
-	d.WaitKey(120, 0)
+	d.Key()
 
 	message = fmt.Sprintf("Returning %s to the BBS..."+door.CRNL, name)
 	d.Write(message)