Guest User

Untitled

a guest
Jan 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. import direct.directbase.DirectStart
  2. from direct.showbase.DirectObject import DirectObject
  3. from direct.gui.OnscreenText import OnscreenText
  4. from direct.gui.DirectGui import *
  5. from pandac.PandaModules import *
  6.  
  7.  
  8. ### client logic
  9. # connect to patcher to see if update is available
  10. # connect to login server
  11. # send login credentials
  12.  
  13.  
  14.  
  15.  
  16. class GameClient(DirectObject):
  17. def __init__(self):
  18. base.setBackgroundColor( 0, 0, 0 )
  19. # sets the background color to black because the
  20. # default grey color bugs me for some reason
  21. #### HERE ####
  22. def hide(self):
  23.  
  24. self.loginScreen()
  25. # draws the login screen
  26.  
  27. self.usernameBox['focus'] = 1
  28. # sets the cursor to the username field by default
  29.  
  30. self.accept('tab', self.cycleLoginBox)
  31. # enables the user to cycle through the text fields with the tab key
  32. # this is a standard feature on most login forms
  33.  
  34. self.accept('enter', self.attemptLogin)
  35. # submits the login form, or you can just click the Login button
  36.  
  37. def loginScreen(self):
  38. # creates a basic login screen that asks for a username/password
  39.  
  40. boxloc = Vec3(0.0, 0.0, 0.0)
  41. # all items in the login form will have a position relative to this
  42. # this makes it easier to shift the entire form around once we have
  43. # some graphics to display with it without having to change the
  44. # positioning of every form element
  45.  
  46. # p is the position of the form element relative to the boxloc
  47. # coordinates set above it is changed for every form element
  48. p = boxloc + Vec3(-0.5, 0, 0.0)
  49. self.textObject = OnscreenText(text = "Username:", pos = p, scale = 0.07,fg=(1, 1, 1, 1),align=TextNode.ALeft)
  50. # "Username: " text that appears beside the username box
  51.  
  52. p = boxloc + Vec3(-0.1, 0.0, 0.0)
  53. self.usernameBox = DirectEntry(text = "" , pos = p, scale=.05, initialText="", numLines = 1)
  54. # Username textbox where you type in your username
  55.  
  56. p = boxloc + Vec3(-0.5, -0.1, 0.0)
  57. self.textObject = OnscreenText(text = "Password:", pos = p, scale = 0.07,fg=(1, 1, 1, 1),align=TextNode.ALeft)
  58. # "Password: " text that appears beside the password box
  59.  
  60. p = boxloc + Vec3(-0.1, 0, -0.1)
  61. self.passwordBox = DirectEntry(text = "" , pos = p, scale=.05, initialText="", numLines = 1, obscured = 1)
  62. # Password textbox where you type in your password
  63. # Note - obscured = 1 denotes that all text entered will be replaced
  64. # with a * like a standard password box
  65.  
  66. p = boxloc + Vec3(0, 0, -0.2)
  67. self.loginButton = DirectButton(text = ("Login", "Login", "Login", "Login"), pos = p, scale = 0.075, command=self.attemptLogin)
  68. # The 'Login' button that will trigger the attemptLogin function
  69. # when clicked
  70.  
  71. p = boxloc + Vec3(-0.5, -0.4, 0)
  72. self.statusText = OnscreenText(text = "", pos = p, scale = 0.05, fg = (1, 0, 0, 1), align=TextNode.ALeft)
  73. # A simple text object that you can display an error/status messages
  74. # to the user
  75.  
  76. def updateStatus(self, statustext):
  77. self.statusText.setText(statustext)
  78. # all this does is change the status text.
  79.  
  80. def attemptLogin(self):
  81. # checks to make sure the user inputed a username and password:
  82. # if they didn't it will spit out an error message
  83. # if they did, it will try to connect to the login server
  84. # (under construction)
  85.  
  86. if(self.usernameBox.get() == ""):
  87. if(self.passwordBox.get() == ""):
  88. self.updateStatus("ERROR: You must enter a username and password before logging in.")
  89. else:
  90. self.updateStatus("ERROR: You must specify a username")
  91. self.passwordBox['focus'] = 0
  92. self.usernameBox['focus'] = 1
  93.  
  94. elif(self.passwordBox.get() == ""):
  95. self.updateStatus("ERROR: You must enter a password")
  96. self.usernameBox['focus'] = 0
  97. self.passwordBox['focus'] = 1
  98.  
  99. else:
  100. self.updateStatus("Attempting to login...")
  101. print "Attempting to connect to Server with credentials: (" + self.usernameBox.get() + ", " + self.passwordBox.get() + ")"
  102. #
  103. # this is where the networking code will get put in
  104. self.loginScreen.hide()
  105.  
  106. def cycleLoginBox(self):
  107. # function is triggered by the tab key so you can cycle between
  108. # the two input fields like on most login screens
  109.  
  110. # IMPORTANT: When you change the focus to one of the text boxes,
  111. # you have to unset the focus on the other textbox. If you do not
  112. # do this Panda seems to get confused.
  113. if(self.passwordBox['focus'] == 1):
  114. self.passwordBox['focus'] = 0
  115. self.usernameBox['focus'] = 1
  116. elif(self.usernameBox['focus'] == 1):
  117. self.usernameBox['focus'] = 0
  118. self.passwordBox['focus'] = 1
  119.  
  120.  
  121.  
  122. Client = GameClient()
  123. run()
Add Comment
Please, Sign In to add comment