Skip to content

Commit

Permalink
add image support to uipop fork. add new uimenu fork. make quit dialo…
Browse files Browse the repository at this point in the history
…g show over normal uipop and uimenu forks.
  • Loading branch information
ThomasTheSpaceFox committed Feb 23, 2017
1 parent 5dfa0d7 commit 0898a16
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 32 deletions.
4 changes: 3 additions & 1 deletion DOCS/overview.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Desutezeoid Technical Documentation.
Overview:
Desutezeoid v1.2.1
Desutezeoid v1.2.2
(c) 2015-2017 Thomas Leathers


-Desutezeoid is an arbitrary point and click engine written in python and pygame. It is designed to be driven using a series of xml files. Each "screen" is an xml file.

-The engine uses a boolean "keyid" and "forking" scripting structure that is parsed each code cycle.



/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
programmer note: see comments in included example xml pages. especially "test0.xml"
this documentation is not exactly done yet.
Expand Down
131 changes: 116 additions & 15 deletions DZU-ENG1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
pygame.display.init()
pygame.font.init()
pygame.mixer.init()
print "Desutezeoid arbitrary point and click engine v1.2.1"
print "Desutezeoid arbitrary point and click engine v1.2.2"
print "parsing ENGSYSTEM.xml"
conftree = ET.parse("ENGSYSTEM.xml")
confroot = conftree.getroot()
Expand Down Expand Up @@ -75,6 +75,15 @@ def __init__(self, seconds, keyid, postkey):
self.seconds=seconds
self.postkey=postkey

class uimenutab:
def __init__(self, con, keyid, stay=0, noact=0, surfrender=None):
self.keyid=keyid
self.con=con
self.surfrender=surfrender
self.stay=stay
self.noact=noact




#class keyobj:
Expand All @@ -94,26 +103,93 @@ 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):

#menu dialog function
def qmenu(xpos, ypos, itemlist, fgcol=uifgcolor, bgcol=uibgcolor, uipoptextsize=uitextsize):
qfnt=pygame.font.SysFont(None, uipoptextsize)
texty=3
textx=100
itemlistB=list()
for itm in itemlist:
texty += uipoptextsize
if itm.noact==1:
qtext1=qfnt.render(itm.con, True, fgcol, bgcol)
else:
qtext1=qfnt.render(itm.con, True, bgcol, fgcol)
#print itm.con
itmB=uimenutab(itm.con, itm.keyid, itm.stay, itm.noact, qtext1)
if (qtext1.get_width())>textx:
textx=qtext1.get_width()
itemlistB.extend([itmB])

xpos=((xpos - int(textx / 2)) - 3)
ypos=((ypos - int(texty / 2)) - 3)
qboxwidth=(6 + textx)
qboxhight=(texty + 20)
if qboxwidth<100:
qboxwidth=100
qbox=pygame.Surface((qboxwidth, qboxhight))
qbox.fill((bgcol))
boxtrace=screensurf.blit(qbox, (xpos, ypos))


texreny=(ypos + 3)
texrenx=(xpos + 3)
retlist=list()
for itm in itemlistB:
itmclick=screensurf.blit(itm.surfrender, (texrenx, (texreny)))
texreny += uipoptextsize
if itm.noact==0:
if itm.stay==0:
itmclicktab=clicktab(itmclick, "key", "none", itm.keyid, "0", 0, "none", quitab=3)
else:
itmclicktab=clicktab(itmclick, "key", "none", itm.keyid, "0", 0, "none")
retlist.extend([itmclicktab])
#screensurf.blit(qtext1, ((xpos + 3), (ypos + 3)))
pygame.draw.rect(screensurf, fgcol, boxtrace, 3)
return(retlist)




#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, img="none"):
qfnt=pygame.font.SysFont(None, uipoptextsize)
if img!="none":
qimg=pygame.image.load(img)
qimgflg=1
qimgy=qimg.get_height()
qimgx=qimg.get_width()
else:
qimgflg=0
qimgy=0
qimgx=0
prevxpos=xpos
qtext1=qfnt.render(qmsg, True, fgcol, bgcol)
xpos=((xpos - int(qtext1.get_width() / 2)) - 3)
if qimgflg==1:
#if image is present, center ypos on image
ypos=((ypos - int(qimgy / 2)))
qboxwidth=(6 + (qtext1.get_width()))
qboxhight=(uipoptextsize + uipoptextsize + 20)
qboxhight=(uipoptextsize + qimgy + uipoptextsize + 20)
if qboxwidth<100:
qboxwidth=100
if qboxwidth<qimgx:
qboxwidth=(qimgx + 6)
#if image is wider than text, center xpos on image
xpos=((prevxpos - int(qimgx / 2)) - 3)
qbox=pygame.Surface((qboxwidth, qboxhight))
qbox.fill((bgcol))
boxtrace=screensurf.blit(qbox, (xpos, ypos))
screensurf.blit(qtext1, ((xpos + 3), (ypos + 3)))
if qimgflg==1:
screensurf.blit(qimg, ((xpos + 3), (ypos + 3)))
screensurf.blit(qtext1, ((xpos + 3), (ypos + qimgy + 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)))
yesclick=screensurf.blit(qytext, ((xpos + 10), (ypos + qimgy + 10 + uipoptextsize)))
noclick=screensurf.blit(qntext, ((xpos + 50), (ypos + qimgy + 10 + uipoptextsize)))
ref="none"
takekey="0"
clicksoundflg=0
Expand All @@ -131,7 +207,7 @@ def qpop(qmsg, xpos, ypos, keyid="0", nokey="0", quyn=0, specialquit=0, fgcol=ui
return(retclicks, quyn)
else:
qytext=qfnt.render("Ok", True, bgcol, fgcol)
yesclick=screensurf.blit(qytext, ((xpos + 10), (ypos + 10 + uipoptextsize)))
yesclick=screensurf.blit(qytext, ((xpos + 10), (ypos + qimgy + 10 + uipoptextsize)))
ref="none"
takekey="0"
clicksoundflg=0
Expand All @@ -152,6 +228,7 @@ def qpop(qmsg, xpos, ypos, keyid="0", nokey="0", quyn=0, specialquit=0, fgcol=ui
print "done. begin mainloop."
uiquit=0
qpopflg=0
qmenuflg=0
while quitflag==0:
huris=0
clicklist=list()
Expand Down Expand Up @@ -297,20 +374,38 @@ def qpop(qmsg, xpos, ypos, keyid="0", nokey="0", quyn=0, specialquit=0, fgcol=ui
FGCOL=pygame.Color(fork.attrib.get("FGCOLOR", uifgcolorstr))
BGCOL=pygame.Color(fork.attrib.get("BGCOLOR", uibgcolorstr))
QFNTSIZE=int(fork.attrib.get("textsize", uitextsize))
uiimg=fork.attrib.get("img", "none")

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)
qpopdat=(msg, qpopx, qpopy, yeskey, nokey, 1, FGCOL, BGCOL, QFNTSIZE, uiimg)
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)
qpopdat=(msg, qpopx, qpopy, okkey, "0", 0, FGCOL, BGCOL, QFNTSIZE, uiimg)
qpopflg=1

for fork in forktag.findall("uimenu"):
masterkey=fork.attrib.get("keyid")
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)
itemlist=list()
for itmf in fork.findall("item"):
itmftab=uimenutab(itmf.attrib.get("con"), itmf.attrib.get("keyid", "0"), stay=int(itmf.attrib.get("stay", "0")), noact=int(itmf.attrib.get("noact", "0")))
itemlist.extend([itmftab])
qmenudat=(qpopx, qpopy, itemlist, FGCOL, BGCOL, QFNTSIZE)
qmenuflg=1
for fork in forktag.findall("timeout"):
masterkey=fork.attrib.get("keyid")
if masterkey in keylist:
Expand Down Expand Up @@ -547,17 +642,21 @@ def qpop(qmsg, xpos, ypos, keyid="0", nokey="0", quyn=0, specialquit=0, fgcol=ui
clicklist.extend([datstr])
#else:
#time.sleep(0.04)

if qmenuflg==1:
#qmenudat=(qpopx, qpopy, itemlist, FGCOL, BGCOL, QFNTSIZE)
menpost=qmenu(qmenudat[0], qmenudat[1], qmenudat[2], fgcol=qmenudat[3], bgcol=qmenudat[4], uipoptextsize=qmenudat[5])
#qmenu(
clicklist=(menpost)
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]), img=(qpopdat[9]))
clicklist=(poppost[0])
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 Down Expand Up @@ -603,6 +702,8 @@ def qpop(qmsg, xpos, ypos, keyid="0", nokey="0", quyn=0, specialquit=0, fgcol=ui
uiquit=0
if f.quitab==2:
qpopflg=0
if f.quitab==3:
qmenuflg=0
if eventhappen==0:
time.sleep(0.1)

Expand Down
5 changes: 4 additions & 1 deletion ENGSYSTEM.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--window size-->
<screen x="800" y="600"/>
<!--Game/program Title/windown icon.-->
<title base="Desutezeoid v1.2.1 test program. " icon="icon.png" />
<title base="Desutezeoid v1.2.2 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.
Expand All @@ -19,6 +19,7 @@
<initkeys>
<k keyid="timeloop1"/>
<k keyid="testkey1"/>
<k keyid="welcome"/>
</initkeys>

<!--Explanation of "globalforks" and "globalcore": these corrispond to the "forks" and "core" sections of page xml files. these are populated into corresponding areas of the page structure in memory. This is why "forks" and "core objects" here act as if they are in every page's xml file.-->
Expand All @@ -32,6 +33,8 @@
<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"/>
<uipop keyid="welcome" msg="Welcome to the Desutezeoid test program!"/>


</globalforks>
<!--these core objects are present on each page-->
Expand Down
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.1
v1.2.2
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.1
<text x="10" y="30" size="20" transp="1" FGCOLOR="#000000">v1.2.2
an arbitrary point and click engine.
(c) 2015-2017 Thomas Leathers

Expand Down
43 changes: 30 additions & 13 deletions test0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,34 @@
<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" />
<!--dialog with image specified by the "img" attribute.-->
<uipop keyid="uidialog5" msg="This Dialog has an image." BGCOLOR="#0000AA" FGCOLOR="#FFFFFF" textsize="25" img="testimage300.png" />


<!--yes/no dialog-->

<uipop keyid="uidialog2" msg="Hello, this is a yes or no dialog." ynflag="1" nokey="nokeyyndiag" yeskey="yeskeyyndiag" />
<uimenu keyid="uimenu1" BGCOLOR="#0000AA" FGCOLOR="#FFFFFF" textsize="25">
<item con="This is a menu." noact="1"/>
<item con="-------------------" noact="1"/>

<item con="play sound" keyid="soundfx1" stay="1"/>
<item con="test dialog with image" keyid="uidialog5" stay="1"/>
<item con="close menu"/>
</uimenu>
<uimenu keyid="dialogtests" BGCOLOR="#0000AA" FGCOLOR="#FFFFFF" textsize="25">
<item con="Desutezeoid dialog system tests." noact="1"/>
<item con="-------------------" noact="1"/>
<item con="test normal dialog" keyid="uidialog1" stay="1"/>
<item con="test yes/no dialog" keyid="uidialog2" stay="1"/>
<item con="test custom color dialog" keyid="uidialog3" stay="1"/>
<item con="test custom text size dialog" keyid="uidialog4" stay="1"/>
<item con="test dialog with image" keyid="uidialog5" stay="1"/>
<item con="close menu"/>
</uimenu>



<!--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 @@ -102,21 +128,12 @@ The timeout instance is also removed after the specified time lapses. also if th
<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>
<label x="0" y="515" size="24" BGCOLOR="#000088" FGCOLOR="#FFFFFF" keyid="dialogtests">
<con>ui dialogs test/example menu.</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>
<label x="0" y="535" size="24" BGCOLOR="#000088" FGCOLOR="#FFFFFF" keyid="uimenu1">
<con>test uimenu</con>
<act type="key" ref="test1.xml"/>
</label>

Expand Down
Binary file added testimage300.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0898a16

Please sign in to comment.