Pārlūkot izejas kodu

Allow numberpad 8/2 as up/down in menu.

We check to make sure they aren't in use as options.
Steve Thielemann 4 gadi atpakaļ
vecāks
revīzija
4e14d901a6
1 mainītis faili ar 38 papildinājumiem un 26 dzēšanām
  1. 38 26
      panel.cpp

+ 38 - 26
panel.cpp

@@ -648,36 +648,48 @@ int Menu::choose(Door &door) {
     unsigned int previous_choice = chosen;
     changed.clear();
 
-    // od_get_input(&event, OD_NO_TIMEOUT, GETIN_NORMAL);
-
-    if (event > XKEY_START) {
-      switch (event) {
-      case XKEY_UP_ARROW:
-        if (chosen > 0) {
-          chosen--;
-          updated = true;
-        }
-        break;
-      case XKEY_DOWN_ARROW:
-        if (chosen < lines.size() - 1) {
-          chosen++;
-          updated = true;
-        }
+    bool use_numberpad = true;
+
+    // Don't use the numberpad, if some of the options are 8 or 2 (up/down)
+    for (const char &c : options) {
+      if ((c == '8') or (c == '2'))
+        use_numberpad = false;
+    }
+
+    switch (event) {
+    case '8':
+      if (!use_numberpad)
         break;
+    case XKEY_UP_ARROW:
+      if (chosen > 0) {
+        chosen--;
+        updated = true;
+      }
+      break;
 
-      case XKEY_HOME:
-        if (chosen != 0) {
-          chosen = 0;
-          updated = true;
-        }
+    case '2':
+      if (!use_numberpad)
         break;
-      case XKEY_END:
-        if (chosen != lines.size() - 1) {
-          chosen = lines.size() - 1;
-          updated = true;
-        }
+    case XKEY_DOWN_ARROW:
+      if (chosen < lines.size() - 1) {
+        chosen++;
+        updated = true;
+      }
+      break;
+
+    case XKEY_HOME:
+      if (chosen != 0) {
+        chosen = 0;
+        updated = true;
+      }
+      break;
+    case XKEY_END:
+      if (chosen != lines.size() - 1) {
+        chosen = lines.size() - 1;
+        updated = true;
       }
-    } else if (event == 0x0d) {
+    }
+    if (event == 0x0d) {
       // ENTER -- use current selection
       return chosen + 1;
     }