here2share

# Tk_old_Uniday_pygame_engine.py

May 2nd, 2022
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 65.71 KB | None | 0 0
  1. # Tk_old_Uniday_pygame_engine.py
  2.  
  3. from tkinter import *
  4. from tkinter.colorchooser import *
  5. import pygame
  6. import os
  7. from tkinter import filedialog
  8. import PIL
  9. from PIL import Image, ImageTk
  10. import subprocess
  11. import sys
  12.  
  13. #####################
  14. screenBg = '#1a1a1a'
  15.  
  16. color_dark1 = '#1a1a1a'
  17. color_dark2 = '#2d2d2d'
  18. color_dark3 = '#494949'
  19.  
  20. color_white1 = '#e6e6e6'
  21.  
  22. color_blue1 = '#2d69ff'
  23. color_blue2 = '#000037' #'#00142d'
  24.  
  25. color_font1 = '#1a1a1a'
  26. color_font2 = '#e6e6e6'
  27.  
  28. color_pine1 = '#c28a2b'
  29.  
  30. color_selection =  "#ba0c0c" #"#ef9a03"
  31. color_unselected = "#2d69ff"
  32.  
  33. #color_sceneObject = '#2d2d2d'
  34. #color_engine = '#00142d'
  35.  
  36. border = 1
  37. padSize = 1
  38. #####################
  39.  
  40. root = Tk()
  41. root.title('UDengine 2 - By Guilherme Teres Nunes')
  42. #root.geometry('512x512')
  43. root.state('zoomed')
  44. root.configure(background=screenBg)
  45.  
  46. ##################################################################
  47. ##                    GAME ENGINE PLAYER CALL                   ##
  48. ##################################################################
  49. inGame = False
  50. # need to fix!
  51. def Call_engine():
  52.     ## STANDALONE PLAY
  53.     #os.spawn*
  54.     #os.system("UDplayer.py")
  55.     #subprocess.call("UDplayer.py", shell=True)
  56.     #proc = subprocess.Popen([sys.executable,"UDplayer.py"])
  57.     #subprocess.call([sys.executable, "UDplayer.py"])
  58.     pass
  59.  
  60. ##################################################################
  61. ##                  GAME ENGINE EDITOR INTERFACE                ##
  62. ##################################################################
  63.  
  64. ##################################
  65. topMenu = Menu(root, background='#000099', foreground='white', activebackground='#004c99', activeforeground='white')# background=color_dark1, activebackground=color_dark1)
  66. topMenu.add_command(label='File')#, command=getColorHTML)
  67. root.config(menu=topMenu)
  68.  
  69. # Default
  70. m1 = PanedWindow(root, orient=VERTICAL,background=screenBg, borderwidth=border, sashpad=padSize) #, showhandle=True
  71. m1.pack(fill=BOTH, expand=1)
  72. #TOP
  73. Paned_top = PanedWindow(m1,background=screenBg, borderwidth=border, sashpad=padSize)
  74. m1.add(Paned_top)
  75. #DOWN
  76. Paned_down = PanedWindow(m1,background=screenBg, borderwidth=border, sashpad=padSize)
  77. m1.add(Paned_down)
  78.  
  79. # CONFIGURATIONS
  80. m1.paneconfig(Paned_top, minsize=64)
  81. m1.paneconfig(Paned_down, minsize=64)
  82.  
  83. Pdown_objInfo = Frame(Paned_down)#Label(Paned_down, text='uee')
  84. Pdown_objInfo.configure(bg=color_dark3)
  85. Paned_down.add(Pdown_objInfo)
  86.  
  87. nodes = Canvas(Paned_down, background=color_blue2)
  88. #nodes.create_rectangle(-100,-100,2512,2512,fill=color_blue1)
  89. Paned_down.add(nodes)
  90. Paned_down.paneconfig(Pdown_objInfo, minsize=256)
  91. Paned_down.paneconfig(nodes, minsize=64)
  92.  
  93. #playGame = pygame.display.set_mode((512,512))
  94.  
  95. ## Tentativa de por Pygame aqui. INICIO:
  96. res = Frame(Paned_top, width=256,height=256)
  97. Paned_top.add(res)
  98. os.environ['SDL_WINDOWID'] = str(res.winfo_id())
  99. os.environ['SDL_VIDEODRIVER'] = 'windib'
  100. #screen = pygame.display.set_mode((256,256))
  101. ## FIM
  102.  
  103. Paned_sceneObj = Frame(Paned_top)#Label(Paned_top, text='Objects')
  104. Paned_sceneObj.configure(bg=color_dark2)
  105. Paned_top.add(Paned_sceneObj)
  106.  
  107. bottom = Canvas(Paned_top)#Label(Paned_top, text="Painel lateral Superior")
  108. bottom.configure(bg=color_dark3)
  109. Paned_top.add(bottom)
  110. bottom.create_rectangle(10,22+2,312,130,fill=color_dark1)
  111. bottom.create_rectangle(10,22+130,312,130+200,fill=color_dark1)
  112. bottom.create_rectangle(10,22+331,312,330+200,fill=color_dark1)
  113.  
  114.  
  115. Paned_top.paneconfig(res, minsize=64)
  116. Paned_top.paneconfig(bottom, minsize=64)
  117. Paned_top.paneconfig(Paned_sceneObj,minsize=128)
  118.  
  119. ##################################################################
  120. ##                  GAME ENGINE EDITOR MECHANICS                ##
  121. ##################################################################
  122.  
  123. ####             GAME ENGINE VARIABLES!
  124. game = {'screenSize':[512,512],
  125.         'fps':60}
  126.  
  127. scenes = []
  128. defaultScene = {'name':'Scene01',
  129.                 'objects':[],
  130.                 'gravity':[True, 9.8],
  131.                 'background':'#00142d',
  132.                 'cameraPos':[0.0,0.0],
  133.                 'logicNode':[],
  134.                 'wireframe':False,
  135.                 'textures':{}}
  136.  
  137. scenes.append(defaultScene)
  138.  
  139. defaultObject = {'name':'Block',
  140.                  'collision':False,
  141.                  'dynamic':False,
  142.                  'objectClass':'',
  143.                  'material':None,
  144.                  'parent':None,
  145.                  'color':'#e6e6e6',
  146.                  'renderLayer':2,
  147.                  'position':[128.0,128.0],
  148.                  'scale':[256.0,256.0],
  149.                  'rotation':[0.0]}
  150. scenes[0]['objects'].append(defaultObject)
  151.  
  152. currentSceneName ='None'
  153. currentScene = None
  154. currentSceneId = None
  155.  
  156. def getCurrentScene():
  157.     global currentScene, currentSceneName, currentSceneId
  158.  
  159.     currentSceneName = 'Scene01'
  160.     TmpcurrentScene = [[obj, ind] for ind, obj in enumerate(scenes) if obj['name'] == currentSceneName]
  161.  
  162.     if len(TmpcurrentScene) > 0:
  163.         currentScene = TmpcurrentScene[0][0]
  164.         currentSceneId = TmpcurrentScene[0][1]
  165.     else:
  166.         currentScene = None
  167.         currentSceneId = None
  168.  
  169. getCurrentScene()
  170. ####             INTERFACE VARIABLES!
  171. selectedObject = None
  172.  
  173. ##################################################################
  174. ##                       TAB CONFIGURATION                      ##
  175. ##################################################################
  176.  
  177. def getColorHTML(start,title,see=None):
  178.     global scenes, currentSceneId
  179.     if currentSceneId != None:
  180.         start = scenes[currentSceneId]['background']
  181.  
  182.     if see == 'objColor': # scenes[currentSceneId]['objects'][selectedObject[1]]['color']
  183.         try:
  184.             gc = askcolor(initialcolor=scenes[currentSceneId]['objects'][selectedObject[1]]['color'], title=title)
  185.         except:
  186.             gc = askcolor(initialcolor=start, title=title)
  187.     else:
  188.         gc = askcolor(initialcolor=start, title=title)
  189.  
  190.     if see == None:
  191.         ue = gc[1]
  192.         #print(ue)
  193.         return(ue)
  194.     elif see == 'bg':
  195.         ue = gc[1]
  196.         if currentSceneId != None:
  197.             scenes[currentSceneId]['background'] = ue
  198.             return(ue)
  199.     elif see == 'objColor':
  200.         ue = gc[1]
  201.         if currentScene != None:
  202.             try:
  203.                 scenes[currentSceneId]['objects'][selectedObject[1]]['color'] = ue
  204.             except:
  205.                 pass
  206.             return(ue)
  207.  
  208. ####   SCENE AND GAME TAB
  209. sg_title_scene = Label(bottom, text='Scene', bg=color_dark3, fg=color_font2)
  210. sg_title_scene.place(x=10,y=2)
  211.  
  212. defaultSpacer = 42
  213.  
  214. sg_title_items1 = Label(bottom,text='Scene Name',bg=color_dark1, fg=color_font2)
  215. sg_title_items1.place(x=32,y=32)
  216. sg_title_items2 = Label(bottom,text='Gravity (bool)',bg=color_dark1, fg=color_font2)
  217. sg_title_items2.place(x=32+128+32,y=32)
  218.  
  219. sg_entry_sname = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  220. sg_entry_sname.place(x=32,y=54)
  221. sg_entry_gravity = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  222. sg_entry_gravity.place(x=64+128,y=54)
  223.  
  224. sg_title_items3 = Label(bottom,text='Background',bg=color_dark1, fg=color_font2)
  225. sg_title_items3.place(x=32,y=32+defaultSpacer)
  226. sg_title_items4 = Label(bottom,text='Gravity Speed',bg=color_dark1, fg=color_font2)
  227. sg_title_items4.place(x=32+128+32,y=32+defaultSpacer)
  228.  
  229. sg_entry_bg = Button(bottom, text='Change BG', width=13, command=lambda:getColorHTML('#ffffff','Change Scene BG','bg'))#Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  230. sg_entry_bg.place(x=32,y=54+defaultSpacer)
  231. sg_entry_gravitySpeed = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  232. sg_entry_gravitySpeed.place(x=64+128,y=54+defaultSpacer)
  233.  
  234. # Game
  235. sg_title_game = Label(bottom, text='Game', bg=color_dark3, fg=color_font2)
  236. sg_title_game.place(x=10,y=5+defaultSpacer*3)
  237.  
  238. sg_title_items3 = Label(bottom,text='Screen Size',bg=color_dark1, fg=color_font2)
  239. sg_title_items3.place(x=32,y=32+defaultSpacer*3)
  240. sg_title_items4 = Label(bottom,text='Max FPS',bg=color_dark1, fg=color_font2)
  241. sg_title_items4.place(x=32+128+32,y=32+defaultSpacer*3)
  242.  
  243. sg_entry_sizeX = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  244. sg_entry_sizeX.place(x=32,y=54+defaultSpacer*3)
  245. sg_entry_maxFPS = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  246. sg_entry_maxFPS.place(x=64+128,y=54+defaultSpacer*3)
  247.  
  248. sg_title_items5 = Label(bottom,text='x',bg=color_dark1, fg=color_font2)
  249. sg_title_items5.place(x=16,y=54+defaultSpacer*3)
  250. sg_title_items6 = Label(bottom,text='y',bg=color_dark1, fg=color_font2)
  251. sg_title_items6.place(x=16,y=54+defaultSpacer*4-22)
  252. sg_entry_sizeY = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  253. sg_entry_sizeY.place(x=32,y=54+defaultSpacer*4-22)
  254.  
  255. ## Camera Pos
  256. sg_title_items7 = Label(bottom,text='Camera Position',bg=color_dark1, fg=color_font2)
  257. sg_title_items7.place(x=32,y=32+defaultSpacer*5)
  258.  
  259. sg_entry_posX = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  260. sg_entry_posX.place(x=32,y=54+defaultSpacer*5)
  261. sg_entry_posY = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  262. sg_entry_posY.place(x=32,y=54+defaultSpacer*6-22)
  263.  
  264. sg_title_items515 = Label(bottom,text='Wireframe',bg=color_dark1, fg=color_font2)
  265. sg_title_items515.place(x=64+128,y=32+defaultSpacer*5)
  266.  
  267. sg_entry_wire = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  268. sg_entry_wire.place(x=64+128,y=54+defaultSpacer*5)
  269.  
  270. sg_title_items8 = Label(bottom,text='x',bg=color_dark1, fg=color_font2)
  271. sg_title_items8.place(x=16,y=54+defaultSpacer*5)
  272. sg_title_items9 = Label(bottom,text='y',bg=color_dark1, fg=color_font2)
  273. sg_title_items9.place(x=16,y=54+defaultSpacer*6-22)
  274.  
  275. ####### LOAD TEXTURES
  276. sg_title_game = Label(bottom, text='Texture Material', bg=color_dark3, fg=color_font2)
  277. sg_title_game.place(x=10,y=38+defaultSpacer*7)
  278.  
  279. def mat_load():
  280.     global scenes
  281.  
  282.     ftype = [("PNG Image","*.png"),("JPG Image","*.jpg")]
  283.     dialog = filedialog.askopenfilename(filetypes=ftype)
  284.     print("Image directory: ",dialog)
  285.     if currentScene != None:
  286.         textName = dialog.split('/')
  287.         textName = textName[len(textName)-1]
  288.         ImageName = textName.split('.')[0]
  289.         imgLoad = Image.open(dialog)
  290.         imgLoad = imgLoad.resize((256,256), PIL.Image.ANTIALIAS)
  291.         format = '.tif'
  292.         imgLoad.save(ImageName+format)
  293.         toAdd = pygame.image.load(ImageName+format)#.convert_alpha() # dialog
  294.         scenes[currentSceneId]['textures'][textName] = [toAdd, dialog]
  295.  
  296. def mat_remove():
  297.     global scenes
  298.     name = mat_entry_name.get()
  299.     if currentScene != None:
  300.         if name in scenes[currentSceneId]['textures']:
  301.             del scenes[currentSceneId]['textures'][name]
  302.             mat_entry_name.delete(0, END)
  303.             print('removed!')
  304.  
  305. def mat_showPreview():
  306.     name = mat_entry_name.get()
  307.     if currentScene != None:
  308.         if name in scenes[currentSceneId]['textures']:
  309.             fname = scenes[currentSceneId]['textures'][name][1]
  310.             img = Image.open(fname)#PhotoImage(file=fname)
  311.             img = img.resize((96,96), PIL.Image.ANTIALIAS)
  312.             photo = ImageTk.PhotoImage(img)
  313.             mat_label_img.config(image=photo)
  314.             mat_label_img.image = photo
  315.             #print(scenes[currentSceneId]['textures'][name])
  316.  
  317. mat_entry_name = Entry(bottom,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  318. mat_entry_name.place(x=64+128,y=74+defaultSpacer*7)
  319. mat_button_remove = Button(bottom, text='Remove',bg=color_white1,fg=color_font1, width=13, command=mat_remove)
  320. mat_button_remove.place(x=64+128,y=22+54+defaultSpacer*10)
  321. mat_button_load = Button(bottom, text='Load New',bg=color_white1,fg=color_font1, width=13, command=mat_load)
  322. mat_button_load.place(x=32,y=22+54+defaultSpacer*10)
  323.  
  324. bottom.create_rectangle(64+128,55+defaultSpacer*8,64+128+100,100+55+defaultSpacer*8, fill=color_dark2)
  325. mat_label_img = Label(bottom, bg=color_dark2)
  326. mat_label_img.place(x=64+128,y=55+defaultSpacer*8)
  327.  
  328. mat_scroll = Scrollbar(bottom)
  329. mat_scroll.place(x=128, y=74+defaultSpacer*7)
  330.  
  331. mat_list_text = Listbox(bottom,bg=color_white1,fg=color_font1, width=16, height=7, yscrollcommand=mat_scroll.set )
  332. mat_list_text.place(x=32, y=74+defaultSpacer*7)
  333.  
  334. mat_scroll.config(command=mat_list_text.yview,width=22)
  335.  
  336. def SceneGameUpdate():
  337.     # .delete(0, END)
  338.     # .insert(0, 'mimimi')
  339.     if currentScene != None:
  340.         # Adicionar texturas na lista
  341.         mat_list_text.delete(0, END)
  342.         mat_list_text.insert(END, ' #Material List:')
  343.         for obj in currentScene['textures']:
  344.             mat_list_text.insert(END, obj)
  345.         mat_entry_name.delete(0,END)
  346.  
  347.         #print(str(currentScene['wireframe']))
  348.         sg_entry_wire.delete(0,END)
  349.  
  350.         sg_entry_sname.delete(0, END)
  351.         sg_entry_sname.insert(0, currentScene['name'])
  352.         sg_entry_gravity.delete(0, END)
  353.         sg_entry_gravity.insert(0, str(currentScene['gravity'][0]))
  354.         sg_entry_gravitySpeed.delete(0, END)
  355.         sg_entry_gravitySpeed.insert(0, str(currentScene['gravity'][1]))
  356.         #sg_entry_bg.delete(0, END)
  357.         #sg_entry_bg.insert(0, currentScene['background'])
  358.         sg_entry_posX.delete(0, END)
  359.         sg_entry_posX.insert(0, str(currentScene['cameraPos'][0]))
  360.         sg_entry_posY.delete(0, END)
  361.         sg_entry_posY.insert(0, str(currentScene['cameraPos'][1]))
  362.  
  363.         sg_entry_sizeX.delete(0, END)
  364.         sg_entry_sizeX.insert(0, str(game['screenSize'][0]))
  365.         sg_entry_sizeY.delete(0, END)
  366.         sg_entry_sizeY.insert(0, str(game['screenSize'][1]))
  367.         sg_entry_maxFPS.delete(0, END)
  368.         sg_entry_maxFPS.insert(0, str(game['fps']))
  369.  
  370. def SceneGameSync():
  371.     global scenes
  372.     error = False
  373.  
  374.     scenes[currentSceneId]['name'] = str(sg_entry_sname.get())
  375.     #scenes[currentSceneId]['background'] = str(sg_entry_bg.get())
  376.  
  377.     mat_showPreview()
  378.  
  379.     lst = mat_list_text.get(ACTIVE)
  380.     if lst != ' #Material List:':
  381.         mat_entry_name.delete(0, END)
  382.         mat_entry_name.insert(END, lst)
  383.  
  384.     mat_list_text.delete(0, END)
  385.     mat_list_text.insert(END, ' #Material List:')
  386.  
  387.     for obj in currentScene['textures']:
  388.         mat_list_text.insert(END, obj)
  389.     try:
  390.         scenes[currentSceneId]['cameraPos'] = [float(sg_entry_posX.get()),float(sg_entry_posY.get())]
  391.         scenes[currentSceneId]['gravity'][0] = bool(sg_entry_gravity.get())
  392.         scenes[currentSceneId]['gravity'][1] = float(sg_entry_gravitySpeed.get())
  393.         scenes[currentSceneId]['wireframe'] = bool(sg_entry_wire.get())
  394.         game['screenSize'] = [float(sg_entry_sizeX.get()),float(sg_entry_sizeY.get())]
  395.         game['fps'] = int(sg_entry_maxFPS.get())
  396.     except:
  397.         error = True
  398.     if error:
  399.         SceneGameUpdate()
  400.         print('ops...')
  401.  
  402. ##################################################################
  403. ##                          OBJECT TAB                          ##
  404. ##################################################################
  405.  
  406. ####   SCENE AND GAME TAB
  407. obj_title_ObjPanel = Label(Pdown_objInfo, text='Object Panel', bg=color_dark3, fg=color_font2)
  408. obj_title_ObjPanel.place(x=0,y=0)
  409.  
  410. defaultSpacer = 42
  411.  
  412. tmpX,tmpY = 32, 32
  413. obj_title_items1 = Label(Pdown_objInfo,text='Object Name',bg=color_dark3, fg=color_font1)
  414. obj_title_items1.place(x=tmpX,y=tmpY)
  415. obj_entry_oname = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  416. obj_entry_oname.place(x=tmpX,y=tmpY+22)
  417.  
  418. tmpX,tmpY = 32+120, 32
  419. obj_title_items2 = Label(Pdown_objInfo,text='Collision (bool)',bg=color_dark3, fg=color_font1)
  420. obj_title_items2.place(x=tmpX,y=tmpY)
  421. obj_entry_col = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  422. obj_entry_col.place(x=tmpX,y=tmpY+22)
  423.  
  424. tmpX,tmpY = 32+120*2, 32
  425. obj_title_items3 = Label(Pdown_objInfo,text='Dynamic (bool)',bg=color_dark3, fg=color_font1)
  426. obj_title_items3.place(x=tmpX,y=tmpY)
  427. obj_entry_dynamic = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  428. obj_entry_dynamic.place(x=tmpX,y=tmpY+22)
  429.  
  430. tmpX,tmpY = 32, 32+defaultSpacer
  431. obj_title_items4 = Label(Pdown_objInfo,text="Obj Class(list,split=,)",bg=color_dark3, fg=color_font1)
  432. obj_title_items4.place(x=tmpX,y=tmpY)
  433. obj_entry_class = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  434. obj_entry_class.place(x=tmpX,y=tmpY+22)
  435.  
  436. tmpX,tmpY = 32+120, 32+defaultSpacer
  437. obj_title_items5 = Label(Pdown_objInfo,text="Material",bg=color_dark3, fg=color_font1)
  438. obj_title_items5.place(x=tmpX,y=tmpY)
  439. obj_SelectedMat = StringVar()
  440. obj_SelectedMat.set("None")
  441. optionList = ["None"]
  442. obj_entry_mat = OptionMenu(Pdown_objInfo, obj_SelectedMat, *optionList)#Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  443. obj_entry_mat.config(height=1, width=9)
  444. obj_entry_mat.place(x=tmpX,y=tmpY+22)
  445.  
  446. tmpX,tmpY = 32+120*2, 32+defaultSpacer
  447. obj_title_items6 = Label(Pdown_objInfo,text="Parent Name",bg=color_dark3, fg=color_font1)
  448. obj_title_items6.place(x=tmpX,y=tmpY)
  449. obj_entry_par = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  450. obj_entry_par.place(x=tmpX,y=tmpY+22)
  451.  
  452. tmpX,tmpY = 32+120, 32+defaultSpacer*2
  453. obj_title_items7 = Label(Pdown_objInfo,text="Color",bg=color_dark3, fg=color_font1)
  454. #obj_title_items7.place(x=tmpX,y=tmpY)
  455. obj_entry_color = Button(Pdown_objInfo, text='Change Color', width=13, command=lambda:getColorHTML('#ffffff','Change Object Color','objColor')) #Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  456. obj_entry_color.place(x=tmpX,y=tmpY+22)
  457.  
  458. tmpX,tmpY = 32+120*2, 32+defaultSpacer*2
  459. obj_title_items8 = Label(Pdown_objInfo,text="Render Layer",bg=color_dark3, fg=color_font1)
  460. obj_title_items8.place(x=tmpX,y=tmpY)
  461. obj_entry_rlayer = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  462. obj_entry_rlayer.place(x=tmpX,y=tmpY+22)
  463.  
  464. ##
  465. obj_title_ObjTPanel = Label(Pdown_objInfo, text='Object Transform Panel', bg=color_dark3, fg=color_font2)
  466. obj_title_ObjTPanel.place(x=0,y=32+defaultSpacer*3)
  467.  
  468. tmpX,tmpY = 32, 64+defaultSpacer*3
  469. obj_title_items9 = Label(Pdown_objInfo,text="Position",bg=color_dark3, fg=color_font1)
  470. obj_title_items9.place(x=tmpX,y=tmpY)
  471. obj_entry_posX = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  472. obj_entry_posX.place(x=tmpX,y=tmpY+22)
  473. obj_entry_posY = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  474. obj_entry_posY.place(x=tmpX,y=tmpY+22+22)
  475.  
  476. tmpX,tmpY = 32+120, 64+defaultSpacer*3
  477. obj_title_items10 = Label(Pdown_objInfo,text="Scale",bg=color_dark3, fg=color_font1)
  478. obj_title_items10.place(x=tmpX,y=tmpY)
  479. obj_entry_scaleX = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  480. obj_entry_scaleX.place(x=tmpX,y=tmpY+22)
  481. obj_entry_scaleY = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  482. obj_entry_scaleY.place(x=tmpX,y=tmpY+22+22)
  483.  
  484. tmpX,tmpY = 32+120*2, 64+defaultSpacer*3
  485. obj_title_items11 = Label(Pdown_objInfo,text="Rotation",bg=color_dark3, fg=color_font1)
  486. obj_title_items11.place(x=tmpX,y=tmpY)
  487. obj_entry_rot = Entry(Pdown_objInfo,bg=color_white1,fg=color_font1, justify=CENTER,width=16)
  488. obj_entry_rot.place(x=tmpX,y=tmpY+22)
  489.  
  490.  
  491. def ObjInfoUpdate():
  492.     if currentScene != None and selectedObject != None:
  493.  
  494.         obj_entry_scaleX.delete(0, END)
  495.         obj_entry_scaleX.insert(END, str(selectedObject[0]['scale'][0]))
  496.         obj_entry_scaleY.delete(0, END)
  497.         obj_entry_scaleY.insert(END, str(selectedObject[0]['scale'][1]))
  498.         obj_entry_posX.delete(0, END)
  499.         obj_entry_posX.insert(END, str(selectedObject[0]['position'][0]))
  500.         obj_entry_posY.delete(0, END)
  501.         obj_entry_posY.insert(END, str(selectedObject[0]['position'][1]))
  502.         obj_entry_rot.delete(0, END)
  503.         obj_entry_rot.insert(END, str(selectedObject[0]['rotation'][0]))
  504.  
  505.         obj_entry_oname.delete(0, END)
  506.         obj_entry_oname.insert(END, str(selectedObject[0]['name']))
  507.         obj_entry_col.delete(0, END)
  508.         obj_entry_col.insert(END, str(selectedObject[0]['collision']))
  509.         obj_entry_dynamic.delete(0, END)
  510.         obj_entry_dynamic.insert(END, str(selectedObject[0]['dynamic']))
  511.  
  512.         #prepareClass = str(selectedObject[0]['objectClass'])
  513.         #prepareClass.replace('[','')
  514.         #prepareClass.replace(']','')
  515.         obj_entry_class.delete(0, END)
  516.         obj_entry_class.insert(END, str(selectedObject[0]['objectClass']))
  517.         #obj_entry_mat.delete(0, END)
  518.         #obj_entry_mat.insert(END, str(selectedObject[0]['material']))
  519.  
  520.         #obj_SelectedMat = StringVar()
  521.         obj_SelectedMat.set(str(selectedObject[0]['material']))
  522.         #optionList = ["None"]
  523.  
  524.         obj_entry_par.delete(0, END)
  525.         obj_entry_par.insert(END, str(selectedObject[0]['parent']))
  526.         #obj_entry_color.delete(0, END)
  527.         #obj_entry_color.insert(END, str(selectedObject[0]['color']))
  528.         obj_entry_rlayer.delete(0, END)
  529.         obj_entry_rlayer.insert(END,str(selectedObject[0]['renderLayer']))
  530.  
  531. from tkinter import _setit
  532.  
  533. def ObjInfoSync():
  534.     global optionList, obj_entry_mat
  535.     global scenes
  536.     try:
  537.         #obj_SelectedMat = StringVar()
  538.         #obj_SelectedMat.set(str(selectedObject[0]['material']))
  539.         optionList = ["None"]# + scenes[currentSceneId]['textures']
  540.         for obj in scenes[currentSceneId]['textures']:
  541.             optionList.append(obj)
  542.         #print(optionList)
  543.         obj_entry_mat['menu'].delete(0,END)#.config(Pdown_objInfo, obj_SelectedMat, *optionList)
  544.         for obj in optionList:
  545.             obj_entry_mat['menu'].add_command(label=obj,command=_setit(obj_SelectedMat, obj))
  546.  
  547.         scenes[currentSceneId]['objects'][selectedObject[1]]['name']         = str(obj_entry_oname.get())
  548.         scenes[currentSceneId]['objects'][selectedObject[1]]['collision']    = bool(obj_entry_col.get())
  549.         scenes[currentSceneId]['objects'][selectedObject[1]]['dynamic']      = bool(obj_entry_dynamic.get())
  550.         scenes[currentSceneId]['objects'][selectedObject[1]]['objectClass']  = obj_entry_class.get()
  551.         scenes[currentSceneId]['objects'][selectedObject[1]]['material']     = str(obj_SelectedMat.get())#str(obj_entry_mat.get())
  552.         #print(obj_SelectedMat.get())
  553.         scenes[currentSceneId]['objects'][selectedObject[1]]['parent']       = str(obj_entry_par.get())
  554.         #scenes[currentSceneId]['objects'][selectedObject[1]]['color']        = str(obj_entry_color.get())
  555.         scenes[currentSceneId]['objects'][selectedObject[1]]['renderLayer']  = int(obj_entry_rlayer.get())
  556.         scenes[currentSceneId]['objects'][selectedObject[1]]['position']     = [float(obj_entry_posX.get()),float(obj_entry_posY.get())]
  557.         scenes[currentSceneId]['objects'][selectedObject[1]]['scale']        = [float(obj_entry_scaleX.get()),float(obj_entry_scaleY.get())]
  558.         scenes[currentSceneId]['objects'][selectedObject[1]]['rotation']     = [float(obj_entry_rot.get())]
  559.     except:
  560.         pass#ObjInfoUpdate()
  561.  
  562. ###########################################################
  563. ####   SCENE OBJECTS TAB
  564. ot_title_sceneOb = Label(Paned_sceneObj, text='      Scene Objects:', bg=color_dark2, fg=color_font2)
  565. ot_title_sceneOb.place(x=0,y=0)
  566.  
  567. ot_entry_selected = Entry(Paned_sceneObj,bg=color_white1,fg=color_font1, justify=CENTER,width=20)
  568. ot_entry_selected.place(x=0, y=22)
  569.  
  570. def Command_NewObject():#(obName=str(ot_entry_selected.get())):
  571.     global scenes, selectedObject
  572.     obName = str(ot_entry_selected.get())
  573.     if obName != '':
  574.         repeater = True
  575.         value = 0
  576.         while repeater:
  577.             if value > 0:
  578.                 try:
  579.                     vesef = obName.split('.')
  580.                     vesef = int(vesef[len(vesef)-1])
  581.                     newName = obName.replace(str(vesef), '')
  582.                     newName = newName+str(value+vesef)
  583.                 except:
  584.                     newName = str(obName)+'.'+str(value)
  585.             else:
  586.                 newName = str(obName)
  587.             selLikeThis = [ [obj, num] for num, obj in enumerate(scenes[currentSceneId]['objects']) if obj['name'] == newName]
  588.             if len(selLikeThis) > 0:
  589.                 value += 1
  590.             else:
  591.                 repeater = False
  592.  
  593.         newObj = {'name':newName,
  594.                  'collision':False,
  595.                  'dynamic':False,
  596.                  'objectClass':'',
  597.                  'material':None,
  598.                  'parent':None,
  599.                  'color':'#e6e6e6',
  600.                  'renderLayer':2,
  601.                  'position':[128.0,128.0],
  602.                  'scale':[256.0,256.0],
  603.                  'rotation':[0.0]}
  604.         #newObj = defaultObject
  605.         #newObj['name'] = newName
  606.         scenes[currentSceneId]['objects'].append(newObj)
  607.         print('added')
  608.         ot_entry_selected.delete(0, END)
  609.         ot_entry_selected.insert(END, newName)
  610.  
  611. def Command_DeleteObject():
  612.     global scenes, selectedObject
  613.     obName = str(ot_entry_selected.get())
  614.     if obName != '':
  615.         selLikeThis = [ [obj, num] for num, obj in enumerate(scenes[currentSceneId]['objects']) if obj['name'] == obName]
  616.         if len(selLikeThis) > 0:
  617.             scenes[currentSceneId]['objects'].remove(selLikeThis[0][0])
  618.             selectedObject = None
  619.             print('removed')
  620.         else:
  621.             print('nothing to remove')
  622.  
  623. ot_button_add = Button(Paned_sceneObj, text='New', command=Command_NewObject, bg=color_dark1, fg=color_font2, width=16)
  624. ot_button_add.place(x=0,y=42)
  625.  
  626. ot_button_delete = Button(Paned_sceneObj, text='Delete',command=Command_DeleteObject, bg=color_dark1, fg=color_font2, width=16)
  627. ot_button_delete.place(x=0,y=68)
  628.  
  629. ot_list_obj = Listbox(Paned_sceneObj, bg=color_dark2, fg=color_font2, activestyle='none', borderwidth=0, height=128)
  630. ot_list_obj.place(x=0,y=96)
  631.  
  632. def SceneObjectsUpdate():
  633.     lst = ot_list_obj.get(ACTIVE)
  634.     if lst != ' #Object List:':
  635.         ot_entry_selected.delete(0, END)
  636.         ot_entry_selected.insert(END, lst)
  637.     ot_list_obj.delete(0, END)
  638.     ot_list_obj.insert(END, ' #Object List:')
  639.     if currentScene != None:
  640.         for obj in currentScene['objects']:
  641.             ot_list_obj.insert(END, obj['name'])
  642.  
  643. def SceneObjectsSync():
  644.     global selectedObject, scenes
  645.  
  646.     if currentScene != None:
  647.         selLikeThis = [ [obj, num] for num, obj in enumerate(scenes[currentSceneId]['objects']) if obj['name'] == str(ot_entry_selected.get())]
  648.         if len(selLikeThis) > 0:
  649.             selectedObject = selLikeThis[0]
  650.         #else:
  651.         #    #ot_entry_selected.delete(0, END)
  652.         #    try:
  653.         #        ot_entry_selected.insert(END, selectedObject[0]['name'])
  654.         #    except:
  655.         #        selectedObject = None
  656.  
  657. ##################################################################
  658. ##                       LOGIC NODES GUI                        ##
  659. ##################################################################
  660. nodeSizeX = 128
  661. nodeSizeY = 32
  662.  
  663. nodeCam = [0,0]
  664. nodeZoom = 1.0
  665.  
  666. nodeList = []
  667. nodeLogic = [] # Sensors        |   Verify
  668. nodeCont  = [] # Controllers    |   Confirm
  669. nodeAct   = [] # Actuators      |   Action
  670. nodeConnect = []
  671.  
  672. Type_Verify  = 'keyevent,mouseevent,mousepos,objpos,prop,ray'.split(',')
  673. Type_Confirm = 'and,or,compare,not'.split(',')
  674. Type_Action  = 'endobj,replace,move,scale,add,propmath,propset'.split(',')
  675.  
  676. mousePos = [0,0]
  677. MMB_Click= False
  678. RMB_Click= False
  679. LCTRL_press = False
  680.  
  681. lastMousePos = [0,0]
  682. MMB_on = False
  683. DragNode = None
  684. RMB_tap = False
  685.  
  686. #### NODE LINES:
  687. lineInput = None
  688. def Node_drawLine(line):
  689.     global nodeLogic, nodeConnect
  690.  
  691.     # line = [entry1, entry2]
  692.     obA = [ob for ob in [[obj for obj in nodeLogic if obj[0] == line[0]],
  693.                          [obj for obj in nodeCont if obj[0] == line[0]],
  694.                          [obj for obj in nodeAct if obj[0] == line[0]]] if len(ob) > 0]
  695.     obB = [ob for ob in [[obj for obj in nodeLogic if obj[0] == line[1]],
  696.                          [obj for obj in nodeCont if obj[0] == line[1]],
  697.                          [obj for obj in nodeAct if obj[0] == line[1]]] if len(ob) > 0]
  698.     if len(obA) > 0 and len(obB) > 0:
  699.         obA = obA[0]
  700.         obB = obB[0]
  701.         if len(obA) > 0 and len(obB) > 0:
  702.             obA = obA[0][5]
  703.             obB = obB[0][5]
  704.             if obA != obB:
  705.                 nodes.create_line((obA[0]+nodeSizeX)*nodeZoom,obA[1]*nodeZoom, obB[0]*nodeZoom, obB[1]*nodeZoom, fill=color_white1)
  706.             else:
  707.                 nodeConnect.remove(line)
  708.  
  709.         else:
  710.             print(nodeLogic)
  711.             print('Node disconnected: ', line)
  712.             nodeConnect.remove(line)
  713.     else:
  714.         print(nodeLogic)
  715.         print('Node disconnected: ', line)
  716.         nodeConnect.remove(line)
  717.  
  718. def Node_removeLine(entry):
  719.     global nodeConnect
  720.  
  721.     for obj in nodeConnect:
  722.         if entry in obj:
  723.             nodeConnect.remove(obj)
  724.     for obj in nodeCont:
  725.         if entry in obj:
  726.             nodeConnect.remove(obj)
  727.     for obj in nodeAct:
  728.         if entry in obj:
  729.             nodeConnect.remove(obj)
  730.  
  731. #### NODE WINDOWS:
  732. def ResetNode():
  733.     nodes.delete(ALL)
  734.  
  735. def Node_addLogic(entry, type, input, output, extraType, posXY):
  736.     # extratype = caso um node tenha mais de 1 objeto... pra poder diferenciar do tipo. Ex: mouse pos tem x e y...
  737.     global nodeLogic
  738.     toInput = None
  739.     toOutput = None # add: if type = 'obj'
  740.     if input == 'bool':
  741.         toInput='bool'
  742.     elif input == 'float':
  743.         toInput='float'
  744.  
  745.     if output == 'bool':
  746.         toOutput='bool'
  747.     elif output == 'float':
  748.         toOutput='float'
  749.  
  750.     toAdd = [entry, type, toInput, toOutput, extraType, posXY]
  751.  
  752.     if type in Type_Action:
  753.         nodeAct.append(toAdd)
  754.     elif type in Type_Confirm:
  755.         nodeCont.append(toAdd)
  756.     elif type in Type_Verify:
  757.         nodeLogic.append(toAdd)
  758.  
  759. def Node_Primitivenew(posX, posY,type ,**kwargs):
  760.     global nodeList
  761.  
  762.     if 'slots' in kwargs:
  763.         extraScale = 1+kwargs['slots']
  764.     else:
  765.         extraScale = 2
  766.     if 'title' in kwargs:
  767.         windowName = kwargs['title']
  768.     else:
  769.         windowName = '  Empty'
  770.  
  771.     thisNode = {'pos':[posX,posY],'slots':extraScale,'title':windowName}
  772.  
  773.     #nodes.create_rectangle(posX+nodeCam[0], posY+nodeCam[1], posX+nodeSizeX+nodeCam[0], posY+nodeSizeY*extraScale+nodeCam[1], fill=color_dark3)
  774.     #nodes.create_rectangle(posX+nodeCam[0], posY+nodeCam[1], posX+nodeSizeX+nodeCam[0], posY+nodeSizeY+nodeCam[1], fill=color_dark1)
  775.     tmpTitle = Label(nodes, text=windowName, bg=color_dark1, fg=color_font2)
  776.     #tmpTitle.place(x=posX+nodeCam[0]+6, y=posY+nodeCam[1]+6)
  777.     thisNode['titleText'] = tmpTitle
  778.  
  779.     nodeList.append(thisNode)
  780.  
  781. def Node_new(posx, posy, type, **kwargs):
  782.     global nodeList
  783.  
  784.     if 'slots' in kwargs:
  785.         extraScale = 1+kwargs['slots']
  786.     else:
  787.         extraScale = 2
  788.     if 'title' in kwargs:
  789.         windowName = kwargs['title']
  790.     else:
  791.         windowName = '  Empty'
  792.  
  793.     thisNode = {'pos':[posx,posy],'slots':1,'title':'Empty','type':None,'entry':[],'titleText':None}
  794.  
  795.     #nodes.create_rectangle(posX+nodeCam[0], posY+nodeCam[1], posX+nodeSizeX+nodeCam[0], posY+nodeSizeY*extraScale+nodeCam[1], fill=color_dark3)
  796.     #nodes.create_rectangle(posX+nodeCam[0], posY+nodeCam[1], posX+nodeSizeX+nodeCam[0], posY+nodeSizeY+nodeCam[1], fill=color_dark1)
  797.     #tmpTitle = Label(nodes, text=windowName, bg=color_dark1, fg=color_font2)
  798.     #tmpTitle.place(x=posX+nodeCam[0]+6, y=posY+nodeCam[1]+6)
  799.     #thisNode['titleText'] = tmpTitle
  800.  
  801.     #nodeList.append(thisNode)
  802.  
  803.     if type == 'Empty':
  804.         thisNode['title'] = 'Empty'
  805.         thisNode['type'] = None
  806.  
  807.     elif type == 'keyevent':
  808.         thisNode['title'] = 'Keyboard event'
  809.         thisNode['type'] = type #'keyevent'
  810.         thisNode['entry'] = []
  811.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  812.         tmpEnt = [tmpEntry, [],['bool'],'ok']
  813.         thisNode['entry'].append(tmpEnt)
  814.  
  815.     elif type == 'mouseevent':
  816.         thisNode['title'] = 'Mouse event'
  817.         thisNode['type'] = type
  818.         thisNode['entry'] = []
  819.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  820.         tmpEnt = [tmpEntry, [],['bool'],'ok']
  821.         thisNode['entry'].append(tmpEnt)
  822.  
  823.     elif type == 'mousepos':
  824.         thisNode['title'] = 'Mouse Position'
  825.         thisNode['type'] = type
  826.         thisNode['entry'] = []
  827.         tmpX = Label(nodes,bg=color_dark3,fg=color_font2, text='Mouse X pos')
  828.         tmpEntX = [tmpX, [],['float'],'x']
  829.         tmpY = Label(nodes,bg=color_dark3,fg=color_font2, text='Mouse Y pos')
  830.         tmpEntY = [tmpY, [],['float'],'y']
  831.         thisNode['entry'].append(tmpEntX)
  832.         thisNode['entry'].append(tmpEntY)
  833.  
  834.     elif type == 'objpos':
  835.         thisNode['title'] = 'Object Position'
  836.         thisNode['type'] = type
  837.         thisNode['entry'] = []
  838.         tmpObj = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  839.         tmpEntObj = [tmpObj, [],[],'ok']
  840.         tmpX = Label(nodes,bg=color_dark3,fg=color_font2, text='Object X')
  841.         tmpEntX = [tmpX, [],['float'],['x',tmpObj]]
  842.         tmpY = Label(nodes,bg=color_dark3,fg=color_font2, text='Object Y')
  843.         tmpEntY = [tmpY, [],['float'],['y',tmpObj]]
  844.         thisNode['entry'].append(tmpEntObj)
  845.         thisNode['entry'].append(tmpEntX)
  846.         thisNode['entry'].append(tmpEntY)
  847.  
  848.     elif type == 'prop':
  849.         thisNode['title'] = 'Float'
  850.         thisNode['type'] = type
  851.         thisNode['entry'] = []
  852.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  853.         tmpEnt = [tmpEntry, [],['float'],'ok']
  854.         thisNode['entry'].append(tmpEnt)
  855.  
  856.     elif type == 'ray':
  857.         thisNode['title'] = 'Ray'
  858.         thisNode['type'] = type
  859.         thisNode['entry'] = []
  860.         tmpX = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  861.         tmpEntX = [tmpX, [],[],'x']
  862.         tmpY = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  863.         tmpEntY = [tmpY, [],[],'y']
  864.         tmpObj = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  865.         tmpEntObj = [tmpObj, [],['bool'],['ok',tmpX,tmpY]]
  866.         thisNode['entry'].append(tmpEntObj)
  867.         thisNode['entry'].append(tmpEntX)
  868.         thisNode['entry'].append(tmpEntY)
  869.  
  870.     ###############################################################################################################
  871.  
  872.     elif type == 'and':
  873.         thisNode['title'] = 'AND'
  874.         thisNode['type'] = type
  875.         thisNode['entry'] = []
  876.         tmpEntry = Label(nodes,bg=color_dark3,fg=color_font2, text=' ')
  877.         tmpEnt = [tmpEntry, ['bool'],['bool'],'ok']
  878.         thisNode['entry'].append(tmpEnt)
  879.  
  880.     elif type == 'or':
  881.         thisNode['title'] = 'OR'
  882.         thisNode['type'] = type
  883.         thisNode['entry'] = []
  884.         tmpEntry = Label(nodes,bg=color_dark3,fg=color_font2, text=' ')
  885.         tmpEnt = [tmpEntry, ['bool'],['bool'],'ok']
  886.         thisNode['entry'].append(tmpEnt)
  887.  
  888.     elif type == 'not':
  889.         thisNode['title'] = 'NOT'
  890.         thisNode['type'] = type
  891.         thisNode['entry'] = []
  892.         tmpEntry = Label(nodes,bg=color_dark3,fg=color_font2, text=' ')
  893.         tmpEnt = [tmpEntry, ['bool'],['bool'],'ok']
  894.         thisNode['entry'].append(tmpEnt)
  895.  
  896.     elif type == 'compare':
  897.         thisNode['title'] = 'Compare'
  898.         thisNode['type'] = type
  899.         thisNode['entry'] = []
  900.         tmpAddNum = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  901.         tmpNum = [tmpAddNum, ['float'],[],'x']
  902.         tmpAddNumY = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  903.         tmpNumY = [tmpAddNumY, ['float'],[],'y']
  904.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  905.         tmpEnt = [tmpEntry, [],['bool'],['ok',tmpAddNum, tmpAddNumY]]
  906.         thisNode['entry'].append(tmpNum)
  907.         thisNode['entry'].append(tmpEnt)
  908.         thisNode['entry'].append(tmpNumY)
  909.  
  910.     ###############################################################################################################
  911.  
  912.     elif type == 'endobj':
  913.         thisNode['title'] = 'End Object'
  914.         thisNode['type'] = type
  915.         thisNode['entry'] = []
  916.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  917.         tmpEnt = [tmpEntry, ['bool'],[],'ok']
  918.         thisNode['entry'].append(tmpEnt)
  919.  
  920.     elif type == 'replace':
  921.         thisNode['title'] = 'Replace Mat'
  922.         thisNode['type'] = type
  923.         thisNode['entry'] = []
  924.         tmpAddNum = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  925.         tmpNum = [tmpAddNum, [],[],'ok']
  926.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  927.         tmpEnt = [tmpEntry, ['bool'],[],['ok',tmpAddNum]]
  928.         thisNode['entry'].append(tmpEnt)
  929.         thisNode['entry'].append(tmpNum)
  930.  
  931.     elif type == 'move':
  932.         thisNode['title'] = 'Move Object'
  933.         thisNode['type'] = type
  934.         thisNode['entry'] = []
  935.         tmpAddNum = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  936.         tmpNum = [tmpAddNum, [],[],'x']
  937.         tmpAddNumY = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  938.         tmpNumY = [tmpAddNumY, [],[],'y']
  939.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  940.         tmpEnt = [tmpEntry, ['bool'],[],['ok',tmpAddNum, tmpAddNumY]]
  941.         thisNode['entry'].append(tmpEnt)
  942.         thisNode['entry'].append(tmpNum)
  943.         thisNode['entry'].append(tmpNumY)
  944.  
  945.     elif type == 'scale':
  946.         thisNode['title'] = 'Set Scale'
  947.         thisNode['type'] = type
  948.         thisNode['entry'] = []
  949.         tmpAddNum = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  950.         tmpNum = [tmpAddNum, [],[],'x']
  951.         tmpAddNumY = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  952.         tmpNumY = [tmpAddNumY, [],[],'y']
  953.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  954.         tmpEnt = [tmpEntry, ['bool'],[],['ok',tmpAddNum, tmpAddNumY]]
  955.         thisNode['entry'].append(tmpEnt)
  956.         thisNode['entry'].append(tmpNum)
  957.         thisNode['entry'].append(tmpNumY)
  958.  
  959.     elif type == 'add':
  960.         thisNode['title'] = 'Add Object'
  961.         thisNode['type'] = type
  962.         thisNode['entry'] = []
  963.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  964.         tmpEnt = [tmpEntry, ['bool'],[],'ok']
  965.         thisNode['entry'].append(tmpEnt)
  966.  
  967.     elif type == 'propmath':
  968.         thisNode['title'] = 'Prop Math'
  969.         thisNode['type'] = type
  970.         thisNode['entry'] = []
  971.         tmpAddNum = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  972.         tmpNum = [tmpAddNum, [],[],'ok']
  973.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  974.         tmpEnt = [tmpEntry, ['bool'],[],['ok',tmpAddNum]]
  975.         thisNode['entry'].append(tmpEnt)
  976.         thisNode['entry'].append(tmpNum)
  977.  
  978.     elif type == 'propset':
  979.         thisNode['title'] = 'Set Prop'
  980.         thisNode['type'] = type
  981.         thisNode['entry'] = []
  982.         tmpAddNum = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  983.         tmpNum = [tmpAddNum, [],[],'ok']
  984.         tmpEntry = Entry(nodes,bg=color_white1,fg=color_font1, justify=CENTER,width=19 )
  985.         tmpEnt = [tmpEntry, ['bool'],[],['ok',tmpAddNum]]
  986.         thisNode['entry'].append(tmpEnt)
  987.         thisNode['entry'].append(tmpNum)
  988.  
  989.     a = thisNode['title']
  990.     #print(a)
  991.     tmpTitle = Label(nodes, text=a, bg=color_dark1, fg=color_font2)
  992.     thisNode['titleText'] = tmpTitle
  993.  
  994.     nodeList.append(thisNode)
  995.  
  996. def Node_BasicDraw(node):
  997.     global nodeList, lineInput, nodeConnect
  998.  
  999.     posX = node['pos'][0]
  1000.     posY = node['pos'][1]
  1001.     try:
  1002.         extraScale = len(node['entry'])+1
  1003.     except:
  1004.         extraScale = node['slots']+1
  1005.     tmpTitle = node['titleText']
  1006.  
  1007.     nodes.create_rectangle((posX+nodeCam[0])*nodeZoom,
  1008.                            (posY+nodeCam[1])*nodeZoom,
  1009.                             (posX+nodeSizeX+nodeCam[0])*nodeZoom,
  1010.                              (posY+nodeSizeY*extraScale+nodeCam[1])*nodeZoom, fill=color_dark3)
  1011.     nodes.create_rectangle((posX+nodeCam[0])*nodeZoom,
  1012.                            (posY+nodeCam[1])*nodeZoom,
  1013.                             (posX+nodeSizeX+nodeCam[0])*nodeZoom,
  1014.                              (posY+nodeSizeY+nodeCam[1])*nodeZoom, fill=color_dark1)
  1015.     #tmpTitle = Label(nodes, text=windowName, bg=color_dark1, fg=color_font2)
  1016.     tmpTitle.place(x=posX+nodeCam[0]+6, y=posY+nodeCam[1]+6)
  1017.  
  1018.     if node['type'] != None:
  1019.         for i, obj in enumerate(node['entry']):
  1020.             obj[0].place(x=posX+nodeCam[0]+6, y=posY+nodeCam[1]+nodeSizeY*(i+1)+6)
  1021.             if obj[1] != []:
  1022.                 nodes.create_rectangle((posX+nodeCam[0]-4)*nodeZoom,  (posY+nodeCam[1]+nodeSizeY*(i+1)+8)*nodeZoom,
  1023.                                         (posX+nodeCam[0]+4)*nodeZoom,  (posY+nodeCam[1]+nodeSizeY*(i+1)+16)*nodeZoom,
  1024.                                        fill=color_pine1)
  1025.                 # Verificar se esta sendo arrastada uma linha ate algum input
  1026.                 if mousePos[0] > (posX+nodeCam[0]-4)*nodeZoom and mousePos[1] > (posY+nodeCam[1]+nodeSizeY*(i+1)+8)*nodeZoom:
  1027.                     if mousePos[0] < (posX+nodeCam[0]+4)*nodeZoom and mousePos[1] < (posY+nodeCam[1]+nodeSizeY*(i+1)+16)*nodeZoom:
  1028.                         if lineInput != None:
  1029.                             nodeConnect.append([lineInput, obj[0]])
  1030.                             print(nodeConnect)
  1031.                             lineInput = None
  1032.                         if RMB_Click and LCTRL_press:
  1033.                             Node_removeLine(obj[0])
  1034.  
  1035.  
  1036.  
  1037.                 toaddA = obj[1][0]
  1038.             else:
  1039.                 toaddA = None
  1040.             if obj[2] != []:
  1041.                 nodes.create_rectangle((posX+nodeCam[0]-4+nodeSizeX)*nodeZoom,  (posY+nodeCam[1]+nodeSizeY*(i+1)+8)*nodeZoom,
  1042.                                         (posX+nodeCam[0]+4+nodeSizeX)*nodeZoom,  (posY+nodeCam[1]+nodeSizeY*(i+1)+16)*nodeZoom,
  1043.                                        fill=color_pine1)
  1044.                 # Verificar se o mousle esta em cima
  1045.                 if lineInput == None:
  1046.                     if mousePos[0] > (posX+nodeCam[0]-4+nodeSizeX)*nodeZoom and mousePos[1] > (posY+nodeCam[1]+nodeSizeY*(i+1)+8)*nodeZoom:
  1047.                         if mousePos[0] < (posX+nodeCam[0]+4+nodeSizeX)*nodeZoom and mousePos[1] < (posY+nodeCam[1]+nodeSizeY*(i+1)+16)*nodeZoom:
  1048.                             lineInput = obj[0] # Mouse esta em cima!
  1049.                 toaddB = obj[2][0]
  1050.             else:
  1051.                 toaddB = None
  1052.  
  1053.             # ADD NODE TO LOGIC HERE!
  1054.             #if not node['type'] in ['compare']:
  1055.             Node_addLogic(obj[0], node['type'], toaddA, toaddB, obj[3], [posX+nodeCam[0],  posY+nodeCam[1]+nodeSizeY*(i+1)+12])
  1056.  
  1057. def Node_RemoveNode(nod):
  1058.     global nodeList
  1059.  
  1060.     #nod['titleText'].grid(row=5,column=5)
  1061.     nod['titleText'].destroy()
  1062.     for obj in nod['entry']:
  1063.         obj[0].destroy()
  1064.         #obj.grid(row=5,column=5)
  1065.         #obj.pack_forget()
  1066.     nodeList.remove(nod)
  1067.  
  1068. def UpdateNode():
  1069.     global MMB_on, lastMousePos, nodeCam, MMB_Click, RMB_Click, DragNode, nodeList, RMB_tap, nodeLogic, nodeCont, nodeAct, lineInput
  1070.  
  1071.     # Limpar nodes pra desenhar de novo
  1072.     ResetNode()
  1073.     nodeLogic = []
  1074.     nodeCont = []
  1075.     nodeAct = []
  1076.  
  1077.     # Redesenhar todos os nodes
  1078.     for node in nodeList:
  1079.         Node_BasicDraw(node) # {'pos':[posX,posY],'slots':extraScale,'title':windowName}
  1080.         if RMB_Click:
  1081.             if DragNode == None and lineInput ==None:
  1082.                 if mousePos[0] > node['pos'][0]+nodeCam[0] and mousePos[1] > node['pos'][1]+nodeCam[1]:
  1083.                     if mousePos[0] < node['pos'][0]+nodeCam[0]+nodeSizeX and mousePos[1] < node['pos'][1]+nodeCam[1]+nodeSizeY:
  1084.                         # Ta dentro do node!
  1085.                         if LCTRL_press:
  1086.                             Node_RemoveNode(node) # Delete Node!
  1087.                         else:
  1088.                             DragNode = node
  1089.                             lastMousePos = mousePos
  1090.                             #RMB_Click = False
  1091.  
  1092.     # Redesenha todas as linhas
  1093.     for line in nodeConnect:
  1094.         Node_drawLine(line)
  1095.  
  1096.     if not RMB_Click:
  1097.         DragNode = None
  1098.  
  1099.     if lineInput != None:
  1100.         if not RMB_Click:
  1101.             lineInput = None
  1102.             #print('rmb')
  1103.             #pass
  1104.         else:
  1105.             #print('ue')
  1106.             obA = [obj for obj in nodeLogic+nodeCont+nodeAct if obj[0] == lineInput]
  1107.             #obA = [ob for ob in [[obj for obj in nodeLogic if obj[0] == lineInput],
  1108.                                  #[obj for obj in nodeCont if obj[0] == lineInput],
  1109.                                  #[obj for obj in nodeAct if obj[0] == lineInput]] if len(ob) > 0]
  1110.             #print(lineInput,nodeLogic+nodeCont+nodeAct)
  1111.             try:
  1112.                 obA = obA[0][5]
  1113.                 nodes.create_line(obA[0]+nodeSizeX,obA[1], mousePos[0], mousePos[1], fill=color_white1)
  1114.                 #print('ue')
  1115.             except:
  1116.                 lineInput = None
  1117.                 #print('closed')
  1118.  
  1119.     if DragNode == None:
  1120.         if MMB_Click and lineInput == None:
  1121.             if RMB_tap == False:
  1122.                 lastMousePos = mousePos
  1123.                 RMB_tap = True
  1124.             if lastMousePos[1] > 0 and lastMousePos[0]> 0: # Dentro do nodes
  1125.                 newPos = mousePos
  1126.                 somaX = lastMousePos[0]-newPos[0]
  1127.                 somaY = lastMousePos[1]-newPos[1]
  1128.  
  1129.                 nodeCam[0] -= somaX
  1130.                 nodeCam[1] -= somaY
  1131.                 lastMousePos = newPos
  1132.         else:
  1133.             RMB_tap = False
  1134.     else:
  1135.         newPos = mousePos
  1136.         somaX = lastMousePos[0]-newPos[0]
  1137.         somaY = lastMousePos[1]-newPos[1]
  1138.  
  1139.         nodeList.remove(DragNode)
  1140.         DragNode['pos'][0] -= somaX
  1141.         DragNode['pos'][1] -= somaY
  1142.         lastMousePos = newPos
  1143.         nodeList.append(DragNode)
  1144.  
  1145. def PopupAdd(item):
  1146.     Node_new(mousePos[0]-nodeCam[0], mousePos[1]-nodeCam[1], item)
  1147.  
  1148. nodeTypes = Type_Action+Type_Confirm+Type_Verify#['keyboard','mousepos','float','bool','mouseover','mouse','getpos',
  1149.              #'getscale','getrot','pointover','endobj','move','rotate','setscale',
  1150.              #'compare']
  1151.  
  1152. popMenu = Menu(nodes, tearoff=0)
  1153.  
  1154. Menu_Verify = Menu(popMenu, tearoff=0)
  1155. toeval = ""
  1156. for obj in Type_Verify:
  1157.     toeval +="Menu_Verify.add_command(label=str('"+obj+"'),command=lambda: PopupAdd(str('"+obj+"')))\n"
  1158. exec(toeval)
  1159.  
  1160. Menu_Confirm = Menu(popMenu, tearoff=0)
  1161. toeval = ""
  1162. for obj in Type_Confirm:
  1163.     toeval +="Menu_Confirm.add_command(label=str('"+obj+"'),command=lambda: PopupAdd(str('"+obj+"')))\n"
  1164. exec(toeval)
  1165.  
  1166. Menu_Action = Menu(popMenu, tearoff=0)
  1167. toeval = ""
  1168. for obj in Type_Action:
  1169.     toeval +="Menu_Action.add_command(label=str('"+obj+"'),command=lambda: PopupAdd(str('"+obj+"')))\n"
  1170. exec(toeval)
  1171.  
  1172. popMenu.add_cascade(label='Verify',menu=Menu_Verify)
  1173. popMenu.add_cascade(label='Confirm',menu=Menu_Confirm)
  1174. popMenu.add_cascade(label='Action',menu=Menu_Action)
  1175.  
  1176. def PopupCreateMenu(event):
  1177.     popMenu.post(event.x_root, event.y_root)
  1178.  
  1179. nodes.bind('<Button-3>', PopupCreateMenu)
  1180.  
  1181. #Node_new(10,10, 'keyboard')
  1182. #Node_new(300,20, 'compare')
  1183.  
  1184.  
  1185. def FmousePos(event):
  1186.     global mousePos
  1187.     x,y = event.x, event.y
  1188.     mousePos = [x,y]
  1189. nodes.bind('<Motion>', FmousePos)
  1190.  
  1191. def FMMB(event):
  1192.     global MMB_Click
  1193.     MMB_Click = True
  1194. nodes.bind("<Button-2>", FMMB)
  1195.  
  1196. def FRMB(event):
  1197.     global RMB_Click
  1198.     RMB_Click = True
  1199. nodes.bind("<Button-1>", FRMB)
  1200. # <ButtonRelease-1>
  1201.  
  1202. def FMMB_re(event):
  1203.     global MMB_Click
  1204.     MMB_Click = False
  1205. nodes.bind("<ButtonRelease-2>", FMMB_re)
  1206.  
  1207. def FRMB_re(event):
  1208.     global RMB_Click
  1209.     RMB_Click = False
  1210. nodes.bind("<ButtonRelease-1>", FRMB_re)
  1211.  
  1212. def LCTRL(event):
  1213.     global LCTRL_press
  1214.     LCTRL_press = True
  1215. nodes.bind("<Key-Control_L>",LCTRL)
  1216.  
  1217. def LCTRL_re(event):
  1218.     global LCTRL_press
  1219.     LCTRL_press = False
  1220. nodes.bind("<KeyRelease-Control_L>",LCTRL_re)
  1221. nodes.focus_set()
  1222.  
  1223. ##################################################################
  1224. ##                      ENGINE VIEW CONTROL                     ##
  1225. ##################################################################
  1226. ## Inicio em 06/06/2016
  1227. pygame.font.init()
  1228. font_default = pygame.font.SysFont('arial', 15)
  1229.  
  1230. wireframe = False
  1231. viewPos = [0,0]
  1232. Obj_Drag = False
  1233. Mouse_Last = [0,0]
  1234. View_Lmb = 2
  1235.  
  1236. def View_ConfigureObjects(): # pra evitar que o usuario coloque coisas erradas nas variaveis
  1237.     global wireframe, scenes, viewPos
  1238.     wireframe = currentScene['wireframe']
  1239.  
  1240.     if currentScene != None:
  1241.         viewPos = [-scenes[currentSceneId]['cameraPos'][0], -scenes[currentSceneId]['cameraPos'][1]]
  1242.  
  1243.         for obj in scenes[currentSceneId]['objects']:
  1244.             if not obj['renderLayer'] in [1,2,3,4]:
  1245.                 if obj['renderLayer'] in '1234':
  1246.                     obj['renderLayer'] = int(obj['renderLayer'])
  1247.                 else:
  1248.                     obj['renderLayer'] = 2
  1249.                 print('changed Render Layer')
  1250.  
  1251. def View_HexToRGB(hex):
  1252.     """ convert #RRGGBB to an (R, G, B) tuple """
  1253.     try:
  1254.         colorstring = hex.strip()
  1255.         if colorstring[0] == '#': colorstring = colorstring[1:]
  1256.         #if len(colorstring) != 6:
  1257.         #    raise ValueError, "input #%s is not in #RRGGBB format" % hex
  1258.         r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:]
  1259.         r, g, b = [int(n, 16) for n in (r, g, b)]
  1260.         return (r, g, b)
  1261.     except:
  1262.         return(0,0,0)
  1263.  
  1264. def View_DrawDebug(fps):
  1265.     text = ''
  1266.     if inGame: # Game running
  1267.         text += '('+str(int(fps*10)/10)+' FPS)'+' Game Engine Running...'
  1268.         debugger = font_default.render(text, 1, (255,255,255))
  1269.         screen.blit(debugger, (10,10))
  1270.     else:
  1271.         text += '('+str(int(fps*10)/10)+' FPS)'+' Game Editor'
  1272.         debugger = font_default.render(text, 1, (255,255,255))
  1273.         screen.blit(debugger, (10,10))
  1274.  
  1275. def View_DrawGimbal(pos, scale):
  1276.     global Obj_Drag, Mouse_Last
  1277.  
  1278.     color = View_HexToRGB(color_selection)
  1279.     width = 4
  1280.     pygame.draw.polygon(screen, color    , [[pos[0]+viewPos[0]-width,pos[1]+viewPos[1]-width],
  1281.                                             [pos[0]+viewPos[0]+scale[0]+width,pos[1]+viewPos[1]-width],
  1282.                                             [pos[0]+viewPos[0]+scale[0]+width,pos[1]+viewPos[1]+scale[1]+width],
  1283.                                             [pos[0]+viewPos[0]-width,pos[1]+viewPos[1]+scale[1]+width]])
  1284.  
  1285.     gpos = pygame.mouse.get_pos()
  1286.     if Obj_Drag == False:
  1287.         if gpos[0] > pos[0]+viewPos[0]-width and gpos[1] > pos[1]+viewPos[1]-width:
  1288.             if gpos[0] < pos[0]+viewPos[0]+scale[0]+width and gpos[1] < pos[1]+viewPos[1]+scale[1]+width:
  1289.                 Obj_Drag = True
  1290.                 Mouse_Last = gpos
  1291.  
  1292. def View_DrawObject(pos, scale, rot, texture, fullobj):
  1293.     global ot_entry_selected
  1294.  
  1295.     noText = True
  1296.  
  1297.     if texture[0] == '#':
  1298.         color = View_HexToRGB(texture)
  1299.         color = (color[0],color[1],color[2],255)
  1300.         noText = True
  1301.     else:
  1302.         color = View_HexToRGB('#fe01fa')
  1303.         color = (color[0],color[1],color[2],255)
  1304.         noText = False
  1305.  
  1306.     # Se o objeto for o selecionado...
  1307.     if currentScene != None and selectedObject != None:
  1308.         if scenes[currentSceneId]['objects'][selectedObject[1]] == fullobj:
  1309.             View_DrawGimbal(pos, scale)
  1310.  
  1311.     if noText == False: # Renderizar textura
  1312.         try: ####################################################################################################################
  1313.              ## URGENTE: Criar uma opção pra CARREGAR TEXTURAS, pq carrega-las todos os frames deixa tudo lento demais.
  1314.             tempTexture = scenes[currentSceneId]['textures'][texture][0]#pygame.image.load(texture).convert_alpha()
  1315.             tempMat = pygame.transform.scale(tempTexture, (int(scale[0]), int(scale[1])))
  1316.             screen.blit(tempMat,(pos[0]+viewPos[0],pos[1]+viewPos[1]))
  1317.         except:
  1318.             noText = True
  1319.  
  1320.     if wireframe == True:
  1321.         #print(bool(scenes[currentSceneId]['wireframe']))
  1322.         wireColor = View_HexToRGB(color_unselected)
  1323.         pygame.draw.polygon(screen, wireColor,
  1324.                             [[pos[0]+viewPos[0], pos[1]+viewPos[1]], [pos[0]+viewPos[0],pos[1]+scale[1]+viewPos[1]],
  1325.                              [pos[0]+scale[0]+viewPos[0],pos[1]+scale[1]+viewPos[1]], [pos[0]+scale[0]+viewPos[0],pos[1]+viewPos[1]] ], 1)
  1326.         pygame.draw.aaline(screen, wireColor, [pos[0]+viewPos[0], pos[1]+viewPos[1]],
  1327.                            [pos[0]+scale[0]+viewPos[0],pos[1]+scale[1]+viewPos[1]])
  1328.     else:
  1329.         if noText:
  1330.             pygame.draw.polygon(screen, color,
  1331.                                 [[pos[0]+viewPos[0], pos[1]+viewPos[1]], [pos[0]+viewPos[0],pos[1]+scale[1]+viewPos[1]],
  1332.                                  [pos[0]+scale[0]+viewPos[0],pos[1]+scale[1]+viewPos[1]], [pos[0]+scale[0]+viewPos[0],pos[1]+viewPos[1]]])
  1333.  
  1334.     # Selecionar objeto
  1335.         #print('ke')
  1336.         #if fullobj != scenes[currentSceneId]['objects'][selectedObject[1]]:
  1337.         mpos = pygame.mouse.get_pos()
  1338.         #print('wtf')
  1339.         if mpos[0] > pos[0]+viewPos[0] and mpos[1] > pos[1]+viewPos[1]:
  1340.             if mpos[0] < pos[0]+scale[0]+viewPos[0] and mpos[1] < pos[1]+scale[1]+viewPos[1]:
  1341.                 if mc[2]:
  1342.                     ot_entry_selected.delete(0, END)
  1343.                     ot_entry_selected.insert(END, fullobj['name'])
  1344.  
  1345. def View_RenderObjlist(lista):
  1346.  
  1347.     layer_01 = [obj for obj in lista if obj['renderLayer'] == 1]
  1348.     layer_02 = [obj for obj in lista if obj['renderLayer'] == 2]
  1349.     layer_03 = [obj for obj in lista if obj['renderLayer'] == 3]
  1350.     layer_04 = [obj for obj in lista if obj['renderLayer'] == 4]
  1351.  
  1352.     for layers in [layer_01,layer_02,layer_03,layer_04]:
  1353.         for obj in layers:
  1354.             if obj['material'] in [None,'None','']:
  1355.                 texture = obj['color']
  1356.             else:
  1357.                 texture = obj['material']
  1358.                 #print(obj['material'], type(obj['material']))
  1359.             View_DrawObject(obj['position'], obj['scale'], obj['rotation'], texture, obj )
  1360.  
  1361. def View_DragObject():
  1362.     global Obj_Drag, scenes, Mouse_Last
  1363.  
  1364.     if Obj_Drag:
  1365.         if View_Lmb < 2:
  1366.             gpos = pygame.mouse.get_pos()
  1367.             toAddX = Mouse_Last[0]- gpos[0]
  1368.             toAddY = Mouse_Last[1]- gpos[1]
  1369.             if currentScene != None and selectedObject != None:
  1370.                 scenes[currentSceneId]['objects'][selectedObject[1]]['position'][0] -= toAddX
  1371.                 scenes[currentSceneId]['objects'][selectedObject[1]]['position'][1] -= toAddY
  1372.                 Mouse_Last = gpos
  1373.                 ObjInfoUpdate()
  1374.             else:
  1375.                 Obj_Drag = False
  1376.         else:
  1377.             Obj_Drag = False
  1378.  
  1379. ##################################################################
  1380. ##                       GAME ENGINE PLAYER                     ##
  1381. ##################################################################
  1382. game_Info = None
  1383. game_scenes = []
  1384. game_active = None
  1385. game_camera = [0,0]
  1386. game_timer = 0
  1387.  
  1388. logic_sen  = []
  1389. logic_cont = []
  1390. logic_act  = []
  1391. logic_connection = []
  1392.  
  1393. TheLastKey = None
  1394. KeyList = {}
  1395.  
  1396. def UD_Draw(fullobj):
  1397.     haveTexture = False
  1398.     if not fullobj['material'] in [None,"None",""]:
  1399.         haveTexture = True
  1400.     #print(fullobj['name'])
  1401.     if haveTexture:
  1402.         try:
  1403.             tempTexture = game_scenes[game_active]['textures'][fullobj['material']][0]
  1404.             tempMat = pygame.transform.scale(tempTexture, (int(fullobj['scale'][0]), int(fullobj['scale'][1])))
  1405.             screen.blit(tempMat,(fullobj['position'][0]+game_camera[0],fullobj['position'][1]+game_camera[1]))
  1406.         except:
  1407.             haveTexture = False
  1408.     if haveTexture == False:
  1409.         color = View_HexToRGB(fullobj['color'])
  1410.         color = (color[0],color[1],color[2],255)
  1411.         pygame.draw.polygon(screen, color,
  1412.                             [[fullobj['position'][0]+game_camera[0],fullobj['position'][1]+game_camera[1]],
  1413.                              [fullobj['position'][0]+game_camera[0],fullobj['position'][1]+game_camera[1]+fullobj['scale'][1]],
  1414.                              [fullobj['position'][0]+game_camera[0]+fullobj['scale'][0],fullobj['position'][1]+game_camera[1]+fullobj['scale'][1]],
  1415.                              [fullobj['position'][0]+game_camera[0]+fullobj['scale'][0],fullobj['position'][1]+game_camera[1]]])
  1416.  
  1417. def UD_Render():
  1418.     #print('working')
  1419.     for obj in game_scenes[game_active]['objects']:
  1420.         UD_Draw(obj)
  1421.  
  1422. def UD_RunNode(n):
  1423.     global TheLastKey
  1424.     if n[1] == 'keyevent':
  1425.         pressed = False
  1426.         #for event in pygame.event.get():
  1427.         #    if event.type == pygame.KEYDOWN:
  1428.         #        print('parte 1', pygame.key.name(event.key), n[0].get())
  1429.         #        if str(pygame.key.name(event.key)) == n[0].get():
  1430.         #            print(str(pygame.key.name(event.key)), n[0].get())
  1431.         #            pressed = True
  1432.         #            break
  1433.         #print(TheLastKey)
  1434.         #if TheLastKey == n[0].get():
  1435.         #    pressed = True
  1436.         #    TheLastKey = None
  1437.         try:
  1438.             print('go')
  1439.             return(KeyList[n[0].get()][0])
  1440.         except:
  1441.             print(KeyList)
  1442.             return(pressed)
  1443.     elif n[1] == 'mouseevent':
  1444.         pressed = False
  1445.         for event in pygame.event.get():
  1446.             if event.type == pygame.MOUSEBUTTONDOWN:
  1447.                 if str(event.button) == str(n[0].get()):
  1448.                     pressed = True
  1449.                     break
  1450.         return(pressed)
  1451.     elif n[1] == 'mousepos':
  1452.         if n[4] == 'x':
  1453.             return(pygame.mouse.get_pos()[0])
  1454.         else:#elif n[4] == 'y':
  1455.             return(pygame.mouse.get_pos()[1])
  1456.     elif n[1] == 'objpos':
  1457.         if n[4][0] == 'x':
  1458.             entrada = n[4][1].get()
  1459.             objeto = [obj for obj in game_scenes[game_active]['objects'] if obj['name'] == entrada]
  1460.             if len(objeto) > 0: # Encontrou o objeto
  1461.                 objeto = objeto[0]
  1462.                 return(objeto['position'][0])
  1463.         else:#elif n[4][0] == 'y':
  1464.             entrada = n[4][1].get()
  1465.             objeto = [obj for obj in game_scenes[game_active]['objects'] if obj['name'] == entrada]
  1466.             if len(objeto) > 0: # Encontrou o objeto
  1467.                 objeto = objeto[0]
  1468.                 return(objeto['position'][1])
  1469.  
  1470. def UD_ExecNode(n):
  1471.     global game_scenes
  1472.     if n[1] == 'endobj':
  1473.         obName = n[0].get()
  1474.         objetos = [[num, obj] for num, obj in enumerate(game_scenes[game_active]['objects']) if obj['name'] == obName]
  1475.         if len(objetos) > 0:
  1476.             objetos = objetos[0]
  1477.             game_scenes[game_active]['objects'].remove(objetos[1])
  1478.             return(True)
  1479.         else:
  1480.             return(False)
  1481.     elif n[1] == 'move':
  1482.         obName = n[0].get()
  1483.         objetos = [[num, obj] for num, obj in enumerate(game_scenes[game_active]['objects']) if obj['name'] == obName]
  1484.         if len(objetos) > 0:
  1485.             objetos = objetos[0]
  1486.             try:
  1487.                 game_scenes[game_active]['objects'][objetos[0]]['position'][0] += int(n[4][1].get())
  1488.                 game_scenes[game_active]['objects'][objetos[0]]['position'][1] += int(n[4][2].get())
  1489.                 return(True)
  1490.             except:
  1491.                 return(False)
  1492.         else:
  1493.             return(False)
  1494.     elif n[1] == 'scale':
  1495.         obName = n[0].get()
  1496.         objetos = [[num, obj] for num, obj in enumerate(game_scenes[game_active]['objects']) if obj['name'] == obName]
  1497.         if len(objetos) > 0:
  1498.             objetos = objetos[0]
  1499.             try:
  1500.                 game_scenes[game_active]['objects'][objetos[0]]['scale'][0] = int(n[4][1].get())
  1501.                 game_scenes[game_active]['objects'][objetos[0]]['scale'][1] = int(n[4][2].get())
  1502.                 return(True)
  1503.             except:
  1504.                 return(False)
  1505.         else:
  1506.             return(False)
  1507.  
  1508. def UD_Logic():
  1509.     for obj in logic_cont: # CONTROLADORES
  1510.         # ENTRADAS:
  1511.         L_input = [ob[0] for ob in logic_connection if ob[1] == obj[0]]
  1512.         # SAIDAS:
  1513.         L_output = [ob[1] for ob in logic_connection if ob[0] == obj[0]]
  1514.  
  1515.         if len(L_input) > 0 and len(L_output) > 0: # Verificar se n é um nodes desnecessario
  1516.  
  1517.             if obj[1] == 'and':
  1518.                 tmpNot = 0 # se no final do for, for 0, ele executa!
  1519.                 for inp in L_input:
  1520.                     inpName = [o for o in logic_sen if o[0] == inp][0]
  1521.                     isTrue = UD_RunNode(inpName)
  1522.                     if isTrue == False:
  1523.                         tmpNot +=1
  1524.                 if tmpNot == 0: # Agr so executar os outputs!!
  1525.                     for out in L_output:
  1526.                         outName = [o for o in logic_act if o[0] == out][0]
  1527.                         UD_ExecNode(outName)
  1528.  
  1529.             elif obj[1] == 'or':
  1530.                 tmpNot = 0 # se no final do for, for 0, ele executa!
  1531.                 for inp in L_input:
  1532.                     inpName = [o for o in logic_sen if o[0] == inp][0]
  1533.                     isTrue = UD_RunNode(inpName)
  1534.                     if isTrue == False:
  1535.                         tmpNot +=1
  1536.                 if tmpNot < len(L_input): # Agr so executar os outputs!!
  1537.                     for out in L_output:
  1538.                         outName = [o for o in logic_act if o[0] == out][0]
  1539.                         UD_ExecNode(outName)
  1540.             elif obj[1] == 'not':
  1541.                 tmpNot = 0 # se no final do for, for 0, ele executa!
  1542.                 for inp in L_input:
  1543.                     inpName = [o for o in logic_sen if o[0] == inp][0]
  1544.                     isTrue = UD_RunNode(inpName)
  1545.                     if isTrue == True:
  1546.                         tmpNot +=1
  1547.                 if tmpNot == 0: # Agr so executar os outputs!!
  1548.                     for out in L_output:
  1549.                         outName = [o for o in logic_act if o[0] == out][0]
  1550.                         UD_ExecNode(outName)
  1551.  
  1552. def UD_GameControl():
  1553.     global game_timer
  1554.  
  1555.     if game_active!= None:
  1556.         if game_timer >= 0: #100:
  1557.             UD_Render()
  1558.             UD_Logic()
  1559.         else:
  1560.             game_timer += 1
  1561.  
  1562. def UD_StartEngine():
  1563.     global inGame, game_timer, game_camera, game_active, game_scenes, game_Info, logic_act, logic_connection, logic_cont,logic_sen
  1564.     if not inGame: # Nao esta no modo jogo
  1565.         if currentSceneId != None:
  1566.             game_timer          = 0
  1567.             game_camera         = scenes[currentSceneId]['cameraPos']
  1568.             game_active         = currentSceneId
  1569.             game_scenes         = scenes
  1570.             game_Info           = game
  1571.             logic_act           = nodeAct
  1572.             logic_connection    = nodeConnect
  1573.             logic_cont          = nodeCont
  1574.             logic_sen           = nodeLogic
  1575.  
  1576.             inGame = True #ATIVA MOTOR
  1577.         else:
  1578.             print("Error: Empty Scene Slot")
  1579.     else:
  1580.         print("Cannot Open multi game Process.")
  1581.  
  1582. def UD_CloseEngine():
  1583.     global inGame
  1584.  
  1585.     try:
  1586.         if inGame:
  1587.             inGame = False
  1588.     except:
  1589.         pass
  1590.  
  1591. topMenu.add_command(label='Run...',command=UD_StartEngine)
  1592. topMenu.add_command(label='Stop...',command=UD_CloseEngine)
  1593. ##################################################################
  1594. ##################################################################
  1595. tap = 0
  1596. selectedObjectBackup = 'forceUpdate///'
  1597.  
  1598. c = pygame.time.Clock()
  1599. lastFps = 0
  1600.  
  1601. pygame.init()
  1602.  
  1603. mainLoop = True
  1604. while mainLoop:
  1605.     for event in pygame.event.get():
  1606.         if event.type == pygame.KEYDOWN:
  1607.             TheLastKey = str(pygame.key.name(event.key))
  1608.             KeyList[str(pygame.key.name(event.key))] = [True,event.key]
  1609.             print('ue',KeyList)
  1610.  
  1611.         if event.type == pygame.KEYUP:
  1612.             print(event.key)
  1613.             if KeyList[str(pygame.key.name(event.key))][1] == event.key:
  1614.                 KeyList[str(pygame.key.name(event.key))] = [False,event.key]
  1615.                 print('saiu',str(pygame.key.name(event.key)))
  1616.  
  1617.         if event.type == pygame.MOUSEBUTTONDOWN:
  1618.             if event.button == 1:
  1619.                 View_Lmb = 0
  1620.         elif event.type == pygame.MOUSEBUTTONUP:
  1621.             if event.button == 1:
  1622.                 View_Lmb += 1
  1623.     #        mainLoop = False
  1624.  
  1625.     tc = pygame.key.get_pressed()
  1626.     mc = pygame.mouse.get_pressed()
  1627.     engineX = Paned_top.sash_coord(0)[0]
  1628.     engineY = m1.sash_coord(0)[1]
  1629.     nodesX = Paned_down.sash_coord(0)[0]
  1630.     #print(engineX,engineY)
  1631.  
  1632.     if tap < 2: # Change the Tab positions
  1633.         altura = root.winfo_height()
  1634.         largura = root.winfo_width()
  1635.  
  1636.         Paned_top.sash_place(0,int((largura/3)*2),800)
  1637.         m1.sash_place(0,0,int((altura/3)*2))
  1638.         Paned_down.sash_place(0, int((largura/3)), 800)
  1639.         tap += 1
  1640.         # Load scene
  1641.         SceneGameUpdate()
  1642.         # Load scene objects
  1643.         SceneObjectsUpdate()
  1644.     else: # Sync Interface to Database
  1645.         SceneGameSync()
  1646.         ObjInfoSync()
  1647.         SceneObjectsSync()
  1648.         SceneObjectsUpdate()
  1649.         #Node UPDATE
  1650.         UpdateNode()
  1651.  
  1652.     if selectedObject != selectedObjectBackup: # Update
  1653.         ObjInfoUpdate()
  1654.         selectedObjectBackup = selectedObject
  1655.  
  1656.     screen = pygame.display.set_mode((engineX,engineY))
  1657.     bgColor = View_HexToRGB(scenes[currentSceneId]['background'])
  1658.     screen.fill((bgColor[0],bgColor[1],bgColor[2],255))
  1659.     pygame.display.init()
  1660.  
  1661.     if inGame:
  1662.         UD_GameControl()
  1663.     else:
  1664.         View_ConfigureObjects()
  1665.         View_DragObject()
  1666.  
  1667.         if currentScene != None:
  1668.             View_RenderObjlist(scenes[currentSceneId]['objects'])
  1669.  
  1670.     # FPS = 30
  1671.     if int(game['fps']) > 30:
  1672.         c.tick(int(game['fps']))
  1673.     else:
  1674.         c.tick(30)
  1675.     View_DrawDebug(c.get_fps())
  1676.     if pygame.time.get_ticks() - lastFps > 1000:
  1677.         #print(c.get_fps())
  1678.         lastFps = pygame.time.get_ticks()
  1679.  
  1680.     pygame.display.update()
  1681.  
  1682.     root.update()
  1683. #mainloop()
Add Comment
Please, Sign In to add comment