def changeServer(self, root): if self.server == None: pytorque.setglobal("$loginInfo::message", "Login failed!") return WorldListBox = TorqueObject("WorldList") self.server.callRemote("changeServer", int( WorldListBox.getSelectedId())).addCallback(self._changeServer)
def _getWorldList(self, list): print "_getWorldList(self, list): %d"%len(list) WorldListBox = TorqueObject("WorldList") for key in list: print "key[%d] name[%s]"%(key, list[key]) WorldListBox.addRow(key, list[key]) loginButton = TorqueObject("LoginButton") signupButton = TorqueObject("SignupButton") loginButton.setActive(1) signupButton.setActive(1) pytorque.setglobal("$loginInfo::message","Version updated!") self.updated = True
def OnSignupPressed(ip, port): global clientObj global userObj if not clientObj.updated: return username = pytorque.getglobal("$loginInfo::username") password1 = pytorque.getglobal("$loginInfo::password1") password2 = pytorque.getglobal("$loginInfo::password2") if password1 == "" or (password1 != password2): pytorque.setglobal("$loginInfo::message","Password Error!") return roleCtrl = TorqueObject("LoginRole") roleId = int(roleCtrl.getSelected()) #print "name[%s] password[%s] confirm[%s] role[%d]" % (usernameCtrl.getText(), password1Ctrl.getText(), password2Ctrl.getText(), roleCtrl.getSelected()) print "name[%s] password[%s] confirm[%s] role[%d]" % (username, password1, password2, roleId) clientObj.register(username, password1, roleId)
def OnSignupPressed(ip, port): global clientObj global userObj if not clientObj.updated: return username = pytorque.getglobal("$loginInfo::username") password1 = pytorque.getglobal("$loginInfo::password1") password2 = pytorque.getglobal("$loginInfo::password2") if password1 == "" or (password1 != password2): pytorque.setglobal("$loginInfo::message", "Password Error!") return roleCtrl = TorqueObject("LoginRole") roleId = int(roleCtrl.getSelected()) #print "name[%s] password[%s] confirm[%s] role[%d]" % (usernameCtrl.getText(), password1Ctrl.getText(), password2Ctrl.getText(), roleCtrl.getSelected()) print "name[%s] password[%s] confirm[%s] role[%d]" % (username, password1, password2, roleId) clientObj.register(username, password1, roleId)
def main(): global clientObj global userObj Running = False OPTIONS, argv = getOptions('mmolite/config/client.cfg', 'client', sys.argv) print "MMO test client initializing torque client" if '-game' not in argv: argv.extend(['-game', 'test.mmo']) pytorque.initialize(len(argv), argv) print "MMO test client connecting to: ip[%s] port[%d]" % ( OPTIONS.master_ip, OPTIONS.master_port) clientObj = PbAuthClient() clientObj.login("Client", "tneilc", OPTIONS.master_ip, OPTIONS.master_port) userObj = PbAuthUser() # get torque object loginButton = TorqueObject("LoginButton") signupButton = TorqueObject("SignupButton") # set torque object's attribute loginButton.Command = 'LoginButton.OnButton("%s", %s);' % ( OPTIONS.master_ip, OPTIONS.master_port) signupButton.Command = 'SignupButton.OnButton("%s", %s);' % ( OPTIONS.master_ip, OPTIONS.master_port) # map python function to torque action pytorque.export(OnLoginPressed, "LoginButton", "OnButton", "Login button command", 2, 2) pytorque.export(OnSignupPressed, "SignupButton", "OnButton", "Signup button command", 2, 2) # call torque object method loginButton.setActive(0) signupButton.setActive(0) print "MMO test client running" reactor.startRunning() #the main loop is broken out and can be combined with other frameworks rather easily while pytorque.tick(): reactorTick() #cleanup pytorque.. goodbye! pytorque.shutdown() print "MMO test client quit"
def main(): global clientObj global userObj Running = False OPTIONS, argv = getOptions('mmolite/config/client.cfg', 'client', sys.argv) print "MMO test client initializing torque client" if '-game' not in argv: argv.extend(['-game', 'test.mmo']) pytorque.initialize(len(argv),argv) print "MMO test client connecting to: ip[%s] port[%d]"%(OPTIONS.master_ip, OPTIONS.master_port) clientObj = PbAuthClient() clientObj.login("Client", "tneilc", OPTIONS.master_ip, OPTIONS.master_port) userObj = PbAuthUser() # get torque object loginButton = TorqueObject("LoginButton") signupButton = TorqueObject("SignupButton") # set torque object's attribute loginButton.Command = 'LoginButton.OnButton("%s", %s);'%(OPTIONS.master_ip, OPTIONS.master_port) signupButton.Command = 'SignupButton.OnButton("%s", %s);'%(OPTIONS.master_ip, OPTIONS.master_port) # map python function to torque action pytorque.export(OnLoginPressed,"LoginButton","OnButton","Login button command",2,2) pytorque.export(OnSignupPressed,"SignupButton","OnButton","Signup button command",2,2) # call torque object method loginButton.setActive(0) signupButton.setActive(0) print "MMO test client running" reactor.startRunning() #the main loop is broken out and can be combined with other frameworks rather easily while pytorque.tick(): reactorTick() #cleanup pytorque.. goodbye! pytorque.shutdown() print "MMO test client quit"
def _getWorldList(self, list): print "_getWorldList(self, list): %d" % len(list) WorldListBox = TorqueObject("WorldList") for key in list: print "key[%d] name[%s]" % (key, list[key]) WorldListBox.addRow(key, list[key]) loginButton = TorqueObject("LoginButton") signupButton = TorqueObject("SignupButton") loginButton.setActive(1) signupButton.setActive(1) pytorque.setglobal("$loginInfo::message", "Version updated!") self.updated = True
profile = "GuiButtonProfile"; horizSizing = "right"; vertSizing = "bottom"; position = "404 361"; extent = "285 85"; minExtent = "8 2"; visible = "1"; text = "Button"; groupNum = "-1"; buttonType = "PushButton"; bitmap = "./button"; helpTag = "0"; };""") #it's easy to grab a reference to the button we created button = TorqueObject("MyButton") #buttons are kind of worthless without commands. Let's make one: def OnMyButton(value): print "Button pushed with value",value #export the function to the console system in much the same way the C++ system does... #we also support optional namespaces, usage documentation, and min/max args pytorque.export(OnMyButton,"MyButton","OnButton","Example button command",1,1) #we can get and set fields (including dynamic fields). We'll set our button's command: button.command = "MyButton::OnButton(42);" #we can call console methods on our TorqueObjects... So, let's simulate a button click. #the OnMyButton function will be called with the value 42 :) button.performClick()
def changeServer(self, root): if self.server == None: pytorque.setglobal("$loginInfo::message","Login failed!") return WorldListBox = TorqueObject("WorldList") self.server.callRemote("changeServer", int(WorldListBox.getSelectedId())).addCallback(self._changeServer)