pm_mainLayer.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. import os
  4. # GTK module ( Graphical interface or Gimp ToolKit
  5. import gi
  6. gi.require_version('Gtk', '3.0')
  7. from gi.repository import Gtk
  8. from gi.repository import GLib
  9. from gi.repository import Gdk
  10. import cairo
  11. # Own modules
  12. from settings import settings
  13. from settings import talk
  14. from project_manager import pm_project
  15. from studio import analytics
  16. from studio import story
  17. from studio import studio_gtk
  18. from studio import studio_dialogs
  19. #UI modules
  20. from UI import UI_elements
  21. from UI import UI_color
  22. def layer(win):
  23. # Making the layer
  24. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  25. win.current['h'])
  26. layer = cairo.Context(surface)
  27. #text setting
  28. layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  29. # Reloads images every time the window size changes
  30. try:
  31. if (win.current['w'] != win.previous['w']):
  32. UI_elements.reload_images(win, force = True, only_cell = 1)
  33. except:
  34. print(f'Ignore: {layer} seems to be broken ):')
  35. # Internet things
  36. def do():
  37. # I used to have a specific UI instance for the help layer here. But
  38. # it proved to be too hard to maintain. So I'm changing it to a different
  39. # dialog. I'm not going to delete the help layer it self. For curious
  40. # poeple.
  41. # win.url = "help_layer"
  42. # The following commands are the replacement. So if you want to see how
  43. # it used to look. Comment those. So not to launch both in the same time.
  44. def after(win, var):
  45. pass
  46. studio_dialogs.help(win, "help", after, SEARCH=talk.text("documentation_project_manager"))
  47. UI_elements.roundrect(layer, win,
  48. win.current['w'] - 50,
  49. 5,
  50. 40,
  51. 40,
  52. 10,
  53. do,
  54. "question",
  55. talk.text("pm_internet_tooltip"),
  56. url="project_manager")
  57. # Update
  58. def do():
  59. win.url = "update_layer"
  60. UI_elements.roundrect(layer, win,
  61. win.current['w'] - 100,
  62. 5,
  63. 40,
  64. 40,
  65. 10,
  66. do,
  67. "update",
  68. talk.text("update"),
  69. url="project_manager")
  70. # This will open and close the sidebar
  71. if 'main_sidebar_open_close' not in win.current:
  72. win.current['main_sidebar_open_close'] = False
  73. def do():
  74. win.current['main_sidebar_open_close'] = not win.current['main_sidebar_open_close']
  75. UI_elements.roundrect(layer, win,
  76. win.current['w'] - 50,
  77. win.current['h'] - 50,
  78. 40,
  79. 40,
  80. 10,
  81. do,
  82. "question",
  83. talk.text("sidebar_left"),
  84. url="project_manager")
  85. # I gonna draw a little thingy for if a new update is available
  86. try:
  87. if win.update["count"]:
  88. count = str(win.update["count"])
  89. UI_color.set(layer, win, "node_background")
  90. UI_elements.roundrect(layer, win,
  91. 30,
  92. win.current["h"]-100,
  93. len(count)*12+6,
  94. 25,
  95. 5)
  96. layer.fill()
  97. UI_color.set(layer, win, "text_normal")
  98. layer.set_font_size(20)
  99. layer.move_to(33,win.current["h"]-80)
  100. layer.show_text(count)
  101. except:
  102. pass
  103. # Settings
  104. def do():
  105. win.url = "settings_layer"
  106. UI_elements.roundrect(layer, win,
  107. win.current['w'] - 150,
  108. 5,
  109. 40,
  110. 40,
  111. 10,
  112. do,
  113. "settings",
  114. talk.text("Settings"),
  115. url="project_manager")
  116. # Now let's make previews of projects. I think each one will be it's own
  117. # layer thingy. Just so I could draw things inside them.
  118. # Clipping so it wont draw beyond the frame
  119. if win.current['main_sidebar_open_close']:
  120. io_close = 100
  121. else:
  122. io_close = 0
  123. UI_elements.roundrect(layer, win,
  124. 0,
  125. 50,
  126. win.current["w"] - io_close,
  127. win.current["h"] - 50,
  128. 30,
  129. fill=False)
  130. layer.clip()
  131. # UI_color.set(layer, win, "dark_overdrop")
  132. # layer.rectangle(0,0,9000,2000)
  133. # layer.fill()
  134. # Setting up scroll for Projects
  135. if "pm_scroll" not in win.current:
  136. win.current["pm_scroll"] = 0.0
  137. if "pm_main" not in win.scroll:
  138. win.scroll["pm_main"] = -400
  139. if 'game_selected' not in win.current:
  140. win.current['game_selected'] = 'fridaynightfunkin.png'
  141. project = win.current['game_selected']
  142. # sizes of banner
  143. x = 10
  144. y = 60 + win.scroll['pm_main']
  145. width = win.current['w']
  146. height = 300
  147. # banner's shadow
  148. UI_color.set(layer, win, "shadow")
  149. UI_elements.roundrect(layer, win,
  150. x + 5,
  151. y + 5,
  152. width,
  153. height,
  154. 30)
  155. # creates a blank layer
  156. node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
  157. node = cairo.Context(node_surface)
  158. # it adds a transparancy mask to the node
  159. UI_elements.roundrect(node, win,
  160. 0,
  161. 0,
  162. width,
  163. height,
  164. 30,
  165. fill=False)
  166. node.clip()
  167. # background colour for smaller images
  168. UI_color.set(node, win, "banner_white")
  169. UI_elements.roundrect(node, win,
  170. 0,
  171. 0,
  172. width,
  173. height,
  174. 30)
  175. # draws images
  176. UI_elements.image(node, win, 'game_previews/' + project,
  177. 0 , 0, width, height, cell = 1)
  178. # Drawing the Node on the main layer.
  179. layer.set_source_surface(node_surface, x,y)
  180. layer.paint()
  181. # download non-button layer
  182. UI_color.set(layer, win, "download_button")
  183. UI_elements.roundrect(layer, win,
  184. win.current['w'] - 440,
  185. y + 140,
  186. 400,
  187. 130,
  188. 30)
  189. # rating stars
  190. ueu = 0
  191. while ueu != 5:
  192. UI_elements.roundrect(layer, win,
  193. win.current['w'] - 440 - ueu * 40,
  194. 300,
  195. 40,
  196. 40,
  197. 10,
  198. do,
  199. "settings",
  200. talk.text("Settings"),
  201. url="project_manager")
  202. ueu += 1
  203. import subprocess
  204. def do():
  205. subprocess.run('worm')
  206. # download button
  207. UI_color.set(layer, win, "download_button")
  208. UI_elements.roundrect(layer, win,
  209. win.current['w'] - 440,
  210. y + 140,
  211. 400,
  212. 130,
  213. 30,
  214. button = do,
  215. fill=False)
  216. # Setting up tilling
  217. tileY = 400
  218. tileX = 0
  219. width = 350
  220. height = 197
  221. # calculates where is the middle of the screen based upon the tiles
  222. tmp_foo = int((win.current["w"] - io_close) / (width + 10)) # of the tile
  223. offset = (win.current['w'] / 2) - (tmp_foo * (width + 10) / 2)
  224. tileX = offset
  225. # temp look into a folder instead the LBRY protocol and tiling (^:3:^)
  226. games = os.listdir('game_previews')
  227. for num, project in enumerate(games):
  228. if tileX > (win.current["w"] - io_close) - 391:
  229. tileY += 197 + 10
  230. tileX = offset
  231. main_layer(layer, win, tileX, 60 + tileY + win.scroll["pm_main"], project)
  232. banner_layer(layer, win, tileX, 60 + tileY + win.scroll["pm_main"], project)
  233. tileX += 368
  234. UI_elements.scroll_area(layer, win, "pm_main",
  235. 0,
  236. 50,
  237. win.current["w"] - io_close,
  238. win.current["h"] - 50,
  239. tileY + 340,
  240. bar = False,
  241. mmb = True,
  242. strenght = 200,
  243. url="project_manager"
  244. )
  245. return surface
  246. # This is for banner User interface. We'll draw non-fuctional UI.
  247. # In the next def we'll draw buttons. They have not been created, yet
  248. def banner_layer(layer, win, x, y, project):
  249. # This function will draw a project to a given place.
  250. node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  251. win.current['h'])
  252. node = cairo.Context(node_surface)
  253. node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  254. # sizes of width and height
  255. width = 350
  256. height = 197
  257. # shadow
  258. UI_color.set(node, win, "shadow")
  259. UI_elements.roundrect(node, win,
  260. x + 5,
  261. y + 5,
  262. width,
  263. height,
  264. 20)
  265. # mouseover
  266. if x + width > win.current['mx'] > x and y + height > win.current['my'] > y:
  267. x -= 5
  268. y -= 5
  269. # Before we gonna do clip. Let's put here the logic of the node.
  270. def do():
  271. print(project)
  272. UI_elements.animate('scroll_pm_main', win, v1 = win.scroll["pm_main"], v2 = 0, time = 10, force = True)
  273. win.scroll["pm_main"] = 0
  274. win.current['game_selected'] = project
  275. Legacytip = ""
  276. nameonly = project[project.rfind("/")+1:]
  277. timefraction = 0.0
  278. projectfraction = 0.0
  279. node.set_line_width(10)
  280. UI_elements.roundrect(node, win,
  281. x + 5,
  282. y + 5,
  283. width - 10,
  284. height - 10,
  285. 20 + 5,
  286. button = do,
  287. fill = False,
  288. tip = project+Legacytip,
  289. url = "project_manager")
  290. # node.stroke()
  291. # This next roundrect will both be the backdrop of the node and both will
  292. # clip the node content. All folowing graphics will be drawn clipped to the
  293. # current roundrect.
  294. UI_color.set(node, win, "node_background")
  295. UI_elements.roundrect(node, win,
  296. x,
  297. y,
  298. width,
  299. height,
  300. 20)
  301. # Clip
  302. UI_elements.roundrect(node, win,
  303. x,
  304. y,
  305. width,
  306. height,
  307. 20,
  308. fill=False)
  309. node.clip()
  310. # this finds images and crops them to the right size
  311. UI_elements.image(node, win, 'game_previews/'+ project,
  312. x, y, width, height)
  313. # Drawing the Node on the main layer.
  314. layer.set_source_surface(node_surface, 0,0)
  315. layer.paint()
  316. def main_layer(layer, win, x, y, project):
  317. # This function will draw a project to a given place.
  318. node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  319. win.current['h'])
  320. node = cairo.Context(node_surface)
  321. node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  322. # sizes of width and height
  323. width = 350
  324. height = 197
  325. # shadow
  326. UI_color.set(node, win, "shadow")
  327. # Before we gonna do clip. Let's put here the logic of the node.
  328. def do():
  329. print(project)
  330. UI_elements.animate('scroll_pm_main', win, v1 = win.scroll["pm_main"], v2 = 0, time = 10, force = True)
  331. win.scroll["pm_main"] = 0
  332. win.current['game_selected'] = project
  333. Legacytip = ""
  334. nameonly = project[project.rfind("/")+1:]
  335. timefraction = 0.0
  336. projectfraction = 0.0
  337. node.set_line_width(10)
  338. UI_elements.roundrect(node, win,
  339. x + 5,
  340. y + 5,
  341. width - 10,
  342. height - 10,
  343. 20 + 5,
  344. button = do,
  345. fill = False,
  346. tip = project+Legacytip,
  347. url = "project_manager")
  348. # node.stroke()
  349. # This next roundrect will both be the backdrop of the node and both will
  350. # clip the node content. All folowing graphics will be drawn clipped to the
  351. # current roundrect.
  352. UI_color.set(node, win, "node_background")
  353. UI_elements.roundrect(node, win,
  354. x,
  355. y,
  356. width,
  357. height,
  358. 20)
  359. # Clip
  360. UI_elements.roundrect(node, win,
  361. x,
  362. y,
  363. width,
  364. height,
  365. 20,
  366. fill=False)
  367. node.clip()
  368. # this finds images and crops them to the right size
  369. UI_elements.image(node, win, 'game_previews/'+ project,
  370. x, y, width, height)
  371. # Drawing the Node on the main layer.
  372. layer.set_source_surface(node_surface, 0,0)
  373. layer.paint()