Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Preliminary fixes for xJournalBookGUIPopup
Browse files Browse the repository at this point in the history
This begins an attempt to move game data out of the python scripts.
In this case, it allows official and fan Ages to use loc paths
directly instead of a reference to a key in xJournalBookDefs in
their PythonFileMod usage of this global script.
  • Loading branch information
Deledrius committed Feb 1, 2013
1 parent 91506ef commit a1bbc30
Showing 1 changed file with 61 additions and 56 deletions.
117 changes: 61 additions & 56 deletions Python/xJournalBookGUIPopup.py
Expand Up @@ -61,24 +61,27 @@
from Plasma import *
from PlasmaTypes import *
from PlasmaKITypes import *
import string

import codecs

import xJournalBookDefs


# define the attributes that will be entered in max
actClickableBook = ptAttribActivator(1,"Actvtr: Clickable small book")
SeekBehavior = ptAttribBehavior(2, "Smart seek before GUI (optional)")
JournalName = ptAttribString(3, "Name of Journal", "")
StartOpen = ptAttribBoolean(10,"Start Opened?",default=0)
JournalName = ptAttribString(3, "Name of Journal (deprecated)", "") # Phasing this out; we don't want to use global Python for data.
Dynamic = ptAttribBoolean(4,"Read Data From Vault?",default=0)
StartOpen = ptAttribBoolean(10,"Start Opened?",default=0)

BookWidth = ptAttribFloat(11,"Book Width Scaling",default=1.0)
BookHeight = ptAttribFloat(12,"Book Height Scaling",default=1.0)
LocPath = ptAttribString(13,"Localization Path for Journal Contents",default="Global.Journals.Empty")
GUIType = ptAttribString(14,"Book GUI Type",default="bkBook")

# globals
LocalAvatar = None

# the global ptBook object.... there can only be one book displayed at one time, so only one global needed (hopefully)
gJournalBook = None

class xJournalBookGUIPopup(ptModifier):
"The Journal Book GUI Popup python code"
def __init__(self):
Expand All @@ -93,7 +96,7 @@ def __del__(self):
"destructor - get rid of any dialogs that we might have loaded"
pass

def OnNotify(self,state,id,events):
def OnNotify(self, state, id, events):
global LocalAvatar

# is it a clickable book on a pedestal?
Expand Down Expand Up @@ -142,67 +145,69 @@ def OnNotify(self,state,id,events):
pass

def IShowBook(self):
global gJournalBook
self.JournalBook = None

# This lookup should be removed once all PFMs are converted to specify their details
if JournalName.value != "":
PtDebugPrint("xJournalBookGUIPopup: deprecated journal format, using name '%s'" % (JournalName.value), level=kErrorLevel)
try:
params = xJournalBookDefs.xJournalBooks[JournalName.value]
JournalIdent = JournalName.value
if len(params) == 4:
width,height,locPath,gui = params
BookWidth.value,BookHeight.value,LocPath.value,GUIType.value = params
else:
width,height,locPath = params
gui = "BkBook"
BookWidth.value,BookHeight.value,LocPath.value = params
except LookupError:
PtDebugPrint("xJournalBookGUIPopup: could not find journal %s's contents" % (JournalName.value),level=kErrorLevel)
PtDebugPrint("xJournalBookGUIPopup: could not find journal parameters for '%s'" % (JournalName.value), level=kErrorLevel)
return
else:
JournalIdent = LocPath.value

# compile journal text
if Dynamic.value:
inbox = ptVault().getGlobalInbox()
inboxChildList = inbox.getChildNodeRefList()
for child in inboxChildList:
PtDebugPrint("xJournalBookGUIPopupDyn: looking at node " + str(child), level=kDebugDumpLevel)
node = child.getChild()
folderNode = node.upcastToFolderNode()
if folderNode:
PtDebugPrint("xJournalBookGUIPopupDyn: node is named %s" % (folderNode.getFolderName()), level=kDebugDumpLevel)
if folderNode.getFolderName() == "Journals":
folderNodeChildList = folderNode.getChildNodeRefList()
for folderChild in folderNodeChildList:
PtDebugPrint("xJournalBookGUIPopupDyn: looking at child node " + str(folderChild), level=kDebugDumpLevel)
childNode = folderChild.getChild()
textNode = childNode.upcastToTextNoteNode()
if textNode:
PtDebugPrint("xJournalBookGUIPopupDyn: child node is named %s" % (textNode.getTitle()), level=kDebugDumpLevel)
# TODO: Convert this to use LocPath.value and migrate node values in DB if necessary once all PFMs
# are converted to use LocalizationPaths
if textNode.getTitle() == JournalIdent:
journalContents = textNode.getText()
PtDebugPrint("xJournalBookGUIPopupDyn: journal contents are '%s'" % (journalContents), level=kDebugDumpLevel)
else:
journalContents = PtGetLocalizedString(LocPath.value)

if journalContents == U"":
PtDebugPrint(U"WARNING - EMPTY JOURNAL: JournalName.value = '{}' LocPath = '{}'".format(codecs.decode(JournalName.value, 'utf-8'), codecs.decode(LocPath.value, 'utf-8')), level=kDebugDumpLevel)

journalContents = "I'm an empty book"

# compile journal text
if Dynamic.value:
inbox = ptVault().getGlobalInbox()
inboxChildList = inbox.getChildNodeRefList()
for child in inboxChildList:
PtDebugPrint("xJournalBookGUIPopupDyn: looking at node " + str(child),level=kDebugDumpLevel)
node = child.getChild()
folderNode = node.upcastToFolderNode()
if type(folderNode) != type(None):
PtDebugPrint("xJournalBookGUIPopupDyn: node is named %s" % (folderNode.getFolderName()),level=kDebugDumpLevel)
if folderNode.getFolderName() == "Journals":
folderNodeChildList = folderNode.getChildNodeRefList()
for folderChild in folderNodeChildList:
PtDebugPrint("xJournalBookGUIPopupDyn: looking at child node " + str(folderChild),level=kDebugDumpLevel)
childNode = folderChild.getChild()
textNode = childNode.upcastToTextNoteNode()
if type(textNode) != type(None):
PtDebugPrint("xJournalBookGUIPopupDyn: child node is named %s" % (textNode.getTitle()),level=kDebugDumpLevel)
if textNode.getTitle() == JournalName.value:
journalContents = textNode.getText()
PtDebugPrint("xJournalBookGUIPopupDyn: journal contents are '%s'" % (journalContents),level=kDebugDumpLevel)
else:
journalContents = PtGetLocalizedString(locPath)

if journalContents == U"":
print U"WARNING - EMPTY JOURNAL: JournalName.value = " + JournalName.value + U" locPath = " + locPath

# hide the KI
PtSendKIMessage(kDisableKIandBB,0)

# now build the book
gJournalBook = ptBook(journalContents,self.key)
gJournalBook.setSize(width,height)
gJournalBook.setGUI(gui)

# make sure there is a cover to show
if not StartOpen.value and not self.IsThereACover(journalContents):
gJournalBook.show(1)
else:
gJournalBook.show(StartOpen.value)
# hide the KI
PtSendKIMessage(kDisableKIandBB, 0)

# now build the book
self.JournalBook = ptBook(journalContents, self.key)
self.JournalBook.setSize(BookWidth.value, BookHeight.value)
self.JournalBook.setGUI(GUIType.value)

# make sure there is a cover to show
if not StartOpen.value and not self.IsThereACover(journalContents):
self.JournalBook.show(1)
else:
PtDebugPrint("xJournalBookGUIPopup: no journal name",level=kErrorLevel)
self.JournalBook.show(StartOpen.value)


def IsThereACover(self,bookHtml):
def IsThereACover(self, bookHtml):
# search the bookhtml string looking for a cover
idx = bookHtml.find('<cover')
if idx >= 0:
Expand Down

0 comments on commit a1bbc30

Please sign in to comment.