textures.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. --Minetest
  2. --Copyright (C) 2013 sapier
  3. --
  4. --This program is free software; you can redistribute it and/or modify
  5. --it under the terms of the GNU Lesser General Public License as published by
  6. --the Free Software Foundation; either version 2.1 of the License, or
  7. --(at your option) any later version.
  8. --
  9. --This program is distributed in the hope that it will be useful,
  10. --but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. --GNU Lesser General Public License for more details.
  13. --
  14. --You should have received a copy of the GNU Lesser General Public License along
  15. --with this program; if not, write to the Free Software Foundation, Inc.,
  16. --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. mm_texture = {}
  18. --------------------------------------------------------------------------------
  19. function mm_texture.init()
  20. mm_texture.defaulttexturedir = core.get_texturepath() .. DIR_DELIM .. "base" ..
  21. DIR_DELIM .. "pack" .. DIR_DELIM
  22. mm_texture.basetexturedir = mm_texture.defaulttexturedir
  23. mm_texture.texturepack = core.setting_get("texture_path")
  24. mm_texture.gameid = nil
  25. end
  26. --------------------------------------------------------------------------------
  27. function mm_texture.update(tab,gamedetails)
  28. if tab ~= "singleplayer" then
  29. mm_texture.reset()
  30. return
  31. end
  32. if gamedetails == nil then
  33. return
  34. end
  35. mm_texture.update_game(gamedetails)
  36. end
  37. --------------------------------------------------------------------------------
  38. function mm_texture.reset()
  39. mm_texture.gameid = nil
  40. local have_bg = false
  41. local have_overlay = mm_texture.set_generic("overlay")
  42. if not have_overlay then
  43. have_bg = mm_texture.set_generic("background")
  44. end
  45. mm_texture.clear("header")
  46. mm_texture.clear("footer")
  47. core.set_clouds(false)
  48. mm_texture.set_generic("footer")
  49. mm_texture.set_generic("header")
  50. if not have_bg and
  51. core.setting_getbool("menu_clouds") then
  52. core.set_clouds(true)
  53. end
  54. end
  55. --------------------------------------------------------------------------------
  56. function mm_texture.update_game(gamedetails)
  57. if mm_texture.gameid == gamedetails.id then
  58. return
  59. end
  60. local have_bg = false
  61. local have_overlay = mm_texture.set_game("overlay",gamedetails)
  62. if not have_overlay then
  63. have_bg = mm_texture.set_game("background",gamedetails)
  64. end
  65. mm_texture.clear("header")
  66. mm_texture.clear("footer")
  67. core.set_clouds(false)
  68. if not have_bg and
  69. core.setting_getbool("menu_clouds") then
  70. core.set_clouds(true)
  71. end
  72. mm_texture.set_game("footer",gamedetails)
  73. mm_texture.set_game("header",gamedetails)
  74. mm_texture.gameid = gamedetails.id
  75. end
  76. --------------------------------------------------------------------------------
  77. function mm_texture.clear(identifier)
  78. core.set_background(identifier,"")
  79. end
  80. --------------------------------------------------------------------------------
  81. function mm_texture.set_generic(identifier)
  82. --try texture pack first
  83. if mm_texture.texturepack ~= nil then
  84. local path = mm_texture.texturepack .. DIR_DELIM .."menu_" ..
  85. identifier .. ".png"
  86. if core.set_background(identifier,path) then
  87. return true
  88. end
  89. end
  90. if mm_texture.defaulttexturedir ~= nil then
  91. local path = mm_texture.defaulttexturedir .. DIR_DELIM .."menu_" ..
  92. identifier .. ".png"
  93. if core.set_background(identifier,path) then
  94. return true
  95. end
  96. end
  97. return false
  98. end
  99. --------------------------------------------------------------------------------
  100. function mm_texture.set_game(identifier,gamedetails)
  101. if gamedetails == nil then
  102. return false
  103. end
  104. if mm_texture.texturepack ~= nil then
  105. local path = mm_texture.texturepack .. DIR_DELIM ..
  106. gamedetails.id .. "_menu_" .. identifier .. ".png"
  107. if core.set_background(identifier,path) then
  108. return true
  109. end
  110. end
  111. local path = gamedetails.path .. DIR_DELIM .."menu" ..
  112. DIR_DELIM .. identifier .. ".png"
  113. if core.set_background(identifier,path) then
  114. return true
  115. end
  116. return false
  117. end