Skip to content

Commit

Permalink
add preliminary dialog system, add ability to specify window icon, ad…
Browse files Browse the repository at this point in the history
…d ability to pagejump to previous loaded page.
  • Loading branch information
ThomasTheSpaceFox committed Feb 22, 2017
1 parent c734bea commit 5dfa0d7
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DOCS/overview.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Desutezeoid Technical Documentation.
Overview:
Desutezeoid v1.2.0
Desutezeoid v1.2.1
(c) 2015-2017 Thomas Leathers


Expand Down
130 changes: 125 additions & 5 deletions DZU-ENG1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@
pygame.display.init()
pygame.font.init()
pygame.mixer.init()
print "Desutezeoid arbitrary point and click engine v1.2.0"
print "Desutezeoid arbitrary point and click engine v1.2.1"
print "parsing ENGSYSTEM.xml"
conftree = ET.parse("ENGSYSTEM.xml")
confroot = conftree.getroot()
screentag=confroot.find("screen")
uitag=confroot.find("ui")
uicolorstag=uitag.find("main")
uifgcolor=pygame.Color(uicolorstag.attrib.get("FGCOLOR", "#000000"))
uibgcolor=pygame.Color(uicolorstag.attrib.get("BGCOLOR", "#FFFFFF"))
uifgcolorstr=uicolorstag.attrib.get("FGCOLOR", "#000000")
uibgcolorstr=uicolorstag.attrib.get("BGCOLOR", "#FFFFFF")
uitextsize=int(uicolorstag.attrib.get("textsize", "24"))

uiquittag=uitag.find("quit")
uiquitmsg=uiquittag.attrib.get("MSG", "Are you sure you want to quit?")



print "populate keylist with null keyid, add any keys in initkeys."
initkeystag=confroot.find("initkeys")
keylist=list(["0"])
Expand All @@ -38,24 +51,32 @@

globalcoretag=confroot.find("globalcore")
globalforkstag=confroot.find("globalforks")
icontag=titletag.attrib.get("icon", "NULL")
if icontag!="NULL":
windowicon=pygame.image.load(icontag)
pygame.display.set_icon(windowicon)

print "config parsed."
titlebase=titletag.attrib.get("base", "Desutezeoid: ")
class clicktab:
def __init__(self, box, reftype, ref, keyid, takekey, sfxclick, sound):
def __init__(self, box, reftype, ref, keyid, takekey, sfxclick, sound, quitab=0):
self.box=box
self.ref=ref
self.keyid=keyid
self.takekey=takekey
self.reftype=reftype
self.sfxclick=sfxclick
self.sound=sound
self.quitab=quitab
class timeouttab:
def __init__(self, seconds, keyid, postkey):
self.keyid=keyid
self.regtime=time.time()
self.seconds=seconds
self.postkey=postkey



#class keyobj:
# def __init__(self, keyid):
# self=keyid
Expand All @@ -73,12 +94,64 @@ def keyprint():
screensurf=pygame.display.set_mode((scrnx, scrny))
quitflag=0
clicklist=list()
#simple dialog popup generator. used by uipop forks and the engine quit dialogs.
def qpop(qmsg, xpos, ypos, keyid="0", nokey="0", quyn=0, specialquit=0, fgcol=uifgcolor, bgcol=uibgcolor, uipoptextsize=uitextsize):
qfnt=pygame.font.SysFont(None, uipoptextsize)

qtext1=qfnt.render(qmsg, True, fgcol, bgcol)
xpos=((xpos - int(qtext1.get_width() / 2)) - 3)
qboxwidth=(6 + (qtext1.get_width()))
qboxhight=(uipoptextsize + uipoptextsize + 20)
if qboxwidth<100:
qboxwidth=100
qbox=pygame.Surface((qboxwidth, qboxhight))
qbox.fill((bgcol))
boxtrace=screensurf.blit(qbox, (xpos, ypos))
screensurf.blit(qtext1, ((xpos + 3), (ypos + 3)))
pygame.draw.rect(screensurf, fgcol, boxtrace, 3)
if quyn==1:
qytext=qfnt.render("Yes", True, bgcol, fgcol)
qntext=qfnt.render("No", True, bgcol, fgcol)
yesclick=screensurf.blit(qytext, ((xpos + 10), (ypos + 10 + uipoptextsize)))
noclick=screensurf.blit(qntext, ((xpos + 50), (ypos + 10 + uipoptextsize)))
ref="none"
takekey="0"
clicksoundflg=0
soundname=0
if specialquit==1:
yesdat=clicktab(yesclick, "quitx", ref, keyid, takekey, clicksoundflg, soundname)
nodat=clicktab(noclick, "key", ref, nokey, takekey, clicksoundflg, soundname, quitab=1)
else:
yesdat=clicktab(yesclick, "key", ref, keyid, takekey, clicksoundflg, soundname, quitab=2)
nodat=clicktab(noclick, "key", ref, nokey, takekey, clicksoundflg, soundname, quitab=2)
retclicks=([])
retclicks.extend([yesdat])
retclicks.extend([nodat])

return(retclicks, quyn)
else:
qytext=qfnt.render("Ok", True, bgcol, fgcol)
yesclick=screensurf.blit(qytext, ((xpos + 10), (ypos + 10 + uipoptextsize)))
ref="none"
takekey="0"
clicksoundflg=0
soundname=0
yesdat=clicktab(yesclick, "key", ref, keyid, takekey, clicksoundflg, soundname, quitab=2)
retclicks=([])
retclicks.extend([yesdat])
return(retclicks, quyn)




timeoutlist=list()
keybak=list(keylist)
forksanitycheck=0
forksanity=0
cachepage=prevpage
print "done. begin mainloop."
uiquit=0
qpopflg=0
while quitflag==0:
huris=0
clicklist=list()
Expand All @@ -90,6 +163,7 @@ def keyprint():

tree = ET.parse(curpage)
root = tree.getroot()
cachepage=prevpage
prevpage=curpage
coretag=root.find('core')
forktag=root.find('forks')
Expand Down Expand Up @@ -206,10 +280,37 @@ def keyprint():
masterkey=fork.attrib.get("keyid")
if masterkey in keylist:
keylist.remove(masterkey)
useprvpge=int(fork.attrib.get('useprev', '0'))
curpage=fork.attrib.get("page")
print ("iref: loading page '" + f.ref + "'")
if useprvpge==1 and cachepage!="NULL":
curpage=cachepage


print ("iref: loading page '" + curpage + "'")
pagejumpflag=1
break
for fork in forktag.findall("uipop"):
masterkey=fork.attrib.get("keyid")
msg=fork.attrib.get("msg")
qpopx=int(fork.attrib.get("x",(screensurf.get_rect().centerx)))
qpopy=int(fork.attrib.get("y",(screensurf.get_rect().centery)))
FGCOL=pygame.Color(fork.attrib.get("FGCOLOR", uifgcolorstr))
BGCOL=pygame.Color(fork.attrib.get("BGCOLOR", uibgcolorstr))
QFNTSIZE=int(fork.attrib.get("textsize", uitextsize))
if masterkey in keylist:
keylist.remove(masterkey)
ynflag=int(fork.attrib.get("ynflag", "0"))
if ynflag==1:
yeskey=fork.attrib.get("yeskey", "0")
nokey=fork.attrib.get("nokey", "0")
#poppost=qpop(msg, qpopx, qpopy, keyid=yeskey, nokey=nokey, quyn=1)
qpopdat=(msg, qpopx, qpopy, yeskey, nokey, 1, FGCOL, BGCOL, QFNTSIZE)
qpopflg=1
else:
okkey=fork.attrib.get("okkey", "0")
#poppost=qpop(msg, qpopx, qpopy, keyid=okkey, quyn=0)
qpopdat=(msg, qpopx, qpopy, okkey, "0", 0, FGCOL, BGCOL, QFNTSIZE)
qpopflg=1
for fork in forktag.findall("timeout"):
masterkey=fork.attrib.get("keyid")
if masterkey in keylist:
Expand Down Expand Up @@ -446,6 +547,17 @@ def keyprint():
clicklist.extend([datstr])
#else:
#time.sleep(0.04)
if uiquit==1:
quitxpos=screensurf.get_rect().centerx
quitypos=screensurf.get_rect().centery
poppost=qpop(uiquitmsg, quitxpos, quitypos, quyn=1, specialquit=1)
clicklist=(poppost[0])

if qpopflg==1:
poppost=qpop(qpopdat[0], qpopdat[1], qpopdat[2], keyid=(qpopdat[3]), nokey=(qpopdat[4]), quyn=(qpopdat[5]), fgcol=(qpopdat[6]), bgcol=(qpopdat[7]), uipoptextsize=(qpopdat[8]))
clicklist=(poppost[0])


if clickfields==1:
for f in clicklist:
pygame.draw.rect(screensurf, cfcolor, f.box, 1)
Expand All @@ -454,8 +566,7 @@ def keyprint():
#print "nominal"
eventhappen=1
if event.type == QUIT:
quitflag=1
print ("quit: OS or WM quit")
uiquit=1
break
if event.type==MOUSEBUTTONDOWN:
#print "nominal2"
Expand All @@ -475,14 +586,23 @@ def keyprint():
keylist.remove(f.takekey)
#print keylist
keyprint()


if f.reftype=="iref":
curpage=f.ref
print ("iref: loading page '" + f.ref + "'")
break
if f.reftype=="quit":
uiquit=1
break
if f.reftype=="quitx":
print ("quit: onclick quit")
quitflag=1
break
if f.quitab==1:
uiquit=0
if f.quitab==2:
qpopflg=0
if eventhappen==0:
time.sleep(0.1)

Expand Down
18 changes: 16 additions & 2 deletions ENGSYSTEM.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
<conf>
<!--window size-->
<screen x="800" y="600"/>
<!--Game/program Title-->
<title base="Desutezeoid v1.2.0 test program. " />
<!--Game/program Title/windown icon.-->
<title base="Desutezeoid v1.2.1 test program. " icon="icon.png" />
<!--page to load at engine start.-->
<beginref>test0.xml</beginref>
<!--debug settings. used in development and testing. printkeys controls keyid list printing.
clickfields uses cfcolor to show outlines around each click field. useful for debugging.-->
<debug debug="1" printkeys="1" clickfields="0" cfcolor="#FFFF00"/>
<!--settings for desutezeoid's internal User Interface.-->
<ui>
<main BGCOLOR="#BBCFE6" FGCOLOR="#000000" textsize="24"/>
<quit MSG="Are you sure you want to quit?"/>
</ui>
<!--keyids loaded into the keyid enviornment at startup.-->

<initkeys>
<k keyid="timeloop1"/>
<k keyid="testkey1"/>
Expand All @@ -24,6 +30,9 @@
<timeout keyid="timeloop1" seconds="0.5" post="timeloop2"/>
<timeout keyid="timeloop2" seconds="0.5" post="timeloop3"/>
<timeout keyid="timeloop3" seconds="0.5" post="timeloop1"/>
<!--The useprev attribute causes a jump to the previous page loaded.-->
<pagejump keyid="pagejumptestB" useprev="1" page="test0.xml"/>

</globalforks>
<!--these core objects are present on each page-->
<globalcore>
Expand All @@ -40,5 +49,10 @@
<con>Home</con>
<act type="iref" ref="test0.xml"/>
</label>
<label x="120" y="580" size="20" BGCOLOR="#008800" keyid="pagejumptestB" FGCOLOR="#FFFFFF" >
<con>Prev</con>
<act type="key"/>
</label>

</globalcore>
</conf>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Desutezeoid
v1.2.0
v1.2.1
an arbitrary point and click engine.
(c) 2015-2017 Thomas Leathers

Expand Down
2 changes: 1 addition & 1 deletion about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<act type="none"/>
</label>
<!--notice how the "text" object has similar attributes to the label tag, but lacking click and hover related, attribues. It still has onkey and offkey though. do note this can take longer to process than other core objects.-->
<text x="10" y="30" size="20" transp="1" FGCOLOR="#000000">v1.2.0
<text x="10" y="30" size="20" transp="1" FGCOLOR="#000000">v1.2.1
an arbitrary point and click engine.
(c) 2015-2017 Thomas Leathers

Expand Down
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions test0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
<k if="1" keyid="switch1"/>
<k if="1" keyid="switch2"/>
</ortrig>
<!--These generate normal and yes/no dialogs respectively. both modes have appropiate selection
keyid attributes. to use yes/no mode, set ynflag="1", and use yesflag and noflag for respective
"post" keyids, in normal mode, use the "okkey" attribute. these use the internal engine ui
parameters, you can specifiy ui parameters like colors and text size in the "ui" section of ENGSYSTEM.xml
Special note: only one uipop dialog can be active at any one time!-->
<uipop keyid="uidialog1" msg="Hello, this is a normal dialog." okkey="normaldialogok"/>
<!--now lets use some custom visual parameters! :D-->
<uipop keyid="uidialog3" msg="This Dialog is red." BGCOLOR="#AA0000" FGCOLOR="#FFFFFF" />
<!--HUGE text :) -->
<uipop keyid="uidialog4" msg="This Dialog is BIG." BGCOLOR="#00AA00" FGCOLOR="#FFFFFF" textsize="70" />
<!--yes/no dialog-->
<uipop keyid="uidialog2" msg="Hello, this is a yes or no dialog." ynflag="1" nokey="nokeyyndiag" yeskey="yeskeyyndiag" />
<!--notice how this trigger lock triggers a sound event. note how the
lock keyid prevents the trigger keyid from re-triggering, thus the sound
triggered by the two toggle switches being on plays only once, and only the
Expand Down Expand Up @@ -88,6 +101,25 @@ The timeout instance is also removed after the specified time lapses. also if th
<con>timer (click me!)</con>
<act type="key" ref="test1.xml"/>
</label>

<label x="0" y="400" size="24" BGCOLOR="#000088" FGCOLOR="#FFFFFF" keyid="uidialog1">
<con>test normal dialog</con>
<act type="key" ref="test1.xml"/>
</label>
<label x="0" y="455" size="24" BGCOLOR="#000088" FGCOLOR="#FFFFFF" keyid="uidialog3">
<con>test colorized dialog</con>
<act type="key" ref="test1.xml"/>
</label>
<label x="0" y="475" size="24" BGCOLOR="#000088" FGCOLOR="#FFFFFF" keyid="uidialog4">
<con>test custom text size dialog</con>
<act type="key" ref="test1.xml"/>
</label>

<label x="0" y="430" size="24" BGCOLOR="#000088" FGCOLOR="#FFFFFF" keyid="uidialog2">
<con>test yes/no dialog</con>
<act type="key" ref="test1.xml"/>
</label>

<!--take note how these toggle switches work.
see how, in each toggle switch, the "keyid" and "offkey" atributes in the "(off)" labels
and the "takekey" and "onkey" in the "(on)" labels all have the same keyid.
Expand Down
6 changes: 6 additions & 0 deletions test1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
such as in a page that acts as a story sequence for example, you would have the
last timeout in the sequence trigger one of these.-->
<pagejump keyid="pagejumptest" page="test0.xml"/>
<pagejump keyid="pagejumptestB" useprev="1" page="test0.xml"/>

</forks>
<core>
<label x="0" y="400" size="40">
Expand All @@ -25,6 +27,10 @@ last timeout in the sequence trigger one of these.-->
<con>test pagejump.</con>
<act type="key"/>
</label>
<label x="0" y="340" size="24" keyid="pagejumptestB">
<con>test pagejump prevpage feature</con>
<act type="key"/>
</label>
<label x="0" y="300" size="24" onkey="pagejumpdelay">
<con>starting booster rockets...</con>
<act type="none"/>
Expand Down

0 comments on commit 5dfa0d7

Please sign in to comment.