studio_asset_selectLayer.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. # This a console project manager.
  4. import os
  5. import time
  6. # GTK module ( Graphical interface
  7. import gi
  8. gi.require_version('Gtk', '3.0')
  9. from gi.repository import Gtk
  10. from gi.repository import GLib
  11. from gi.repository import Gdk
  12. import cairo
  13. # Own modules
  14. from settings import settings
  15. from settings import talk
  16. from settings import fileformats
  17. from project_manager import pm_project
  18. #UI modules
  19. from UI import UI_elements
  20. from UI import UI_color
  21. # story
  22. from studio import story
  23. from studio import analytics
  24. from studio import history
  25. def layer(win, call):
  26. # Making the layer
  27. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  28. win.current['h'])
  29. layer = cairo.Context(surface)
  30. #text setting
  31. layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  32. UI_color.set(layer, win, "dark_overdrop")
  33. layer.rectangle(
  34. 0,
  35. 0,
  36. win.current["w"],
  37. win.current["h"],
  38. )
  39. layer.fill()
  40. UI_color.set(layer, win, "node_background")
  41. UI_elements.roundrect(layer, win,
  42. 80,
  43. 80,
  44. win.current["w"]-160,
  45. win.current["h"]-160,
  46. 10)
  47. ############################################################################
  48. # Before we start anything. I would like to refresh the cash of the assets.
  49. # so I would have the most up to date list / fractions of each item.
  50. # In the studio/story.py there is the get_asset_data() functions. Which if
  51. # you look closly just loads fraction into a dictionary called win.assets
  52. # from which we can read directly.
  53. # The function is designed to give load the fraction ones and then just give
  54. # you one from the RAM. So it's not always going to read the asset.progress
  55. # files which is not too good. Since I want to have a good idea about the
  56. # asset's actuall fraction.
  57. # One way I can force it to update is by using the force argument. But doing
  58. # it on every frame defeats the purpose of the function entirelly. So here
  59. # what I'm going to do. Each time I close this window. AKA return anything
  60. # I am also going to wipe the dictionary win.asset clean. It will take one
  61. # frame of potential lag to load everything back ( at least the stuff that's
  62. # ont the screen in a given moment.
  63. # Also to make sure that this dialog has the up to date info. I will do it
  64. # as well in the studio_dialogs.py when initilizing this function. So yeah.
  65. # Let's continue with the program.
  66. ############################################################################
  67. ####### TOP PANEL #######
  68. for num, cur in enumerate(["chr","veh","loc","obj"]):
  69. if win.current["asset_cur"] == cur:
  70. UI_color.set(layer, win, "progress_time")
  71. UI_elements.roundrect(layer, win,
  72. 100+(40*num),
  73. 100,
  74. 40,
  75. 40,
  76. 10)
  77. def do():
  78. win.current["asset_cur"] = cur
  79. UI_elements.roundrect(layer, win,
  80. 100+(40*num),
  81. 100,
  82. 40,
  83. 40,
  84. 10,
  85. do,
  86. cur,
  87. tip=talk.text(cur))
  88. # In case the user is confused
  89. UI_color.set(layer, win, "text_normal")
  90. layer.set_font_size(30)
  91. layer.move_to(300,130)
  92. layer.show_text(talk.text(win.current["asset_cur"]))
  93. # Search
  94. UI_elements.image(layer, win, "settings/themes/"\
  95. +win.settings["Theme"]+"/icons/search.png",
  96. win.current["w"]-440,
  97. 100,
  98. 40,
  99. 40)
  100. UI_elements.text(layer, win, "asset_select_search",
  101. win.current["w"]-400,
  102. 100,
  103. 250,
  104. 40)
  105. # CANCEl
  106. def do():
  107. win.current["calls"][call]["var"] = False
  108. win.assets = {}
  109. UI_elements.roundrect(layer, win,
  110. win.current["w"]-120,
  111. win.current["h"]-120,
  112. 40,
  113. 40,
  114. 10,
  115. button=do,
  116. icon="cancel",
  117. tip=talk.text("cancel"))
  118. # Short cut ESC
  119. if 65307 in win.current["keys"] and not win.textactive:
  120. do()
  121. # Now let's prepare the ground for the next part.
  122. UI_elements.roundrect(layer, win,
  123. 100,
  124. 150,
  125. win.current["w"]-200,
  126. win.current["h"]-250,
  127. 10,
  128. fill=False)
  129. layer.clip()
  130. tileX = 120
  131. current_Y = 50
  132. if "asset_select" not in win.scroll:
  133. win.scroll["asset_select"] = 0
  134. newcreate = win.text["asset_select_search"]["text"].replace("/","_").replace(" ", "_")\
  135. .replace('"',"_").replace("(","_").replace(")","_").replace("'","_")\
  136. .replace("[","_").replace("]","_").replace("{","_").replace("}","_")
  137. ###########################
  138. okay = True
  139. for asset in os.listdir(win.project+"/dev/"+win.current["asset_cur"]):
  140. if os.path.isdir(win.project+"/dev/"+win.current["asset_cur"]+"/"+asset):
  141. okay = True
  142. # Search
  143. if win.text["asset_select_search"]["text"]\
  144. and newcreate.lower() not in asset.lower():
  145. okay = False
  146. if okay:
  147. if int(current_Y + win.scroll["asset_select"] + 100) in range(0-100, win.current["h"]):
  148. # Making the layer
  149. nodesurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 170, 200)
  150. node = cairo.Context(nodesurface)
  151. node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  152. UI_elements.roundrect(node, win,
  153. 0,
  154. 0,
  155. 170,
  156. 200,
  157. 10,
  158. fill=False)
  159. node.clip()
  160. # Background
  161. UI_color.set(node, win, "dark_overdrop")
  162. node.rectangle(0,0,170, 200)
  163. node.fill()
  164. # Banner
  165. UI_color.set(node, win, "node_asset")
  166. node.rectangle(0,0,170, 20)
  167. node.fill()
  168. # Outputting the layer
  169. layer.set_source_surface(nodesurface,
  170. tileX-10,
  171. current_Y + win.scroll["asset_select"] + 120)
  172. layer.paint()
  173. # Previes image
  174. if os.path.exists(win.project+"/dev/"+win.current["asset_cur"]+"/"+asset+"/renders/Preview.png"):
  175. UI_elements.image(layer, win, win.project+"/dev/"+win.current["asset_cur"]+"/"+asset+"/renders/Preview.png",
  176. tileX,
  177. current_Y + win.scroll["asset_select"] + 140,
  178. 150,
  179. 150)
  180. elif os.path.exists(win.project+"/dev/"+win.current["asset_cur"]+"/"+asset+"/renders/Preview.jpg"):
  181. UI_elements.image(layer, win, win.project+"/dev/"+win.current["asset_cur"]+"/"+asset+"/renders/Preview.jpg",
  182. tileX,
  183. current_Y + win.scroll["asset_select"] + 140,
  184. 150,
  185. 150)
  186. else:
  187. UI_elements.image(layer, win, "settings/themes/"+win.settings["Theme"]+"/icons/"+win.current["asset_cur"]+".png",
  188. tileX+55,
  189. current_Y + win.scroll["asset_select"] + 150+55,
  190. 150,
  191. 150)
  192. # Progress bar
  193. fraction = story.get_asset_data(win, win.current["asset_cur"]+"/"+asset)["fraction"]
  194. UI_color.set(layer, win, "progress_background")
  195. UI_elements.roundrect(layer, win,
  196. tileX,
  197. current_Y + win.scroll["asset_select"] + 300,
  198. 150,
  199. 0,
  200. 5)
  201. UI_color.set(layer, win, "progress_active")
  202. UI_elements.roundrect(layer, win,
  203. tileX,
  204. current_Y + win.scroll["asset_select"] + 300,
  205. 150*fraction,
  206. 0,
  207. 5)
  208. UI_color.set(layer, win, "text_normal")
  209. layer.set_font_size(12)
  210. layer.move_to(tileX,
  211. current_Y + win.scroll["asset_select"] + 135)
  212. layer.show_text(asset[asset.rfind("/")+1:][:22])
  213. # Button to activate it
  214. def do():
  215. print("test")
  216. win.current["calls"][call]["var"] = "/"+win.current["asset_cur"]+"/"+asset
  217. win.assets = {}
  218. layer.set_line_width(4)
  219. UI_elements.roundrect(layer, win,
  220. tileX-10,
  221. current_Y + win.scroll["asset_select"] + 120,
  222. 170,
  223. 200,
  224. 10,
  225. button=do,
  226. tip=talk.text(win.current["asset_cur"])+": "+asset,
  227. fill=False,
  228. clip=[
  229. 100,
  230. 150,
  231. win.current["w"]-200,
  232. win.current["h"]-250
  233. ])
  234. layer.stroke()
  235. layer.set_line_width(2)
  236. tileX += 200
  237. if tileX > win.current["w"]-270:
  238. tileX = 120
  239. current_Y += 230
  240. if win.text["asset_select_search"]["text"]\
  241. and newcreate\
  242. not in os.listdir(win.project+"/dev/"+win.current["asset_cur"])\
  243. and newcreate not in "chr veh loc obj": #Avoiding potential mistakes
  244. # If there is a seach and there is no asset with the search name. It
  245. # will ask if you want to create such an asset.
  246. def do():
  247. # I don't thing I need to write a whole module for creating a couple
  248. # of folders.
  249. try:
  250. os.mkdir(win.project+"/dev/"+win.current["asset_cur"]+"/"+newcreate)
  251. os.mkdir(win.project+"/dev/"+win.current["asset_cur"]+"/"+newcreate+"/renders")
  252. os.mkdir(win.project+"/dev/"+win.current["asset_cur"]+"/"+newcreate+"/reference")
  253. os.mkdir(win.project+"/dev/"+win.current["asset_cur"]+"/"+newcreate+"/tex")
  254. # Recodring to history
  255. history.record(win, win.project+"/dev/"+win.current["asset_cur"]+"/"+newcreate, "[Added Asset]")
  256. except:
  257. pass
  258. # There is a problem that was introduced with the multiuser.
  259. # Basically. The other user whould need to create this asset too. And it's
  260. # not cool. I want to the experience to be seamless. Or at least somewhat seamless.
  261. # So I'm going to enter the cur of the asset for a fraction of a second. And then
  262. # come back to what ever we were doing.
  263. tmp = win.cur
  264. win.cur = win.current["asset_cur"]
  265. time.sleep(0.1) # This should be plenty
  266. win.cur = tmp
  267. win.text["asset_select_search"]["text"] = ""
  268. win.current["calls"][call]["var"] = "/"+win.current["asset_cur"]+"/"+newcreate
  269. win.assets = {}
  270. # Refrashing analytics
  271. win.analytics = analytics.load(win.project)
  272. analytics.save(win.project, win.analytics)
  273. UI_elements.roundrect(layer, win,
  274. tileX-10,
  275. current_Y + win.scroll["asset_select"] + 120,
  276. 170,
  277. 200,
  278. 10,
  279. button=do,
  280. tip=talk.text("create_new_asset")+" "+newcreate)
  281. UI_color.set(layer, win, "progress_background")
  282. UI_elements.roundrect(layer, win,
  283. tileX-10,
  284. current_Y + win.scroll["asset_select"] + 120,
  285. 170,
  286. 200,
  287. 10,
  288. fill=False)
  289. layer.stroke()
  290. UI_elements.image(layer, win,
  291. "settings/themes/"+win.settings["Theme"]+"/icons/asset_new.png",
  292. tileX+55,
  293. current_Y + win.scroll["asset_select"] + 200,
  294. 40, 40)
  295. UI_color.set(layer, win, "text_normal")
  296. layer.set_font_size(12)
  297. layer.move_to(tileX+85-len(newcreate)*4,
  298. current_Y + win.scroll["asset_select"] + 300)
  299. layer.show_text(newcreate)
  300. ###########################
  301. current_Y += 230
  302. UI_elements.scroll_area(layer, win, "asset_select",
  303. 50,
  304. 100,
  305. win.current["w"]-100,
  306. win.current["h"]-200,
  307. current_Y,
  308. bar=True,
  309. mmb=True,
  310. url="asset_select",
  311. strenght=130
  312. )
  313. return surface