Exemplo n.º 1
0
    class createPane(Pane):
        def __init__(self, parent):
            self._parent = parent
            Pane.__init__(self)
            self._clientcon = ClientConnection()
            self.x = MENUPOS[0]
            self.y = MENUPOS[1]
            self.width = MENUSIZE[0]
            self.height = MENUSIZE[1]

            DEBUG_NAME = "Test Game"

            self.add(Label("NEW NETWORK GAME", pos=(160, 1)))
            self.add(Label("Name", pos=(MENUPAD[0], MENUPAD[2])))
            self.i_name = self.add(Entry(DEBUG_NAME, pos=(MENUPAD[0] + 140, MENUPAD[2]), size=(220, 10)))
            self.add(Label("Number of Players", pos=(MENUPAD[0], MENUPAD[2] + 25)))
            self.i_num = self.add(Entry("3", pos=(MENUPAD[0] + 140, MENUPAD[2] + 25), size=(40, 10)))
            self.add(Label("Map", pos=(MENUPAD[0] + 160, MENUPAD[2] + 50)))
            self.s_maps = self.add(
                SelList([], pos=(MENUPAD[0], MENUPAD[2] + 75), size=(MENUSIZE[0] - MENUPAD[2] - 5, 150))
            )
            self.add(Button("Ok", self._ok, pos=(MENUPAD[0], MENUSIZE[1] - MENUPAD[3] - 20), size=(100, 12)))
            self.add(
                Button("Cancel", self._cancel, pos=(MENUSIZE[0] - 120, MENUSIZE[1] - MENUPAD[3] - 20), size=(100, 12))
            )

            self._mapStore = MapStore()
            self._refreshMaps()

        def _ok(self):
            self.createDialog = gui.add(Dialog())
            if self.i_name.text is "":
                self.createDialog.text = "Please enter a name for the game"
                self.createDialog.button.text = "ok"
            elif self.i_num.text is "" or int(self.i_num.text) > MAX_GAME_PLAYERS:
                self.createDialog.text = "Invalid number of players"
                self.createDialog.button.text = "ok"
            elif self.s_maps.getSelectedOption() is None:
                self.createDialog.text = "Please select a map"
                self.createDialog.button.text = "ok"
            else:
                self.createDialog.text = "Creating game."
                # print(self._mapStore)
                mapName = self.s_maps.buttons[self.s_maps.getSelectedOption()].text
                # print(mapName)
                mapDict = self._mapStore.getMap(name=mapName)

                print("id=%s" % mapDict["id"])
                if mapDict is not None:
                    self._clientcon.newGame(self.i_name.text, mapDict["id"], self.i_num.text, self._createResponse)
                else:
                    self.createDialog.text = "Cannot load selected map"
                    LOG.error("[createPane] Cannot load selected map")

        def _createResponse(self, status):
            print("Resp=%s" % status)
            if status > 0:
                self.createDialog.ok()
                self._parent._refreshGames()
                self._cancel()
            else:
                self.createDialog.text = "Error creating game"
                LOG.error("[createPane] Error creating game")

        def _cancel(self):
            self._parent.visible = True
            self.visible = False
            gui.remove(self)
            del (self)

        def _refreshMaps(self):
            self._mapStore.rescan()
            mapList = self._mapStore.getAvailableNames()
            for b in self.s_maps.buttons:
                self.remove(b)
            for m in mapList:
                self.s_maps.addOption(m)
Exemplo n.º 2
0
    class createPane(Pane):
        def __init__(self, parent):
            self._parent = parent
            Pane.__init__(self)
            self._clientcon = ClientConnection()
            self.x = MENUPOS[0]
            self.y = MENUPOS[1]
            self.width = MENUSIZE[0]
            self.height = MENUSIZE[1]

            DEBUG_NAME = "Test Game"

            self.add(Label("NEW NETWORK GAME", pos=(160, 1)))
            self.add(Label("Name", pos=(MENUPAD[0], MENUPAD[2])))
            self.i_name = self.add(
                Entry(DEBUG_NAME,
                      pos=(MENUPAD[0] + 140, MENUPAD[2]),
                      size=(220, 10)))
            self.add(
                Label("Number of Players", pos=(MENUPAD[0], MENUPAD[2] + 25)))
            self.i_num = self.add(
                Entry("3",
                      pos=(MENUPAD[0] + 140, MENUPAD[2] + 25),
                      size=(40, 10)))
            self.add(Label("Map", pos=(MENUPAD[0] + 160, MENUPAD[2] + 50)))
            self.s_maps = self.add(
                SelList([],
                        pos=(MENUPAD[0], MENUPAD[2] + 75),
                        size=(MENUSIZE[0] - MENUPAD[2] - 5, 150)))
            self.add(
                Button("Ok",
                       self._ok,
                       pos=(MENUPAD[0], MENUSIZE[1] - MENUPAD[3] - 20),
                       size=(100, 12)))
            self.add(
                Button("Cancel",
                       self._cancel,
                       pos=(MENUSIZE[0] - 120, MENUSIZE[1] - MENUPAD[3] - 20),
                       size=(100, 12)))

            self._mapStore = MapStore()
            self._refreshMaps()

        def _ok(self):
            self.createDialog = gui.add(Dialog())
            if (self.i_name.text is ''):
                self.createDialog.text = "Please enter a name for the game"
                self.createDialog.button.text = "ok"
            elif (self.i_num.text is ''
                  or int(self.i_num.text) > MAX_GAME_PLAYERS):
                self.createDialog.text = "Invalid number of players"
                self.createDialog.button.text = "ok"
            elif (self.s_maps.getSelectedOption() is None):
                self.createDialog.text = "Please select a map"
                self.createDialog.button.text = "ok"
            else:
                self.createDialog.text = "Creating game."
                #print(self._mapStore)
                mapName = self.s_maps.buttons[
                    self.s_maps.getSelectedOption()].text
                #print(mapName)
                mapDict = self._mapStore.getMap(name=mapName)

                print("id=%s" % mapDict['id'])
                if mapDict is not None:
                    self._clientcon.newGame(self.i_name.text, mapDict['id'],
                                            self.i_num.text,
                                            self._createResponse)
                else:
                    self.createDialog.text = "Cannot load selected map"
                    LOG.error("[createPane] Cannot load selected map")

        def _createResponse(self, status):
            print("Resp=%s" % status)
            if status > 0:
                self.createDialog.ok()
                self._parent._refreshGames()
                self._cancel()
            else:
                self.createDialog.text = "Error creating game"
                LOG.error("[createPane] Error creating game")

        def _cancel(self):
            self._parent.visible = True
            self.visible = False
            gui.remove(self)
            del (self)

        def _refreshMaps(self):
            self._mapStore.rescan()
            mapList = self._mapStore.getAvailableNames()
            for b in self.s_maps.buttons:
                self.remove(b)
            for m in mapList:
                self.s_maps.addOption(m)