283 lines
7.9 KiB
Python
283 lines
7.9 KiB
Python
import sys
|
|
|
|
sys.dont_write_bytecode = True
|
|
import mtTkinter as tk
|
|
from tkinter import ttk as tkk
|
|
from tkinter import messagebox
|
|
import PCPL
|
|
import langsys
|
|
import time
|
|
import subprocess
|
|
import sys
|
|
import hashengine
|
|
import os
|
|
import random
|
|
import string
|
|
import easygui
|
|
|
|
global LH
|
|
global gamedata
|
|
gamedata = {}
|
|
LH = langsys.langhandler()
|
|
lang = open("clang", 'r')
|
|
lang = lang.read()
|
|
LH.setlang(lang)
|
|
# LH.string("")
|
|
|
|
PCPL.interpreter.ENG = hashengine
|
|
|
|
class script:
|
|
def __init__(self):
|
|
self.code = ""
|
|
|
|
def execute(self):
|
|
PCPL.resetvar()
|
|
PCPL.LIS("HASHBASE")
|
|
PCPL.run(self.code)
|
|
|
|
class previewrend:
|
|
def __init__(self, size, container, offset):
|
|
self._size = size
|
|
self._grid = {}
|
|
self._win = container
|
|
for y in range(size[1]):
|
|
for x in range(size[0]):
|
|
temp = tk.Label(text=" ")
|
|
temp.grid(row=y+offset[1], column=x+offset[0])
|
|
self._win.update()
|
|
self._grid[f"{x}:{y}"] = temp
|
|
|
|
def coltohex(self, target):
|
|
colors = []
|
|
target = [target.r, target.g, target.b]
|
|
for i in target:
|
|
colors.append(("0"*(2-len(hex(i)[2:])))+hex(i)[2:])
|
|
out = ""
|
|
for i in colors:
|
|
out = out + i
|
|
return "#"+out
|
|
|
|
def pix(self, x, y, text, bcolor, fcolor):
|
|
if f"{x}:{y}" in self._grid:
|
|
self._grid[f"{x}:{y}"].config(text=text, bg=self.coltohex(bcolor), fg=self.coltohex(fcolor))
|
|
self._win.update()
|
|
|
|
def selectlang(new):
|
|
lang = open("clang", 'w')
|
|
lang.write(new)
|
|
lang.close()
|
|
container.quit()
|
|
subprocess.Popen([sys.executable, __file__])
|
|
|
|
def add(objtype):
|
|
global objtree
|
|
crucial = ["obj"]
|
|
obj = getattr(types, objtype)()
|
|
args = {}
|
|
for i in dir(obj):
|
|
if i.startswith("_"): continue
|
|
args[i] = getattr(obj, i)
|
|
temp = {"id": objtype, "args": args, "name": LH.string(objtype)}
|
|
id = ""
|
|
chars = list(string.ascii_letters)
|
|
for i in range(255):
|
|
id = id + random.choice(chars)
|
|
objtree.insert("", tk.END, text=LH.string(objtype), image=icons[objtype], iid=id, tags=("objsel"))
|
|
gamedata[id] = temp
|
|
if objtype in crucial:
|
|
preview.addobj(obj)
|
|
gamedata[id]["args"]["ID"] = obj.ID
|
|
preview.render()
|
|
|
|
def renameobj():
|
|
target = objtree.focus()
|
|
if target == "": return
|
|
new = easygui.enterbox(LH.string("NN"), LH.string("rename"))
|
|
if new:
|
|
objtree.item(target, text=new)
|
|
gamedata[target]["name"] = new
|
|
|
|
def delobj():
|
|
target = objtree.focus()
|
|
if target == "": return
|
|
atritree.delete(*atritree.get_children())
|
|
objtree.delete(target)
|
|
gamedata.pop(target)
|
|
|
|
def rpopup(event):
|
|
try:
|
|
rmenu.tk_popup(event.x_root, event.y_root)
|
|
finally:
|
|
rmenu.grab_release()
|
|
|
|
def getattributes(target):
|
|
out = {}
|
|
for i in dir(target):
|
|
if i.startswith("_"): continue
|
|
out[i] = getattr(target, i)
|
|
return out
|
|
|
|
def updatribute(event):
|
|
global currentat
|
|
target = objtree.focus()
|
|
currentat = target
|
|
atritree.delete(*atritree.get_children())
|
|
for i in gamedata[target]["args"]:
|
|
if i in ignoreat: continue
|
|
|
|
if i in valtypes:
|
|
val = gamedata[target]["args"][i]
|
|
atritree.insert("", tk.END, text=i, values=(val))
|
|
else:
|
|
root = atritree.insert("", tk.END, text=i)
|
|
temp = getattributes(gamedata[target]["args"][i])
|
|
for f in temp:
|
|
atritree.insert(root, tk.END, text=f, values=(temp[f]))
|
|
|
|
def halatribute(event):
|
|
target = atritree.focus()
|
|
name = atritree.item(target, "text")
|
|
parent = atritree.parent(target)
|
|
if name in valtypes:
|
|
if parent == "":
|
|
new = valtypes[name](gamedata[currentat]["args"][name])
|
|
gamedata[currentat]["args"][name] = new
|
|
if "ID" in gamedata[currentat]["args"]:
|
|
temp = preview.getobjbyid(gamedata[currentat]["args"]["ID"])
|
|
setattr(temp, name, new)
|
|
atritree.item(target, values=(new))
|
|
else:
|
|
parent = atritree.item(parent, "text")
|
|
new = valtypes[name](getattr(gamedata[currentat]["args"][parent], name))
|
|
setattr(gamedata[currentat]["args"][parent], name, new)
|
|
atritree.item(target, values=(new))
|
|
preview.render()
|
|
|
|
def GUIinit():
|
|
global container
|
|
global objtree
|
|
global rmenu
|
|
global atritree
|
|
global currentat
|
|
global preview
|
|
container = tk.Tk()
|
|
|
|
global icons
|
|
icons = {}
|
|
|
|
for i in os.listdir("icons"):
|
|
icons[i.split(".")[0]] = tk.PhotoImage(file=f"icons/{i}")
|
|
|
|
#preview init
|
|
preview = hashengine.game(renderer=lambda size: previewrend(size, container=container, offset=[0, 0]))
|
|
|
|
#tree init
|
|
objtree = tkk.Treeview(container, selectmode="browse")
|
|
objtree.heading("#0", text=LH.string("objs"))
|
|
objtree.tag_bind("objsel", "<<TreeviewSelect>>", updatribute)
|
|
objtree.grid(row=10, column=11)
|
|
|
|
#attribute tree init
|
|
currentat = "temp"
|
|
atritree = tkk.Treeview(container, columns=("#1"), selectmode="browse")
|
|
atritree.heading("#0", text=LH.string("attribute"))
|
|
atritree.heading("#1", text=LH.string("attribute-val"))
|
|
atritree.bind("<Double-1>", halatribute)
|
|
atritree.grid(row=11, column=11)
|
|
|
|
#right click menu
|
|
rmenu = tk.Menu(container, tearoff=0)
|
|
rmenu.add_command(label=LH.string("rename"), command=renameobj)
|
|
rmenu.add_command(label=LH.string("delete"), command=delobj)
|
|
|
|
objtree.bind("<Button-3>", rpopup)
|
|
|
|
#menu init
|
|
menu = tk.Menu(container)
|
|
container.config(menu=menu)
|
|
filemenu = tk.Menu(menu)
|
|
menu.add_cascade(label=LH.string("file"), menu=filemenu)
|
|
filemenu.add_command(label=LH.string("new"))
|
|
filemenu.add_command(label=LH.string("open"))
|
|
filemenu.add_command(label=LH.string("save"))
|
|
filemenu.add_separator()
|
|
filemenu.add_command(label=LH.string("exit"), command=container.quit)
|
|
|
|
addmenu = tk.Menu(menu)
|
|
menu.add_cascade(label=LH.string("add"), menu=addmenu)
|
|
addmenu.add_command(label=LH.string("obj"), command=lambda: add("obj"))
|
|
addmenu.add_command(label=LH.string("script"), command=lambda: add("script"))
|
|
|
|
langmenu = tk.Menu(menu)
|
|
menu.add_cascade(label=LH.string("langs"), menu=langmenu)
|
|
for i in LH.getlangs():
|
|
langmenu.add_command(label=i, command=lambda i=i: selectlang(i))
|
|
|
|
container.mainloop()
|
|
|
|
def ats(mode, old):
|
|
#mode 0 = string
|
|
#mode 1 = single character
|
|
out = easygui.enterbox(LH.string("newval"), LH.string("newval"))
|
|
if out:
|
|
if mode == 1 and len(out) != 1:
|
|
messagebox.showerror(LH.string("error"), LH.string("SCE"))
|
|
return "N"
|
|
return out
|
|
else:
|
|
return "N"
|
|
|
|
def anum(old):
|
|
out = easygui.integerbox(LH.string("newval"), LH.string("newval"), lowerbound=-9999999999, upperbound=9999999999)
|
|
if out:
|
|
return out
|
|
else:
|
|
return 0
|
|
|
|
def abool(old):
|
|
out = easygui.boolbox(LH.string("newval"), LH.string("newval"), (LH.string("true"), LH.string("false")))
|
|
return out
|
|
|
|
def acode(old):
|
|
out = easygui.textbox(LH.string("newval"), LH.string("newval"), old)
|
|
if out:
|
|
return out
|
|
else:
|
|
return "NULL"
|
|
|
|
global types
|
|
global icon
|
|
global ignoreat
|
|
global valtypes
|
|
types = hashengine.enum({"obj": hashengine.obj, "script": script})
|
|
icon = hashengine.enum({"obj": "icons/object.png", "script": "icons/script.pngg"})
|
|
ignoreat = ["ID", "execute"]
|
|
"""self.position = vector2()
|
|
self.char = " "
|
|
self.ID = 0
|
|
self.gravity = 0
|
|
self.acceleration = vector2()
|
|
self.velocity = vector2()
|
|
self.friction = 0
|
|
self.collide = True
|
|
self.touch = True
|
|
self.anchored = False
|
|
self.bcolor = color3(255, 255, 255)
|
|
self.fcolor = color3()"""
|
|
valtypes = {
|
|
"char": lambda old: ats(1, old),
|
|
"gravity": anum,
|
|
"x": anum,
|
|
"y": anum,
|
|
"z": anum,
|
|
"r": anum,
|
|
"g": anum,
|
|
"b": anum,
|
|
"friction": anum,
|
|
"collide": abool,
|
|
"touch": abool,
|
|
"anchored": abool,
|
|
"code": acode,
|
|
}
|
|
|
|
GUIinit() |