Przeglądaj źródła

Initial start of configuration menu.

Steve Thielemann 5 lat temu
rodzic
commit
da722c5197
2 zmienionych plików z 78 dodań i 12 usunięć
  1. 76 12
      flexible.py
  2. 2 0
      galaxy.py

+ 76 - 12
flexible.py

@@ -1735,17 +1735,10 @@ class ProxyMenu(object):
             #     " " + self.c1 + ch + self.c2 + " - " + self.c1 + desc + self.nl
             # )
 
+        menu_item("C", "Configuration ({0})".format(len(self.game.gamedata.config)))
         menu_item("D", "Display Report again")
         # menu_item("Q", "Quest")
-        # if hasattr(self.game, 'portdata'):
-        #     ports = len(self.game.portdata)
-        # else:
-        #    ports = '?'
         menu_item("P", "Port CIM Report ({0})".format(len(self.game.gamedata.ports)))
-        # if hasattr(self.game, 'warpdata'):
-        #     warps = len(self.game.warpdata)
-        # else:
-        #     warps = '?'
         menu_item("W", "Warp CIM Report ({0})".format(len(self.game.gamedata.warps)))
         menu_item("T", "Trading Report")
         menu_item("S", "Scripts")
@@ -1775,6 +1768,9 @@ class ProxyMenu(object):
         ok_trades = []
         best_trades = []
 
+        show_best = self.game.gamedata.get_config('Display_Best', 'Y').upper()[0] == 'Y'
+        show_ok = self.game.gamedata.get_config('Display_Ok', 'N').upper()[0] == 'Y'
+
         # for sector, pd in self.game.gamedata.ports.items():
         for sector in sorted(self.game.gamedata.ports.keys()):
             pd = self.game.gamedata.ports[sector]
@@ -1816,10 +1812,16 @@ class ProxyMenu(object):
                                 ok_trades.append(self.game.gamedata.port_trade_show(sector, w))
             yield
 
-        self.trade_report.append("Best Trades: (org/equ)")
-        self.trade_report.extend(best_trades)
-        self.trade_report.append("Ok Trades:")
-        self.trade_report.extend(ok_trades)
+        if show_best:
+            self.trade_report.append("Best Trades: (org/equ)")
+            self.trade_report.extend(best_trades)
+        if show_ok:
+            self.trade_report.append("Ok Trades:")
+            self.trade_report.extend(ok_trades)
+
+        if not show_best and not show_ok:
+            self.queue_game.put(Boxes.alert("You probably want to choose something to display in configuration!", color="red"))
+
         # self.queue_game.put("BEST TRADES:" + self.nl + self.nl.join(best_trades) + self.nl)
         # self.queue_game.put("OK TRADES:" + self.nl + self.nl.join(ok_trades) + self.nl)
 
@@ -1888,6 +1890,10 @@ class ProxyMenu(object):
                     self.queue_game.put(t + self.nl)
             else:
                 self.queue_game.put("Missing trade_report." + self.nl)
+        elif key == "C":
+            self.queue_game.put(self.c + key + self.r + self.nl)
+            self.activate_config_menu()
+            return
             # self.queue_game.put(pformat(self.portdata).replace("\n", "\n\r") + self.nl)
             # self.queue_game.put(pformat(self.warpdata).replace("\n", "\n\r") + self.nl)    
         elif key == "Q":
@@ -1958,11 +1964,69 @@ class ProxyMenu(object):
         self.keepalive.start(30, True)
         self.menu()
 
+    def activate_config_menu(self):
+        self.observer.disconnect("player", self.player)
+        self.observer.connect("player", self.config_player)
+        self.config_menu()
+
+    def deactivate_config_menu(self, *data):
+        log.warn("deactivate_config_menu ({0})".format(data))
+        self.observer.disconnect("player", self.config_player)
+        self.observer.connect("player", self.player)  
+        self.welcome_back() 
+
     def activate_scripts_menu(self):
         self.observer.disconnect("player", self.player)
         self.observer.connect("player", self.scripts_player)
         self.scripts_menu()
 
+    def config_player(self, chunk: bytes):
+        """ Data from player (in bytes). """
+        chunk = chunk.decode("latin-1", "ignore")
+        key = chunk.upper()
+
+        if key == 'X':
+            self.queue_game.put(self.c + key + self.r + self.nl)            
+            self.deactivate_config_menu()
+            return
+        else:
+            self.queue_game.put(self.c + "?" + self.r + self.nl)
+        self.config_menu()
+
+    def config_menu(self, *_):
+        c1 = merge(Style.BRIGHT + Fore.CYAN)
+        c2 = merge(Style.NORMAL + Fore.CYAN)
+
+        box = Boxes(40, color=c1)
+
+        self.queue_game.put(box.top())
+        self.queue_game.put(box.row(c1 + "{0:^40}".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)
+            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)
+            # self.queue_game.put(
+            #     " " + c1 + ch + c2 + " - " + c1 + desc + self.nl
+            # )
+            self.queue_game.put(box.row(row))
+
+        index = 1
+        for k in sorted(self.game.gamedata.config.keys()):
+        # for k, v in self.game.gamedata.config.items():
+            v = self.game.gamedata.config[k]
+            config_option(index, k, v)
+            index += 1
+
+        menu_item("X", "eXit")
+        self.queue_game.put(box.bottom())
+        self.queue_game.put("   " + c1 + "-=>" + self.r + " ")
+
+
+
     def deactivate_scripts_menu(self, *data):
         log.warn("deactivate_scripts_menu ({0})".format(data))
         self.observer.disconnect("player", self.scripts_player)

+ 2 - 0
galaxy.py

@@ -188,6 +188,8 @@ class GameData(object):
     def get_config(self, key, default=None):
         if key in self.config:
             return self.config[key]
+        else:
+            self.config[key] = default
         return default
 
     def set_config(self, key, value):