settings.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. def layer(game):
  18. # Setting up a cairo layer
  19. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
  20. game.current['w'],
  21. game.current['h'])
  22. layer = cairo.Context(surface)
  23. layer.set_antialias(cairo.ANTIALIAS_NONE)
  24. ui.color(game, layer, "#FFFFFF")
  25. ui.text(game, layer, "Settings",
  26. int(game.current["w"]/2), 5,
  27. align="center")
  28. def do():
  29. game.scene = "main_menu"
  30. ui.button(game, layer,
  31. 5,
  32. 5 ,
  33. int(game.current["w"] / 3 ) - 30 ,
  34. 13,
  35. menu="settings",
  36. string="< Back",
  37. func=do)
  38. # Setting up the scroller
  39. if "settings" not in game.scroll:
  40. game.scroll["settings"] = 0
  41. current_Y = 0
  42. layer.rectangle(4,20,
  43. game.current["w"]-10,
  44. game.current["h"]-25)
  45. layer.clip()
  46. <<<<<<< HEAD
  47. =======
  48. <<<<<<< HEAD
  49. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  50. # WORLD
  51. if "settings_world_active" not in game.current:
  52. game.current["settings_world_active"] = False
  53. wicon = "right"
  54. if game.current["settings_world_active"]:
  55. wicon = "down"
  56. def do():
  57. game.current["settings_world_active"] = not game.current["settings_world_active"]
  58. game.menus = {}
  59. <<<<<<< HEAD
  60. =======
  61. =======
  62. # World
  63. def do():
  64. print("world")
  65. >>>>>>> 4cee21d (made game red)
  66. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  67. ui.button(game, layer,
  68. 5,
  69. current_Y+25,
  70. int(game.current["w"]) - 11 ,
  71. 13,
  72. menu="settings",
  73. scroll="settings",
  74. <<<<<<< HEAD
  75. icon=wicon,
  76. string="World: "+game.worlds[game.settings["world"]]["title"],
  77. func=do)
  78. current_Y += 15
  79. # List of worlds
  80. if game.current["settings_world_active"]:
  81. for world in game.worlds:
  82. def do():
  83. game.settings["world"] = world
  84. game.current["settings_world_active"] = False
  85. game.menus = {}
  86. save_settings(game)
  87. wicon = "radio_false"
  88. if game.settings["world"] == world:
  89. wicon = "radio_true"
  90. ui.button(game, layer,
  91. 15,
  92. current_Y+25,
  93. int(game.current["w"]) - 36 ,
  94. 13,
  95. menu="settings",
  96. scroll="settings",
  97. icon=wicon,
  98. string=str(game.worlds[world]["title"]),
  99. =======
  100. <<<<<<< HEAD
  101. icon=wicon,
  102. =======
  103. >>>>>>> 4cee21d (made game red)
  104. string="World: I'm Not Even Human",
  105. func=do)
  106. current_Y += 15
  107. <<<<<<< HEAD
  108. # List of worlds
  109. if game.current["settings_world_active"]:
  110. for world in os.listdir(os.getcwd()+"/assets/worlds"):
  111. def do():
  112. print(world)
  113. ui.button(game, layer,
  114. 15,
  115. current_Y+25,
  116. int(game.current["w"]) - 37 ,
  117. 13,
  118. menu="settings",
  119. scroll="settings",
  120. icon="radio_false",
  121. string=str(world),
  122. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  123. func=do)
  124. # Editor
  125. def do():
  126. <<<<<<< HEAD
  127. game.settings["world"] = world
  128. game.current["settings_world_active"] = False
  129. game.menus = {}
  130. save_settings(game)
  131. game.scene = "editor"
  132. =======
  133. print("edit")
  134. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  135. ui.button(game, layer,
  136. game.current["w"]-19,
  137. current_Y+25,
  138. 13,
  139. 13,
  140. menu="settings",
  141. scroll="settings",
  142. icon="edit",
  143. func=do)
  144. current_Y += 15
  145. <<<<<<< HEAD
  146. # PIXELS PER PIXEL
  147. =======
  148. =======
  149. # Pixels Per Pixels
  150. ui.color(game, layer, "#FF0000")
  151. ui.text(game, layer, "Pixels size: ",
  152. 5,
  153. current_Y+28+game.scroll["settings"])
  154. def do():
  155. game.settings["pixels"] += 1
  156. ui.button(game, layer,
  157. game.current["w"]-75,
  158. current_Y+25,
  159. 13,
  160. 13,
  161. menu="settings",
  162. scroll="settings",
  163. string="+",
  164. func=do)
  165. ui.color(game, layer, "#FF0000")
  166. ui.text(game, layer, str(game.settings["pixels"]),
  167. game.current["w"]-50,
  168. current_Y+28+game.scroll["settings"])
  169. def do():
  170. game.settings["pixels"] -= 1
  171. if game.settings["pixels"] < 1:
  172. game.settings["pixels"] = 1
  173. ui.button(game, layer,
  174. game.current["w"]-19,
  175. current_Y+25,
  176. 13,
  177. 13,
  178. menu="settings",
  179. scroll="settings",
  180. string="-",
  181. func=do)
  182. current_Y += 15
  183. >>>>>>> 4cee21d (made game red)
  184. # PIXELS PER PIXEL
  185. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  186. ui.color(game, layer, "#00FF00")
  187. ui.text(game, layer, "Pixels size: ",
  188. 5,
  189. current_Y+28+game.scroll["settings"])
  190. def do():
  191. game.settings["pixels"] += 1
  192. <<<<<<< HEAD
  193. save_settings(game)
  194. =======
  195. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  196. ui.button(game, layer,
  197. game.current["w"]-75,
  198. current_Y+25,
  199. 13,
  200. 13,
  201. menu="settings",
  202. scroll="settings",
  203. string="+",
  204. func=do)
  205. ui.color(game, layer, "#00FF00")
  206. ui.text(game, layer, str(game.settings["pixels"]),
  207. game.current["w"]-50,
  208. current_Y+28+game.scroll["settings"])
  209. def do():
  210. game.settings["pixels"] -= 1
  211. if game.settings["pixels"] < 1:
  212. game.settings["pixels"] = 1
  213. <<<<<<< HEAD
  214. save_settings(game)
  215. =======
  216. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  217. ui.button(game, layer,
  218. game.current["w"]-19,
  219. current_Y+25,
  220. 13,
  221. 13,
  222. menu="settings",
  223. scroll="settings",
  224. string="-",
  225. func=do)
  226. current_Y += 15
  227. # FULLSCREEN
  228. ficon = "fullscreen"
  229. if game.settings["fullscreen"]:
  230. ficon = "unfullscreen"
  231. def do():
  232. game.settings["fullscreen"] = not game.settings["fullscreen"]
  233. <<<<<<< HEAD
  234. save_settings(game)
  235. =======
  236. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  237. ui.button(game, layer,
  238. 5,
  239. current_Y+25,
  240. <<<<<<< HEAD
  241. int(game.current["w"]/2) - 5,
  242. =======
  243. int(game.current["w"]/2) - 10,
  244. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  245. 13,
  246. menu="settings",
  247. scroll="settings",
  248. icon=ficon,
  249. string="Fullscreen",
  250. func=do)
  251. # TESTING MODE
  252. dicon = "false"
  253. if game.current["testing"]:
  254. dicon = "true"
  255. def do():
  256. game.current["testing"] = not game.current["testing"]
  257. ui.button(game, layer,
  258. <<<<<<< HEAD
  259. int(game.current["w"]/2) + 2,
  260. current_Y+25,
  261. int(game.current["w"]/2) - 8,
  262. =======
  263. int(game.current["w"]/2) + 4,
  264. current_Y+25,
  265. int(game.current["w"]/2) - 10,
  266. >>>>>>> 4f59bf84d5c1dc67fcc03c78488f20af217ceab7
  267. 13,
  268. menu="settings",
  269. scroll="settings",
  270. icon=dicon,
  271. string="Debug Mode",
  272. func=do)
  273. current_Y += 15
  274. ui.scroll_area(game, layer, "settings", 5,20,
  275. game.current["w"]-10,
  276. game.current["h"]-25,
  277. current_Y)
  278. # Navigating the menus
  279. ui.button_navigate(game, "settings")
  280. return surface
  281. def update_worlds(game):
  282. """This function updates the selection of playable worlds."""
  283. game.worlds = {}
  284. for world in os.listdir(os.getcwd()+"/assets/worlds"):
  285. try:
  286. with open("assets/worlds/"+world+"/world.json") as f:
  287. metadata = json.load(f)
  288. except:
  289. metadata = {"title":world}
  290. game.worlds[world] = metadata
  291. def get_settings_folder(folder="ineh/"):
  292. try:
  293. data_dir = os.environ["XDG_DATA_HOME"] + "/" + folder
  294. except:
  295. data_dir = os.path.expanduser("~/.local/share/"+folder)
  296. try:
  297. os.makedirs(data_dir)
  298. except:
  299. pass
  300. return data_dir
  301. def save_settings(game):
  302. """This function saves the settings"""
  303. with open(get_settings_folder()+"config.json", 'w') as f:
  304. json.dump(game.settings, f, indent=4, sort_keys=True)
  305. def load_settings(game):
  306. """This function loads settings, or creates the settings
  307. from defautls"""
  308. defaults = {
  309. "pixels":4, # How big are pixels on the screen
  310. "fullscreen":False, # Whether the games is fullscreen
  311. "world":"ImNotEvenHuman"} # What wold you are playing
  312. try:
  313. with open(get_settings_folder()+"config.json") as f:
  314. game.settings = json.load(f)
  315. except:
  316. game.settings = defaults