瀏覽代碼

Cleaned up Upgrade planet selector.

We now (first) show only planets in
the current sector.

You can still type in any number planet
you wish, but if you're not sure, you
can "L" to list them all.
Steve Thielemann 5 年之前
父節點
當前提交
709e4b1a61
共有 1 個文件被更改,包括 50 次插入34 次删除
  1. 50 34
      flexible.py

+ 50 - 34
flexible.py

@@ -2401,6 +2401,42 @@ class PlanetUpScript(object):
         # self.warpdata = {}
         self.queue_game.put(Boxes.alert("Let me see what I can see here..."))
 
+    def display_planets(self, justLocal=True):
+        tc = merge(Style.BRIGHT + Fore.YELLOW + Back.BLUE)
+        c1 = merge(Style.BRIGHT + Fore.WHITE + Back.BLUE)
+        c2 = merge(Style.BRIGHT + Fore.CYAN + Back.BLUE)
+
+        box = Boxes(44, color=tc)
+        self.queue_game.put(box.top())
+        self.queue_game.put(
+            box.row(
+                tc
+                + "{0:3} {1:6} {2:20} {3} ".format(
+                    " # ", "Sector", "Planet Name", "Citadel LVL"
+                )
+            )
+        )
+        self.queue_game.put(box.middle())
+
+        def planet_output(number, sector, name, citadel):
+            row = "{0}{1:^3} {2:6} {3}{4:29} {0}{5:2} ".format(
+                c1, number, sector, c2, name, citadel
+            )
+            self.queue_game.put(box.row(row))
+
+        for s in sorted(self.planets.keys()):
+            if (justLocal == False) or (
+                self.current_sector == self.planets[s]["sector"]
+            ):
+                planet_output(
+                    s,
+                    self.planets[s]["sector"],
+                    self.planets[s]["name"],
+                    self.planets[s]["citadel"],
+                )
+
+        self.queue_game.put(box.bottom())
+
     def game_prompt(self, prompt):
         log.info("prompt {0} : {1}".format(self.state, prompt))
         if self.state == 1 and re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
@@ -2436,41 +2472,10 @@ class PlanetUpScript(object):
             self.current_sector = int(sector)
 
             # A better default is to ask which planet to upgrade.
-
-            tc = merge(Style.BRIGHT + Fore.YELLOW + Back.BLUE)
-            c1 = merge(Style.BRIGHT + Fore.WHITE + Back.BLUE)
-            c2 = merge(Style.BRIGHT + Fore.CYAN + Back.BLUE)
-
-            box = Boxes(44, color=tc)
-            self.queue_game.put(box.top())
-            self.queue_game.put(
-                box.row(
-                    tc
-                    + "{0:3} {1:6} {2:20} {3} ".format(
-                        " # ", "Sector", "Planet Name", "Citadel LVL"
-                    )
-                )
-            )
-            self.queue_game.put(box.middle())
-
-            def planet_output(number, sector, name, citadel):
-                row = "{0}{1:^3} {2:6} {3}{4:29} {0}{5:2} ".format(
-                    c1, number, sector, c2, name, citadel
-                )
-                self.queue_game.put(box.row(row))
-
-            for s in sorted(self.planets.keys()):
-                planet_output(
-                    s,
-                    self.planets[s]["sector"],
-                    self.planets[s]["name"],
-                    self.planets[s]["citadel"],
-                )
-
-            self.queue_game.put(box.bottom())
+            self.display_planets(True)
 
             ask = PlayerInput(self.game)
-            d = ask.prompt("Choose a planet", 3, name="planet", digits=True)
+            d = ask.prompt("Choose a planet (L to List)", 3, name="planet")
             d.addCallback(self.planet_chosen)
         elif self.state == 3:
             if prompt.startswith("Do you want to engage the TransWarp drive? "):
@@ -2698,8 +2703,19 @@ class PlanetUpScript(object):
     def planet_chosen(self, choice: str):
         if choice.strip() == "":
             self.deactivate()
+        elif choice.strip()[0] == "L":
+            self.display_planets(False)
+
+            ask = PlayerInput(self.game)
+            d = ask.prompt("Choose a planet (L to List)", 3, name="planet")
+            d.addCallback(self.planet_chosen)
+            return
         else:
-            self.planet_number = int(choice)
+            try:
+                self.planet_number = int(choice)
+            except ValueError:
+                self.deactivate()
+                return
             if self.planet_number in self.planets:
                 # Ok, this'll work
                 self.planet_sector = self.planets[self.planet_number]["sector"]