editor.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # THIS IS A SOURCE CODE FILE FROM I'M NOT EVEN HUMAN THE GAME.
  2. # IT COULD BE USED IN A DIFFERENT PIECE OF SOFTWARE ( LIKE A
  3. # DIFFERENT GAME ), BUT IT WAS ORIGINALLY WRITTEN FOR I'M NOT
  4. # EVEN HUMAN THE GAME.
  5. # THE DEVELOPERS OF THE GAME ARE : (C) J.Y.AMIHUD, AYYZEE AND
  6. # OTHER CONTRIBUTORS. THIS AND OTHER FILES IN THIS GAME,
  7. # UNLESS SPECIFICALLY NOTED, COULD BE USED UNDER THE TERMS OF
  8. # GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER VERSION.
  9. import os
  10. import json
  11. # GTK module ( Graphical interface
  12. import gi
  13. gi.require_version('Gtk', '3.0')
  14. from gi.repository import Gtk
  15. import cairo
  16. from modules import ui
  17. from modules import world
  18. def layer(game):
  19. # Setting up a cairo layer
  20. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
  21. game.current['w'],
  22. game.current['h'])
  23. layer = cairo.Context(surface)
  24. layer.set_antialias(cairo.ANTIALIAS_NONE)
  25. def do():
  26. game.scene = "settings"
  27. ui.button(game, layer,
  28. 5,
  29. 5 ,
  30. int(game.current["w"] / 3 ) - 30 ,
  31. 13,
  32. menu="editor",
  33. string="< Back",
  34. func=do)
  35. ui.color(game, layer, "#FFFFFF")
  36. ui.text(game, layer, game.worlds[game.settings["world"]]["title"],
  37. int(game.current["w"]/2), 5,
  38. align="center")
  39. # THE WORLD VIEW
  40. world.draw(game, layer, int(game.current["w"] / 3), 20,
  41. int(game.current["w"]/3*2),
  42. game.current["h"]-50, grid=True)
  43. # BOTTOM TOOL BAR
  44. # Heigh setting ( Layer )
  45. def do():
  46. game.current["camera"][2] += 1
  47. ui.button(game, layer,
  48. 2,
  49. game.current["h"]-30,
  50. 13 ,
  51. 13 ,
  52. menu="editor",
  53. icon="up",
  54. func=do)
  55. def do():
  56. game.current["camera"][2] -= 1
  57. ui.button(game, layer,
  58. 2,
  59. game.current["h"]-15,
  60. 13 ,
  61. 13 ,
  62. menu="editor",
  63. icon="down",
  64. func=do)
  65. ui.color(game, layer, "#00FF00")
  66. ui.text(game, layer, "Height",
  67. 17,game.current["h"]-30)
  68. ui.text(game, layer, str(game.current["camera"][2]),
  69. 17,game.current["h"]-15)
  70. # Brush size
  71. def do():
  72. game.current["editor_brush"] += 1
  73. ui.button(game, layer,
  74. 65,
  75. game.current["h"]-30,
  76. 13 ,
  77. 13 ,
  78. menu="editor",
  79. icon="up",
  80. func=do)
  81. def do():
  82. game.current["editor_brush"] -= 1
  83. if game.current["editor_brush"] < 1:
  84. game.current["editor_brush"] = 1
  85. ui.button(game, layer,
  86. 65,
  87. game.current["h"]-15,
  88. 13 ,
  89. 13 ,
  90. menu="editor",
  91. icon="down",
  92. func=do)
  93. ui.color(game, layer, "#00FF00")
  94. ui.text(game, layer, "Brush Size",
  95. 82,game.current["h"]-30)
  96. ui.text(game, layer, str(game.current["editor_brush"]),
  97. 82,game.current["h"]-15)
  98. #####################################
  99. # TREE VIEW SELECTOR #
  100. #####################################
  101. # The next section will implement a tree view
  102. # to select various editable assets.
  103. # Setting up the scroller
  104. if "editor" not in game.scroll:
  105. game.scroll["editor"] = 0
  106. current_Y = 0
  107. layer.rectangle(1, 19,
  108. int(game.current["w"]/3)-3,
  109. game.current["h"]-70)
  110. layer.clip()
  111. if "editor_chooser" not in game.current:
  112. game.current["editor_chooser"] = {}
  113. for types in game.elements:
  114. if "type_"+types not in game.current["editor_chooser"]:
  115. game.current["editor_chooser"]["type_"+types] = False
  116. def do():
  117. game.menus = {}
  118. game.current["editor_chooser"]["type_"+types] = not game.current["editor_chooser"]["type_"+types]
  119. if game.current["editor_chooser"]["type_"+types]:
  120. wicon = "down"
  121. else:
  122. wicon = "right"
  123. ui.button(game, layer,
  124. 2,
  125. current_Y+20,
  126. int(game.current["w"]/3)-4 ,
  127. 13 ,
  128. menu="editor",
  129. scroll="editor",
  130. icon=wicon,
  131. string=types,
  132. func=do,
  133. borders=False)
  134. current_Y += 13
  135. if game.current["editor_chooser"]["type_"+types]:
  136. current_Y += 5
  137. for asset in game.elements[types]:
  138. if "asset_"+asset not in game.current["editor_chooser"]:
  139. game.current["editor_chooser"]["asset_"+asset] = False
  140. try:
  141. assetname = game.images["assets/elements/"+types+"/"+asset]["title"]
  142. except:
  143. assetname = asset
  144. def do():
  145. game.menus = {}
  146. game.current["editor_chooser"]["asset_"+asset] = not game.current["editor_chooser"]["asset_"+asset]
  147. if game.current["editor_chooser"]["asset_"+asset]:
  148. wicon = "down"
  149. else:
  150. wicon = "right"
  151. ui.button(game, layer,
  152. 7,
  153. current_Y+20,
  154. int(game.current["w"]/3)-9 ,
  155. 13 ,
  156. menu="editor",
  157. scroll="editor",
  158. icon=wicon,
  159. string=assetname,
  160. func=do,
  161. borders=False)
  162. current_Y += 13
  163. if game.current["editor_chooser"]["asset_"+asset]:
  164. current_Y += 5
  165. for n, version in enumerate(game.elements[types][asset]):
  166. def do():
  167. game.current["editor_selection"][0] = types
  168. game.current["editor_selection"][1] = asset
  169. game.current["editor_selection"][2] = n
  170. if game.current["editor_selection"][2] == n\
  171. and game.current["editor_selection"][1] == asset\
  172. and game.current["editor_selection"][0] == types:
  173. wicon = "radio_true"
  174. else:
  175. wicon = "radio_false"
  176. ui.button(game, layer,
  177. 10,
  178. current_Y+20,
  179. int(game.current["w"]/3)-12 ,
  180. 13 ,
  181. menu="editor",
  182. scroll="editor",
  183. icon=wicon,
  184. string=str(version["title"]),
  185. func=do,
  186. borders=False)
  187. # Mouse over the block
  188. if int(game.current["mx"]) in range(10, int(game.current["w"]/3)+6 )\
  189. and int(game.current["my"]) in range(int(current_Y+20+game.scroll["editor"]), int(current_Y+20+game.scroll["editor"]+13)):
  190. ui.image(game, layer,
  191. game.current["mx"]-20,
  192. game.current["my"]-20,
  193. "assets/elements/"+types+"/"+asset, version["title"], offset=True)
  194. current_Y += 13
  195. current_Y += 5
  196. current_Y += 5
  197. ui.scroll_area(game, layer, "editor", 1, 19,
  198. int(game.current["w"]/3)-3,
  199. game.current["h"]-70,
  200. current_Y)
  201. # Navigating the menus
  202. ui.button_navigate(game, "editor")
  203. return surface