Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.75 KB | None | 0 0
  1. from OpenGL.GL import *
  2. from OpenGL.GLU import *
  3. from OpenGL.GLUT import *
  4. import PyCEGUI
  5. import PyCEGUIOpenGLRenderer
  6. from twisted.internet import reactor,protocol
  7. path="datafiles\\"
  8.  
  9. class BaseApp(object, protocol.Protocol):
  10.     def __init__(self):
  11.         glutInit(sys.argv)
  12.         glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA)
  13.         glutInitWindowSize(1280, 1024)
  14.         glutInitWindowPosition(100, 100)
  15.         glutCreateWindow("")
  16.         glutSetCursor(GLUT_CURSOR_NONE)
  17.  
  18.         glutDisplayFunc(self.displayFunc)
  19.         glutReshapeFunc(self.reshapeFunc)
  20.         glutMouseFunc(self.mouseFunc)
  21.         glutMotionFunc(self.mouseMotionFunc)
  22.         glutPassiveMotionFunc(self.mouseMotionFunc)
  23.         glutKeyboardFunc(self.keyFunc)
  24.  
  25.         PyCEGUIOpenGLRenderer.OpenGLRenderer.bootstrapSystem()
  26.  
  27.     def __del__(self):
  28.         PyCEGUIOpenGLRenderer.OpenGLRenderer.destroySystem()
  29.  
  30.     def initialiseResources(self):
  31.         rp = PyCEGUI.System.getSingleton().getResourceProvider()
  32.  
  33.         parser = PyCEGUI.System.getSingleton().getXMLParser()
  34.         if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
  35.             parser.setProperty("SchemaDefaultResourceGroup", "schemas")    
  36.  
  37.     def setupUI(self):
  38.         PyCEGUI.SchemeManager.getSingleton().create(path+"VanillaSkin.scheme")
  39.         PyCEGUI.System.getSingleton().setDefaultFont("DejaVuSans-10")
  40.         PyCEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
  41.         layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("C:\\python27\\game\\datafiles\\login.layout")
  42.         PyCEGUI.System.getSingleton().setGUISheet(layout)
  43.         self.loginWindow=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login")
  44.         self.submit=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Submit")
  45.         self.username=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Username")
  46.         self.password=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Password")
  47.         self.submit.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'login')
  48.         self.noUsername=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername")
  49.         self.noUsernameOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername/Ok")
  50.         self.noUsernameOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noUsernameOkClicked')
  51.         self.noPassword=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword")
  52.         self.noPasswordOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword/Ok")
  53.         self.noPasswordOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noPasswordOkClicked')
  54.  
  55.     def run(self):
  56.         self.initialiseResources()
  57.         self.setupUI()
  58.  
  59.         self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)
  60.         self.updateFPS = 0
  61.         glutMainLoop()
  62.  
  63.     def displayFunc(self):
  64.         thisTime = glutGet(GLUT_ELAPSED_TIME)
  65.         elapsed = (thisTime - self.lastFrameTime) / 1000.0
  66.         self.lastFrameTime = thisTime
  67.         self.updateFPS = self.updateFPS - elapsed
  68.  
  69.         PyCEGUI.System.getSingleton().injectTimePulse(elapsed)
  70.  
  71.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  72.         PyCEGUI.System.getSingleton().renderGUI()
  73.         glutPostRedisplay()
  74.         glutSwapBuffers()
  75.  
  76.     def reshapeFunc(self, width, height):
  77.         glViewport(0, 0, width, height)
  78.         glMatrixMode(GL_PROJECTION)
  79.         glLoadIdentity()
  80.         gluPerspective(60.0, width / height, 1.0, 50.0)
  81.         glMatrixMode(GL_MODELVIEW)
  82.         PyCEGUI.System.getSingleton().notifyDisplaySizeChanged(PyCEGUI.Size(width, height))
  83.  
  84.     def mouseFunc(self, button, state, x, y):
  85.         if button == GLUT_LEFT_BUTTON:
  86.             if state == GLUT_UP:
  87.                 PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.LeftButton)
  88.             else:
  89.                 PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.LeftButton)
  90.  
  91.         elif button == GLUT_RIGHT_BUTTON:
  92.             if state == GLUT_UP:
  93.                 PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.RightButton)
  94.             else:
  95.                 PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.RightButton)
  96.  
  97.     def mouseMotionFunc(self, x, y):
  98.         PyCEGUI.System.getSingleton().injectMousePosition(x, y)
  99.  
  100.     def keyFunc(self, key, x,y):
  101.         PyCEGUI.System.getSingleton().injectChar(ord(key))
  102.  
  103.     def login(self, args):
  104.         user=self.username.getText()
  105.         if user=="":
  106.             self.noUsername.setProperty("Visible", "True")
  107.         else:
  108.             password=self.password.getText()
  109.             if password=="":
  110.                 self.noPassword.setProperty("Visible", "True")
  111.             else:
  112.                 user="'" + user + "'"
  113.  
  114.     def noUsernameOkClicked(self,args):
  115.         self.noUsername.setProperty("Visible", "False")
  116.        
  117.     def noPasswordOkClicked(self,args):
  118.         self.noPassword.setProperty("Visible", "False")
  119.  
  120. class EchoClient(protocol.Protocol):
  121.     def connectionMade(self):
  122.         self.transport.write("connected")
  123.  
  124.     def send(self, message):
  125.         self.transport.write(message)
  126.  
  127. class EchoFactory(protocol.ClientFactory):
  128.     protocol = EchoClient
  129.  
  130.     def clientConnectionFailed(self, connector, reason):
  131.         print "Connection failed - goodbye!"
  132.         reactor.stop()
  133.    
  134.     def clientConnectionLost(self, connector, reason):
  135.         print "Connection lost - goodbye!"
  136.         reactor.stop()
  137.                
  138. def twistedThread():
  139.    reactor.connectTCP("localhost",8000)
  140.    reactor.run()
  141.  
  142. def CEGUIThread():
  143.     app.run()
  144.  
  145. if __name__ == '__main__':
  146.    app=BaseApp()
  147.    reactor.callFromThread(twistedThread)
  148.    reactor.callFromThread(CEGUIThread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement