Skip to content

Commit

Permalink
add core objects text and box, add global core objects and global for…
Browse files Browse the repository at this point in the history
…ks, various other tweaks.
  • Loading branch information
ThomasTheSpaceFox committed Feb 18, 2017
1 parent 857d147 commit 6c804f5
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 34 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.1.2
Desutezeoid v1.1.3
(c) 2015-2017 Thomas Leathers


Expand Down
156 changes: 145 additions & 11 deletions DZU-ENG1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import pygame
import time
import os
import copy
from pygame.locals import *
import xml.etree.ElementTree as ET
pygame.display.init()
pygame.font.init()
pygame.mixer.init()
print "Desutezeoid arbitrary point and click engine v1.1.2"
print "Desutezeoid arbitrary point and click engine v1.1.3"
print "parsing ENGSYSTEM.xml"
conftree = ET.parse("ENGSYSTEM.xml")
confroot = conftree.getroot()
Expand All @@ -23,11 +24,17 @@
for initk in initkeystag.findall("k"):
if (initk.attrib.get("keyid"))!="0":
keylist.extend([initk.attrib.get("keyid")])
print keylist

scrnx=int(screentag.attrib.get("x", "800"))
scrny=int(screentag.attrib.get("y", "600"))
titletag=confroot.find("title")
debugtag=confroot.find("debug")
DEBUG=int(debugtag.attrib.get("debug", "1"))
printkeys=int(debugtag.attrib.get("printkeys", "1"))
beginref=(confroot.find("beginref")).text

globalcoretag=confroot.find("globalcore")
globalforkstag=confroot.find("globalforks")
print "config parsed."
titlebase=titletag.attrib.get("base", "Desutezeoid: ")
class clicktab:
Expand All @@ -45,13 +52,17 @@ def __init__(self, seconds, keyid, postkey):
self.regtime=time.time()
self.seconds=seconds
self.postkey=postkey
DEBUG=1

#class keyobj:
# def __init__(self, keyid):
# self=keyid
def debugmsg(msg):
if DEBUG==1:
print msg
def keyprint():
if printkeys==1:
print keylist
keyprint()
prevpage="NULL"
#point this to your first screen c: no menu program really needed :o
curpage=beginref
Expand All @@ -73,14 +84,23 @@ def debugmsg(msg):
#print "tic"
if curpage!=prevpage:
print "preparsing page"
pygame.mixer.music.stop()

tree = ET.parse(curpage)
root = tree.getroot()
prevpage=curpage
coretag=root.find('core')
forktag=root.find('forks')
print "parsing global core objects into page structure..."
for glb in globalcoretag:
coretag.append(copy.deepcopy(glb))
print "parsing global fork objects into page structure..."
for glb in globalforkstag:
forktag.append(copy.deepcopy(glb))
pageconf=root.find('pageconf')
pagetitle=(pageconf.find('title')).text
BGMstop=int(pageconf.attrib.get("BGMstop", "1"))
if BGMstop==1:
pygame.mixer.music.stop()
BGon=int(pageconf.attrib.get("BGimg", "0"))
BGMon=int(pageconf.attrib.get("BGM", "0"))
if BGMon==1:
Expand Down Expand Up @@ -127,12 +147,14 @@ def debugmsg(msg):
if len(set(complist)) == 1:
if not masterkey in keylist:
keylist.extend([masterkey])
print keylist
#print keylist
keyprint()
forksanity=1
else:
if masterkey in keylist:
keylist.remove(masterkey)
print keylist
#print keylist
keyprint()
forksanity=1
for fork in forktag.findall("batchset"):
#print "batch"
Expand All @@ -146,14 +168,16 @@ def debugmsg(msg):
subkeyid=subkey.attrib.get("keyid")
if not subkeyid in keylist:
keylist.extend([subkeyid])
print keylist
#print keylist
keyprint()
forksanity=1
else:
for subkey in fork.findall("k"):
subkeyid=subkey.attrib.get("keyid")
if subkeyid in keylist:
keylist.remove(subkeyid)
print keylist
#print keylist
keyprint()
forksanity=1
pagejumpflag=0
for fork in forktag.findall("pagejump"):
Expand Down Expand Up @@ -210,7 +234,8 @@ def debugmsg(msg):
if tif.postkey not in keylist:
if tif.postkey!="0":
keylist.extend([tif.postkey])
print keylist
#print keylist
keyprint()
timeoutlist.remove(tif)

keybak=list(keylist)
Expand Down Expand Up @@ -275,6 +300,113 @@ def debugmsg(msg):
# break
datstr=clicktab(clickref, "key", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
for labref in coretag.findall("box"):
keyid=labref.attrib.get('keyid', "0")
takekey=labref.attrib.get('takekey', "0")
onkey=labref.attrib.get('onkey', "0")
offkey=labref.attrib.get('offkey', "0")
hoverkey=labref.attrib.get('hoverkey', "0")
clicksoundflg=int(labref.attrib.get('sfxclick', "0"))
soundname=(labref.attrib.get('sound', "0"))
if ((onkey=="0" and offkey=="0") or (onkey=="0" and offkey not in keylist) or (onkey in keylist and offkey=="0") or (onkey in keylist and offkey not in keylist)):
imgx=int(labref.attrib.get("x"))
imgy=int(labref.attrib.get("y"))
sizex=int(labref.attrib.get("sizex"))
sizey=int(labref.attrib.get("sizey"))
onhov=int(labref.attrib.get("onhov", "0"))
hovcolor=pygame.Color(labref.attrib.get("HOVCOLOR", "#FFFFFF"))
hovalpha=int(labref.attrib.get("hovalpha", "140"))
boxalpha=int(labref.attrib.get("alpha", "100"))
boxcolor=pygame.Color(labref.attrib.get("COLOR", "#FFFFFF"))
#imgcon=(labref.find("con")).text
act=labref.find("act")
acttype=act.attrib.get("type", "none")
pos = pygame.mouse.get_pos()
#imggfx=pygame.image.load(imgcon)
boxgfx=pygame.Surface((sizex, sizey))
boxgfx.convert_alpha()
#imggfx.fill(boxcolor)
boxgfx.set_alpha(0)
clickref=screensurf.blit(boxgfx, (imgx, imgy))
if onhov==1 and clickref.collidepoint(pos)==1:
boxgfx.fill(hovcolor)
boxgfx.set_alpha(hovalpha)
#skip blitting a second time if alpha is 0.
if hovalpha!=0:
clickref=screensurf.blit(boxgfx, (imgx, imgy))
else:
boxgfx.fill(boxcolor)
boxgfx.set_alpha(boxalpha)
#skip blitting a second time if alpha is 0.
if boxalpha!=0:
clickref=screensurf.blit(boxgfx, (imgx, imgy))
if hoverkey!="0":
if clickref.collidepoint(pos)==1:
if not hoverkey in keylist:
keylist.extend([hoverkey])
else:
if hoverkey in keylist:
keylist.remove(hoverkey)
if acttype!="none":
pos = pygame.mouse.get_pos()
if acttype=="iref":
ref=act.attrib.get("ref")
#for event in pygame.event.get(MOUSEBUTTONDOWN):
#pygame.event.get()
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# curpage=ref
# break
datstr=clicktab(clickref, "iref", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
if acttype=="quit":
ref=act.attrib.get("ref")
#for event in pygame.event.get(MOUSEBUTTONDOWN):
#pygame.event.get()
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# quitflag=1
# break
datstr=clicktab(clickref, "quit", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
if acttype=="key":
ref=act.attrib.get("ref")
#for event in pygame.event.get(MOUSEBUTTONDOWN):
#pygame.event.get()
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# quitflag=1
# break
datstr=clicktab(clickref, "key", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
for texref in coretag.findall("text"):
onkey=texref.attrib.get('onkey', "0")
offkey=texref.attrib.get('offkey', "0")
if ((onkey=="0" and offkey=="0") or (onkey=="0" and offkey not in keylist) or (onkey in keylist and offkey=="0") or (onkey in keylist and offkey not in keylist)):
labx=int(texref.attrib.get("x"))
laby=int(texref.attrib.get("y"))
size=int(texref.attrib.get("size"))
FGCOL=pygame.Color(texref.attrib.get("FGCOLOR", "#FFFFFF"))
BGCOL=pygame.Color(texref.attrib.get("BGCOLOR", "#000000"))
transp=int(texref.attrib.get("transp", "0"))
texfnt=pygame.font.SysFont(None, size)
pixcnt1=laby
pixjmp=(size+0)
textcont=(texref.text + "\n")
textchunk=""
#this draws the text body line-per-line
for texch in textcont:
if texch=="\n":
#if at newline, render line of text, clear textchunk, and add to pixcnt1
if transp==0:
texgfx=texfnt.render(textchunk, True, FGCOL, BGCOL)
else:
texgfx=texfnt.render(textchunk, True, FGCOL)
screensurf.blit(texgfx, (labx, pixcnt1))
pixcnt1 += pixjmp
textchunk=""
else:
#if not at a newline yet, keep building textchunk.
textchunk=(textchunk + texch)

#clickref=screensurf.blit(labgfx, (labx, laby))
for labref in coretag.findall("label"):
keyid=labref.attrib.get('keyid', "0")
takekey=labref.attrib.get('takekey', "0")
Expand Down Expand Up @@ -356,11 +488,13 @@ def debugmsg(msg):
if f.keyid!="0":
if not f.keyid in keylist:
keylist.extend([f.keyid])
print keylist
#print keylist
keyprint()
if f.takekey!="0":
if takekey in keylist and f.takekey!="0":
keylist.remove(f.takekey)
print keylist
#print keylist
keyprint()
if f.reftype=="iref":
curpage=f.ref
print ("iref: loading page '" + f.ref + "'")
Expand Down
31 changes: 30 additions & 1 deletion ENGSYSTEM.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,41 @@
<!--window size-->
<screen x="800" y="600"/>
<!--Game/program Title-->
<title base="Desutezeoid v1.1.2 test program. " />
<title base="Desutezeoid v1.1.3 test program. " />
<!--page to load at engine start.-->
<beginref>test0.xml</beginref>
<!--debug settings. used in development and testing. printkeys controls keyid list printing.-->
<debug debug="1" printkeys="1"/>
<!--keyids loaded into the keyid enviornment at startup.-->
<initkeys>
<k keyid="timeloop1"/>
<k keyid="testkey1"/>
</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.-->

<!--These forks are present on each page-->
<globalforks>
<!--this is an endless loop of 3 keyids. this is started by a keyid added by the initkeys section of config. also note how since this is in globalforks, it stays running.
and with a nonlooping sequence, such as an "on-click" animation. you would only need it on the page the animation is present on.-->
<timeout keyid="timeloop1" seconds="0.5" post="timeloop2"/>
<timeout keyid="timeloop2" seconds="0.5" post="timeloop3"/>
<timeout keyid="timeloop3" seconds="0.5" post="timeloop1"/>
</globalforks>
<!--these core objects are present on each page-->
<globalcore>
<!--this label uses the act type "quit" when clicked, this will quit the "game" also note how since this is present in globalcore, it shows on every page.-->
<label x="0" y="580" size="20" BGCOLOR="#880000" FGCOLOR="#FFFFFF" >
<con>QUIT</con>
<act type="quit" ref="test1.xml"/>
</label>
<label x="40" y="580" size="20" BGCOLOR="#008800" FGCOLOR="#FFFFFF" >
<con>About</con>
<act type="iref" ref="about.xml"/>
</label>
<label x="80" y="580" size="20" BGCOLOR="#008800" FGCOLOR="#FFFFFF" >
<con>Home</con>
<act type="iref" ref="test0.xml"/>
</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.1.2
v1.1.3
an arbitrary point and click engine.
(c) 2015-2017 Thomas Leathers

Expand Down
34 changes: 34 additions & 0 deletions about.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<main>
<pageconf BGimg="1" BGM="0">
<title>About Desutezeoid.</title>
<BG>BGseaside.jpg</BG>
<BGM>BGM1.ogg</BGM>
</pageconf>
<forks>
</forks>
<core>
<label x="0" y="10" size="30" transp="1" FGCOLOR="#000000">
<con>Desutezeoid</con>
<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.1.3
an arbitrary point and click engine.
(c) 2015-2017 Thomas Leathers


Desutezeoid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Desutezeoid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Desutezeoid. If not, see &lt;http://www.gnu.org/licenses/&gt;.</text>
</core>
</main>
19 changes: 8 additions & 11 deletions test0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ but only after the keyid is present will the countdown begin. it is safe to remo
timeout fork associated with it. as the timeout instance in question will be removed automatically.
The timeout instance is also removed after the specified time lapses. also if the optional post keyid atribbute is set, a keyid will be passively added after timeout.-->
<timeout keyid="prototime" seconds="3.5" post="soundfx1"/>
<!--this is an endless loop of 3 keyids. this is started by a keyid added by the initkeys section of config. also note this should be in all pages' xml files. that will keep the loop running.
and with a nonlooping sequence, such as an "on-click" animation. you would only need it on the page the animation is present on.-->
<timeout keyid="timeloop1" seconds="0.5" post="timeloop2"/>
<timeout keyid="timeloop2" seconds="0.5" post="timeloop3"/>
<timeout keyid="timeloop3" seconds="0.5" post="timeloop1"/>

</forks>
<core>
<!--note the "hoverkey" attribute. this toggles in and out of the keyidlist based on wether the curser is over the label/img instance. this one triggers a label further down.-->
<label x="300" y="400" size="40" transp="1" FGCOLOR="#FFFFFF" hoverkey="onhov2">
<con>Hello world! :D</con>
<act type="none"/>
</label>
<!--note on label colors: if you only specify "FGCOLOR", the label will have a transparent background.-->
<!--This is the box object. it generates a solid color box of the specified size. like img, and label, it is clickable, has separate hover visual attributes, and so on. "COLOR" is an html #RRGGBB format color. as is "HOVCOLOR". hovcolor is used when the mouse is over the box, and "onhov" is specified as "1". otherwise "COLOR" is used. also you can overwride the default alpha values using "alpha" and "hovalpha" both alpha values should be a number from 0 to 255.-->
<box x="300" y="200" sizex="40" sizey="60" COLOR="#FF0000" alpha="60" hovalpha="150" onhov="1" HOVCOLOR="#FF0000">
<act type="none"/>
</box>

<!--note on label colors: if you only specify "FGCOLOR" and set "transp" as "1", the label will have a transparent background.-->
<label x="80" y="130" size="24" transp="1" FGCOLOR="#000000" onkey="onhov1">
<con>Hey... an on-hover event. :o</con>
<act type="none"/>
Expand Down Expand Up @@ -122,16 +123,12 @@ plese use either "iref" or "key"-->
<con>click me for a sound fx!</con>
<act type="key"/>
</label>
<label x="0" y="580" size="20" BGCOLOR="#880000" FGCOLOR="#FFFFFF" >
<con>QUIT</con>
<act type="quit" ref="test1.xml"/>
</label>
<img x="80" y="80" hovpic="1" hoverkey="onhov1">
<con>testimg0.png</con>
<altcon>testimg1.png</altcon>
<act type="quit" ref="test1.xml"/>
</img>
<!--lets animate a test animation with that timeout loop!-->
<!--lets animate a test animation with that timeout loop in "globalcore"! See engine config file (ENGSYSTEM.xml) comments for further explanation.-->
<img x="300" y="100" onkey="timeloop1">
<con>animtest1a.png</con>
<act type="none"/>
Expand Down
Loading

0 comments on commit 6c804f5

Please sign in to comment.