Quellcode durchsuchen

Adds Macro ability. (limited to 1 run, currently)

Steve Thielemann vor 5 Jahren
Ursprung
Commit
28a33a9d4d
1 geänderte Dateien mit 41 neuen und 4 gelöschten Zeilen
  1. 41 4
      flexible.py

+ 41 - 4
flexible.py

@@ -2502,6 +2502,8 @@ class ProxyMenu(object):
         self.queue_game = game.queue_game
         self.observer = game.observer
 
+        self.game.gamedata.get_config('Macro', 'D^1N^D')
+
         # Am I using self or game?  (I think I want game, not self.)
         # if hasattr(self.game, "portdata"):
         #     self.portdata = self.game.portdata
@@ -2559,6 +2561,7 @@ class ProxyMenu(object):
         menu_item("D", "Display Report again")
         menu_item("E", "Export Data (Save)")
         # menu_item("Q", "Quest")
+        menu_item("M", "Macro")
         menu_item("P", "Port CIM Report ({0})".format(len(self.game.gamedata.ports)))
         menu_item("W", "Warp CIM Report ({0})".format(len(self.game.gamedata.warps)))
         menu_item("R", "Restock Report")
@@ -2767,6 +2770,15 @@ class ProxyMenu(object):
             d.addCallback(self.warp_report)
             d.addErrback(self.welcome_back)            
             return
+        elif key == "M":
+            self.queue_game.put(self.c + key + self.r + self.nl)
+            self.activate_macro(1)
+            if False:
+                ask = PlayerInput(self.game)
+                d = ask.prompt("How many times?", 10, name="times", abort_blank=True, digits=True)
+                d.addCallback(self.activate_macro)
+                d.addErrback(self.welcome_back)
+            return
         elif key == "S":
             self.queue_game.put(self.c + key + self.r + self.nl)
             # Scripts
@@ -2782,7 +2794,6 @@ class ProxyMenu(object):
             for sector, data in s.items():
                 self.queue_game.put(box.row("{0}  {1:5}{2} {3:^5} ".format( self.c1, sector, self.c2, data['class'])))
             self.queue_game.put(box.bottom())
-
         elif key == "D":
             self.queue_game.put(self.c + key + self.r + self.nl)
             # (Re) Display Trade Report
@@ -2890,6 +2901,26 @@ class ProxyMenu(object):
         self.observer.connect("player", self.player)  
         self.welcome_back() 
 
+    def activate_macro(self, *data):
+        log.warn("macro: ({0})".format(data))
+        
+        macro = self.game.gamedata.get_config('Macro', 'D')
+        # Macro processing would go in here ...
+        macro = macro.replace('^', "\r")
+        log.warn("macro: [{0}]".format(repr(macro)))
+        self.game.queue_player.put(macro)
+
+        log.warn("Restore ...")
+        self.observer.load(self.save)
+        self.save = None
+        self.keepalive = None
+
+        if self.defer:
+            reactor.CallLater(0, self.defer.callback)
+            self.defer = None
+
+        # self.welcome_back()
+
     def activate_scripts_menu(self):
         self.observer.disconnect("player", self.player)
         self.observer.connect("player", self.scripts_player)
@@ -2910,7 +2941,10 @@ class ProxyMenu(object):
                 # 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)
+                if self.option_select == 'Macro':
+                    d = ask.prompt("Change {0} to?".format(self.option_select), 48)
+                else:                    
+                    d = ask.prompt("Change {0} to?".format(self.option_select), 18)
                 d.addCallback(self.option_entry)
                 # d.addErrback(self.config_menu)
             else:
@@ -2942,7 +2976,10 @@ class ProxyMenu(object):
                 # 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)
+                if self.option_select == 'Macro':
+                    d = ask.prompt("Change {0} to?".format(self.option_select), 48)
+                else:
+                    d = ask.prompt("Change {0} to?".format(self.option_select), 18)
                 d.addCallback(self.option_entry)
                 # d.addErrback(self.config_menu)
                 return
@@ -2973,7 +3010,7 @@ class ProxyMenu(object):
         self.queue_game.put(box.middle())
 
         def config_option(index, key, value):
-            row = "{0}{1:2}   {2:19}{3}{4:<20}".format(c1, index, key, c2, value)
+            row = "{0}{1:2}   {2:19}{3}{4:<20.20}".format(c1, index, key, c2, value)
             self.queue_game.put(box.row(row))
 
         def menu_item(ch, desc):