*** empty log message ***

This commit is contained in:
Mike Goslin 2000-11-30 02:42:38 +00:00
parent be485738fa
commit 1e4f7df0ae
2 changed files with 217 additions and 202 deletions

View File

@ -1,201 +1,203 @@
from ShowBaseGlobal import * from ShowBaseGlobal import *
import PandaObject import PandaObject
import Frame import Frame
import GuiFrame import GuiFrame
import Button import Button
import GuiLabel import GuiLabel
import Sign import Sign
font = (loader.loadModelOnce("phase_3/models/fonts/ttf-comic")).node() font = (loader.loadModelOnce("phase_3/models/fonts/ttf-comic")).node()
class ScrollingLabel(PandaObject.PandaObject): class ScrollingLabel(PandaObject.PandaObject):
# special methods # special methods
def __init__(self, name, itemList): def __init__(self, name, itemList):
self.name = name self.name = name
self.eventName = self.name self.eventName = self.name
self.frame = Frame.Frame(name) self.frame = Frame.Frame(name)
self.frame.setOffset(0.015) self.frame.setOffset(0.015)
self.item = 0 self.item = 0
self.items = [] self.items = []
self.keyFocus = 1 self.keyFocus = 1
# create the new title # create the new title
label = GuiLabel.GuiLabel.makeSimpleTextLabel(self.name, font) label = GuiLabel.GuiLabel.makeSimpleTextLabel(self.name, font)
label.setForegroundColor(1., 0., 0., 1.) label.setForegroundColor(1., 0., 0., 1.)
label.setBackgroundColor(1., 1., 1., 0.) label.setBackgroundColor(1., 1., 1., 0.)
self.title = Sign.Sign(self.name, label) self.title = Sign.Sign(self.name, label)
self.frame.addItem(self.title) self.frame.addItem(self.title)
# create a sign for each item in itemList # create a sign for each item in itemList
for item in itemList: for item in itemList:
thisLabel = GuiLabel.GuiLabel.makeSimpleTextLabel(item, font) thisLabel = GuiLabel.GuiLabel.makeSimpleTextLabel(item, font)
thisLabel.setForegroundColor(0., 0., 0., 1.) thisLabel.setForegroundColor(0., 0., 0., 1.)
thisLabel.setBackgroundColor(1., 1., 1., 1.) thisLabel.setBackgroundColor(1., 1., 1., 1.)
thisSign = Sign.Sign(item, thisLabel) thisSign = Sign.Sign(item, thisLabel)
self.items.append(thisSign) self.items.append(thisSign)
# add each item temporarily # add each item temporarily
self.frame.addItem(thisSign) self.frame.addItem(thisSign)
# make all labels the same width # make all labels the same width
self.frame.makeWideAsWidest() self.frame.makeWideAsWidest()
# remove all labels except the first # remove all labels except the first
for itemNum in range(1, len(self.items)): for itemNum in range(1, len(self.items)):
self.frame.removeItem(self.items[itemNum]) self.frame.removeItem(self.items[itemNum])
# pack the first label under the name # pack the first label under the name
self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.UNDER, self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.UNDER,
self.title) self.title)
self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.ALIGNLEFT, self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.ALIGNLEFT,
self.title) self.title)
# create the scroll buttons # create the scroll buttons
self.leftButton = Button.Button(self.name + "-left", " < ") self.leftButton = Button.Button(self.name + "-left", " < ")
self.leftButton.getGuiItem().setDownRolloverEvent(self.name + "-left") self.leftButton.getGuiItem().setDownRolloverEvent(self.name + "-left")
self.frame.addItem(self.leftButton) self.leftButton.getGuiItem().setUpRolloverEvent(self.name + "-rollover")
self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.UNDER, self.frame.addItem(self.leftButton)
self.title) self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.UNDER,
self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.LEFT, self.title)
self.title) self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.LEFT,
self.rightButton = Button.Button(self.name + "-right", " > ") self.title)
self.rightButton.getGuiItem().setDownRolloverEvent(self.name + self.rightButton = Button.Button(self.name + "-right", " > ")
"-right") self.rightButton.getGuiItem().setDownRolloverEvent(self.name +
self.frame.addItem(self.rightButton) "-right")
self.frame.packItem(self.rightButton, GuiFrame.GuiFrame.UNDER, self.rightButton.getGuiItem().setUpRolloverEvent(self.name + "-rollover")
self.title) self.frame.addItem(self.rightButton)
self.frame.packItem(self.rightButton, GuiFrame.GuiFrame.RIGHT, self.frame.packItem(self.rightButton, GuiFrame.GuiFrame.UNDER,
self.title) self.title)
self.frame.packItem(self.rightButton, GuiFrame.GuiFrame.RIGHT,
# listen for the scroll buttons self.title)
self.accept(self.name + "-left", self.handleLeftButton)
self.accept(self.name + "-right", self.handleRightButton) # listen for the scroll buttons
# listen for keyboard hits self.accept(self.name + "-left", self.handleLeftButton)
self.setKeyFocus(1) self.accept(self.name + "-right", self.handleRightButton)
# listen for keyboard hits
# refresh the frame self.setKeyFocus(1)
self.frame.recompute()
# refresh the frame
self.frame.recompute()
def cleanup(self):
# remove gui items
del(self.frame) def cleanup(self):
for item in self.items: # remove gui items
del(item) del(self.frame)
for item in self.items:
# ignore events del(item)
self.ignore(self.name + "-left")
self.ignore(self.name + "-right") # ignore events
self.setKeyFocus(0) self.ignore(self.name + "-left")
self.ignore(self.name + "-right")
# accessing self.setKeyFocus(0)
def getTitle(self):
return self.name # accessing
def getTitle(self):
def setTitle(self, name): return self.name
self.name = name
self.title.setText(name) def setTitle(self, name):
self.frame.recompute() self.name = name
self.title.setText(name)
def getItem(self): self.frame.recompute()
return self.items[self.item]
def getItem(self):
def setItem(self, item): return self.items[self.item]
self.frame.removeItem(self.items[self.item])
self.item = item def setItem(self, item):
self.addItem() self.frame.removeItem(self.items[self.item])
self.item = item
def getEventName(self): self.addItem()
return self.eventName
def getEventName(self):
def setEventName(self, eventName): return self.eventName
self.eventName = eventName
def setEventName(self, eventName):
def setPos(self, x, y): self.eventName = eventName
self.frame.setPos(x, y)
self.frame.recompute() def setPos(self, x, y):
self.frame.setPos(x, y)
def setScale(self, scale): self.frame.recompute()
self.frame.setScale(scale)
self.frame.recompute() def setScale(self, scale):
self.frame.setScale(scale)
def getKeyFocus(self): self.frame.recompute()
return self.keyFocus
def getKeyFocus(self):
def setKeyFocus(self, focus): return self.keyFocus
self.keyFocus = focus
if (focus == 1): def setKeyFocus(self, focus):
# listen for keyboard hits self.keyFocus = focus
self.accept("left-up", self.handleLeftArrow) if (focus == 1):
self.accept("right-up", self.handleRightArrow) # listen for keyboard hits
else: self.accept("left-up", self.handleLeftArrow)
# ignore keyboard hits self.accept("right-up", self.handleRightArrow)
self.ignore("left-up") else:
self.ignore("right-up") # ignore keyboard hits
self.ignore("left-up")
# actions self.ignore("right-up")
def recompute(self):
self.frame.recompute() # actions
def recompute(self):
def manage(self): self.frame.recompute()
self.frame.manage()
def manage(self):
def unmanage(self): self.frame.manage()
self.frame.unmanage()
def unmanage(self):
def handleLeftButton(self): self.frame.unmanage()
# update the current item and the scroll label
self.frame.removeItem(self.items[self.item]) def handleLeftButton(self):
self.item = self.item - 1 # update the current item and the scroll label
if (self.item < 0): self.frame.removeItem(self.items[self.item])
self.item = len(self.items) - 1 self.item = self.item - 1
self.addItem() if (self.item < 0):
self.item = len(self.items) - 1
def handleRightButton(self): self.addItem()
# update the current item and the scroll label
self.frame.removeItem(self.items[self.item]) def handleRightButton(self):
self.item = self.item + 1 # update the current item and the scroll label
if (self.item >= len(self.items)): self.frame.removeItem(self.items[self.item])
self.item = 0 self.item = self.item + 1
self.addItem() if (self.item >= len(self.items)):
self.item = 0
def handleLeftArrow(self): self.addItem()
# make the button toggle
self.leftButton.getGuiItem().down() def handleLeftArrow(self):
self.spawnButtonUpTask(self.leftButton) # make the button toggle
# then act like a mouse click self.leftButton.getGuiItem().down()
self.handleLeftButton() self.spawnButtonUpTask(self.leftButton)
# then act like a mouse click
def handleRightArrow(self): self.handleLeftButton()
# make the button toggle
self.rightButton.getGuiItem().down() def handleRightArrow(self):
self.spawnButtonUpTask(self.rightButton) # make the button toggle
# then act like a mouse click self.rightButton.getGuiItem().down()
self.handleRightButton() self.spawnButtonUpTask(self.rightButton)
# then act like a mouse click
def spawnButtonUpTask(self, button): self.handleRightButton()
def buttonUp(state):
state.button.getGuiItem().up() def spawnButtonUpTask(self, button):
return Task.done def buttonUp(state):
task = Task.Task(buttonUp) state.button.getGuiItem().up()
task.button = button return Task.done
taskMgr.spawnTaskNamed(Task.doLater(.035, task, "buttonUp-later"), task = Task.Task(buttonUp)
"doLater-buttonUp-later") task.button = button
taskMgr.spawnTaskNamed(Task.doLater(.035, task, "buttonUp-later"),
def addItem(self): "doLater-buttonUp-later")
self.frame.addItem(self.items[self.item])
self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.UNDER, def addItem(self):
self.title) self.frame.addItem(self.items[self.item])
self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.ALIGNLEFT, self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.UNDER,
self.title) self.title)
self.items[self.item].manage() self.frame.packItem(self.items[self.item], GuiFrame.GuiFrame.ALIGNLEFT,
self.frame.recompute() self.title)
messenger.send(self.eventName, [self.item]) self.items[self.item].manage()
self.frame.recompute()
messenger.send(self.eventName, [self.item])

View File

@ -32,7 +32,7 @@ class Loader:
else: else:
nodePath = None nodePath = None
return nodePath return nodePath
def loadModelOnce(self, modelPath): def loadModelOnce(self, modelPath):
"""loadModelOnce(self, string) """loadModelOnce(self, string)
Attempt to load a model from modelPool, if not present Attempt to load a model from modelPool, if not present
@ -58,6 +58,11 @@ class Loader:
return (nodePath.copyTo(self.__base.hidden)) return (nodePath.copyTo(self.__base.hidden))
else: else:
return None return None
def unloadModel(self, modelPath):
"""unloadModel(self, string)
Loader.notify.info("Unloading model: %s" % (modelPath))
ModelPool.releaseModel(modelPath)
# texture loading funcs # texture loading funcs
def loadTexture(self, texturePath): def loadTexture(self, texturePath):
@ -68,6 +73,10 @@ class Loader:
texture = TexturePool.loadTexture(texturePath) texture = TexturePool.loadTexture(texturePath)
return texture return texture
def unloadTexture(self, texture):
"""unloadTexture(self, texture)
TexturePool.releaseTexture(texture)
# sound loading funcs # sound loading funcs
def loadSound(self, soundPath): def loadSound(self, soundPath):
"""loadSound(self, string) """loadSound(self, string)
@ -77,6 +86,10 @@ class Loader:
sound = AudioPool.loadSound(soundPath) sound = AudioPool.loadSound(soundPath)
return sound return sound
def unloadSound(self, sound):
"""unloadSound(self, sound)
AudioPool.releaseSound(sound)