Quellcode durchsuchen

Working config edit. (Colors ugly, but it works.)

Steve Thielemann vor 5 Jahren
Ursprung
Commit
bcbfb691f0
1 geänderte Dateien mit 52 neuen und 7 gelöschten Zeilen
  1. 52 7
      flexible.py

+ 52 - 7
flexible.py

@@ -1980,12 +1980,48 @@ class ProxyMenu(object):
         self.observer.connect("player", self.scripts_player)
         self.scripts_menu()
 
+    def option_entry(self, entry):
+        if len(entry) > 0:
+            # Ok, they gave us something
+            self.game.gamedata.set_config(self.option_select, entry.strip())
+        else:
+            self.queue_game.put("Edit aborted." + self.nl)
+        self.config_menu()
+
+    def option_input(self, option):
+        if len(option) > 0:
+            option = int(option)
+            if option in self.config_opt:
+                # Ok, it's a valid option!
+                self.option_select = self.config_opt[option]
+                ask = PlayerInput(self.game)
+                d = ask.prompt("Change {0} to?".format(self.option_select), 18)
+                d.addCallback(self.option_entry)
+                # d.addErrback(self.config_menu)
+            else:
+                self.queue_game.put("Unknown option, sorry." + self.nl)
+                self.config_menu()
+        else:
+            # Aborted
+            self.config_menu()
+
     def config_player(self, chunk: bytes):
         """ Data from player (in bytes). """
         chunk = chunk.decode("latin-1", "ignore")
         key = chunk.upper()
 
-        if key == 'X':
+        if key == 'C':
+            self.queue_game.put(self.c + key + self.r + self.nl)            
+            self.game.gamedata.config = {}
+        elif key == 'E':
+            self.queue_game.put(self.c + key + self.r + self.nl)            
+            ask = PlayerInput(self.game)
+            d = ask.prompt("Which to edit?", 4, name='option', abort_blank=True, digits=True)
+            d.addCallback(self.option_input)
+            d.addErrback(self.config_menu)
+            return
+
+        elif key == 'X':
             self.queue_game.put(self.c + key + self.r + self.nl)            
             self.deactivate_config_menu()
             return
@@ -1994,33 +2030,42 @@ class ProxyMenu(object):
         self.config_menu()
 
     def config_menu(self, *_):
-        c1 = merge(Style.BRIGHT + Fore.CYAN)
-        c2 = merge(Style.NORMAL + Fore.CYAN)
+        titlecolor = merge(Style.BRIGHT + Fore.CYAN + Back.BLUE)
 
-        box = Boxes(40, color=c1)
+        c1 = merge(Style.BRIGHT + Fore.CYAN + Fore.BLUE)
+        c2 = merge(Style.NORMAL + Fore.CYAN + Back.BLACK)
+
+        box = Boxes(44, color=titlecolor)
 
         self.queue_game.put(box.top())
-        self.queue_game.put(box.row(c1 + "{0:^40}".format("Configuration")))
+        self.queue_game.put(box.row(titlecolor + "{0:^44}".format("Configuration")))
         self.queue_game.put(box.middle())
 
         def config_option(index, key, value):
-            row = "{0:2}{1}{2:18}{3}{4:<20}".format(index, c1, key, c2, value)
+            row = "{0}{1:2}   {2:19}{3}{4:<20}".format(c1, index, key, c2, value)
             self.queue_game.put(box.row(row))
 
         def menu_item(ch, desc):
-            row = " {0}{1} {2}-{3} {4:35}".format(c1, ch, c2, c1, desc)
+            row = " {0}{1} {2}-{3} {4:39}".format(c1, ch, c2, c1, desc)
             # self.queue_game.put(
             #     " " + c1 + ch + c2 + " - " + c1 + desc + self.nl
             # )
             self.queue_game.put(box.row(row))
 
         index = 1
+        self.config_opt = {}
+
         for k in sorted(self.game.gamedata.config.keys()):
         # for k, v in self.game.gamedata.config.items():
             v = self.game.gamedata.config[k]
+            self.config_opt[index] = k
             config_option(index, k, v)
             index += 1
 
+        self.queue_game.put(box.middle())
+
+        menu_item("C", "Clear Config")
+        menu_item("E", "Edit Item")
         menu_item("X", "eXit")
         self.queue_game.put(box.bottom())
         self.queue_game.put("   " + c1 + "-=>" + self.r + " ")