pm_mainLayer.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. fill=True)
  156. # creates a blank layer
  157. node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
  158. node = cairo.Context(node_surface)
  159. # it adds a transparancy mask to the node
  160. UI_elements.roundrect(node, win,
  161. 0,
  162. 0,
  163. width,
  164. height,
  165. 30,
  166. fill=False)
  167. node.clip()
  168. # background colour for smaller images
  169. UI_color.set(node, win, "banner_white")
  170. UI_elements.roundrect(node, win,
  171. 0,
  172. 0,
  173. width,
  174. height,
  175. 30,
  176. fill=True)
  177. # draws images
  178. UI_elements.image(node, win, 'game_previews/' + project,
  179. 0 , 0, width, height, cell = 1)
  180. # Drawing the Node on the main layer.
  181. layer.set_source_surface(node_surface, x,y)
  182. layer.paint()
  183. # Setting up tilling
  184. tileY = 400
  185. tileX = 0
  186. width = 350
  187. height = 197
  188. # calculates where is the middle of the screen based upon the tiles
  189. tmp_foo = int((win.current["w"] - io_close) / (width + 10)) # of the tile
  190. offset = (win.current['w'] / 2) - (tmp_foo * (width + 10) / 2)
  191. tileX = offset
  192. # temp look into a folder instead the LBRY protocol and tiling (^:3:^)
  193. games = os.listdir('game_previews')
  194. for num, project in enumerate(games):
  195. if tileX > (win.current["w"] - io_close) - 391:
  196. tileY += 197 + 10
  197. tileX = offset
  198. project_node(layer, win, tileX, 60 + tileY + win.scroll["pm_main"], project)
  199. tileX += 360
  200. UI_elements.scroll_area(layer, win, "pm_main",
  201. 0,
  202. 50,
  203. win.current["w"] - io_close,
  204. win.current["h"] - 50,
  205. tileY + 340,
  206. bar = False,
  207. mmb = True,
  208. strenght = 200,
  209. url="project_manager"
  210. )
  211. return surface
  212. def project_node(layer, win, x, y, project):
  213. # This function will draw a project to a given place.
  214. node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  215. win.current['h'])
  216. node = cairo.Context(node_surface)
  217. node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  218. # sizes of width and height
  219. width = 350
  220. height = 197
  221. # shadow
  222. UI_color.set(node, win, "shadow")
  223. UI_elements.roundrect(node, win,
  224. x + 5,
  225. y + 5,
  226. width,
  227. height,
  228. 20,
  229. fill=True)
  230. # mouseover
  231. if x + width > win.current['mx'] > x and y + height > win.current['my'] > y:
  232. x -= 5
  233. y -= 5
  234. # Before we gonna do clip. Let's put here the logic of the node.
  235. def do():
  236. print(project)
  237. UI_elements.animate('scroll_pm_main', win, v1 = win.scroll["pm_main"], v2 = 0, time = 10, force = True)
  238. win.scroll["pm_main"] = 0
  239. win.current['game_selected'] = project
  240. Legacytip = ""
  241. nameonly = project[project.rfind("/")+1:]
  242. timefraction = 0.0
  243. projectfraction = 0.0
  244. node.set_line_width(10)
  245. UI_elements.roundrect(node, win,
  246. x + 5,
  247. y + 5,
  248. width - 10,
  249. height - 10,
  250. 20 + 5,
  251. button = do,
  252. fill = False,
  253. tip = project+Legacytip,
  254. url = "project_manager")
  255. # node.stroke()
  256. # This next roundrect will both be the backdrop of the node and both will
  257. # clip the node content. All folowing graphics will be drawn clipped to the
  258. # current roundrect.
  259. UI_color.set(node, win, "node_background")
  260. UI_elements.roundrect(node, win,
  261. x,
  262. y,
  263. width,
  264. height,
  265. 20)
  266. # Clip
  267. UI_elements.roundrect(node, win,
  268. x,
  269. y,
  270. width,
  271. height,
  272. 20,
  273. fill=False)
  274. node.clip()
  275. # this finds images and crops them to the right size
  276. UI_elements.image(node, win, 'game_previews/'+ project,
  277. x, y, width, height)
  278. # Drawing the Node on the main layer.
  279. layer.set_source_surface(node_surface, 0,0)
  280. layer.paint()