Hi!
I have been trying to use DirectEntry in our game so players can enter their username and password before starting the game. I am doing this on a MacBook running osx v.10.4.8.
The frame displays no problem but when I try to input text nothing happens. I have seen another posting from someone with the same problem but no replies.
Does anybody know how to fix this??? (code follows- see ‘def loginScreen’)
Help will be greatly appreciated! Thanks
from pandac.PandaModules import loadPrcFileData #Modifies/adds the .prc (Panda3D's configuration file)
#loadPrcFileData("", "client-sleep 0.03")
#loadPrcFileData("", "interpolate-frames 1")
#encoding: UTF-8
import direct.directbase.DirectStart #starts the Game (opens an empty window)
from pandac.PandaModules import * #Contains most of Panda's modules
from pandac.PandaModules import Material
from direct.gui.DirectGui import * #Imports Gui objects we use for putting text ont the screen
from direct.showbase.DirectObject import DirectObject #to listen for events
from direct.showbase.ShowBaseGlobal import *
from direct.actor.Actor import Actor #to use animated actors
from direct.interval.IntervalGlobal import * #to use intervals
from direct.task import Task #to use tasks
from direct.distributed.PyDatagram import PyDatagram #to send data to server
from direct.distributed.PyDatagramIterator import PyDatagramIterator
import math #to use math (angles,degrees..etc)
import random
import re
import MySQLdb
import socket
from md5 import md5
#load first environment model
import sys, os
# Function to put instructions on the screen.
def addInstructions(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)
# Function to put title on the screen.
def addTitle(text):
return OnscreenText(text=text, style=1, fg=(1,1,1,1),
pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
#Find out what dir this program is in
AppPath = os.path.abspath(sys.path[0])
AppPath = Filename.fromOsSpecific(AppPath).getFullpath()
#print AppPath
curposindex =[]
class World(DirectObject): #our main class
def __init__(self): #iniialization method caused when a world object is created
# Post instructions on screen
self.title = addTitle("Psychology Dept. Glasgow")
self.inst1 = addInstructions(0.95, "[ESC]: Quit")
self.inst2 = addInstructions(0.90, "[Left Arrow]: Turn camera left")
self.inst3 = addInstructions(0.85, "[Right Arrow]: Turn camera right")
self.inst4 = addInstructions(0.75, "[O]: Move camera forwards")
self.inst5 = addInstructions(0.70, "[L]: Move camera backwards")
#make background color black (R=0, B=0, G=0) intead of default grey
base.setBackgroundColor(0, 0, 1)
base.disableMouse()
self.speed = .10 # Controls speed of rotation and zoom.
self.curposindex = curposindex
#we call loadObjects which handles getting our objects in the world
## TO DO::: Here: If the player is 'player1' self.loadObjects() but if it is 'player2' load .dat file with only the objects left by player1!!!!!
#self.loadObjects()
self.setupLighting()
# Setup key controls
# To Do: Implement zoom in & out + collision
self.accept("escape", sys.exit)
self.accept("arrow_right", self.rotate,[1])
self.accept("arrow_left", self.rotate,[-1])
self.accept("o", self.cameraFocus,[-1])
self.accept("l", self.cameraFocus,[1])
self.accept("arrow_up", self.walk, [-1])
self.accept("arrow_down", self.walk, [1])
#set the camera position (x, y, z)
base.camera.setPosHpr(Vec3(-60,-60, -3),Vec3(-30,-5,0)) #(Y,X,Z)manipulating 'z' you can go up/down, 'y' in and out of the pic, 'x' + goes left and '-' goes right & 'y' goes up and down
#set the camera orientation (heading(yaw), pitch, roll) in degrees
#set Field of View to be wider as our room is quite reduced in size
base.camLens.setFov(90)
#base.camLens.setFar(100000) #this line of code doesn't seem to do anything
###new code to deal with server/client
# self.blocksize = 16 #don't know if we'll need this
self.playerlist = {}
self.moverlist = set([])
self.connected = False
self.loggedIn = False
self.sendPlayerPos = False
self.wbUpdate = True
print "before trying server connection"
#Try connecting to server
try:
self.initNetwork()
print "connection to server established"
except:
print "no server found"
sys.exit()
#end __init__
#def self.loadGui(self):
def loadGui(self):
#load the GUI!
pass
def loginScreen(self):
self.frame = DirectFrame(frameColor=(1,0,1,1), frameSize=(-1,1,0,1))
self.unEntry = DirectEntry(initialText="Username",
scale=0.08,
text_scale=(1,1),
pos=(-.7,0,.7))
self.unEntry.reparentTo(self.frame)
self.pwEntry = DirectEntry(initialText="Password",
scale=0.08,text_scale=(1,1),
pos=(-.7,0,.55),obscured=1)
self.pwEntry.reparentTo(self.frame)
self.loginbutton = DirectButton(text = "Login",
pos=(0.26,0,.7),
scale=0.08,
command=self.login)
self.loginbutton.reparentTo(self.frame)
self.regbutton = DirectButton(text = "register",
pos=(0.26,0,.57),
scale=0.08,
command=self.registeracc)
self.regbutton.reparentTo(self.frame)