Commit d00b31bd33e0475cca948e3eb1aba185215da474

Authored by dg
1 parent c10fc8f2

The new game window can now be told to force loading of an incompatible module (…

…which will usually work anyway)


git-svn-id: http://svn.net-core.org/repos/t-engine4@3367 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -34,14 +34,14 @@ end
34 34
35 35 --- List all available modules
36 36 -- Static
37   -function _M:listModules()
  37 +function _M:listModules(incompatible)
38 38 local ms = {}
39 39 fs.mount(engine.homepath, "/")
40 40 -- print("Search Path: ") for k,e in ipairs(fs.getSearchPath()) do print("*",k,e) end
41 41
42 42 local knowns = {}
43 43 for i, short_name in ipairs(fs.list("/modules/")) do
44   - local mod = self:createModule(short_name)
  44 + local mod = self:createModule(short_name, incompatible)
45 45 if mod then
46 46 if not knowns[mod.short_name] then
47 47 table.insert(ms, {short_name=mod.short_name, name=mod.name, versions={}})
... ... @@ -76,11 +76,11 @@ function _M:listModules()
76 76 return ms
77 77 end
78 78
79   -function _M:createModule(short_name)
  79 +function _M:createModule(short_name, incompatible)
80 80 local dir = "/modules/"..short_name
81 81 print("Creating module", short_name, ":: (as dir)", fs.exists(dir.."/init.lua"), ":: (as team)", short_name:find(".team$"), "")
82 82 if fs.exists(dir.."/init.lua") then
83   - local mod = self:loadDefinition(dir)
  83 + local mod = self:loadDefinition(dir, nil, incompatible)
84 84 if mod and mod.short_name then
85 85 return mod
86 86 end
... ... @@ -88,7 +88,7 @@ function _M:createModule(short_name)
88 88 fs.mount(fs.getRealPath(dir), "/testload", false)
89 89 local mod
90 90 if fs.exists("/testload/mod/init.lua") then
91   - mod = self:loadDefinition("/testload", dir)
  91 + mod = self:loadDefinition("/testload", dir, incompatible)
92 92 end
93 93 fs.umount(fs.getRealPath(dir))
94 94 if mod and mod.short_name then return mod end
... ... @@ -96,7 +96,7 @@ function _M:createModule(short_name)
96 96 end
97 97
98 98 --- Get a module definition from the module init.lua file
99   -function _M:loadDefinition(dir, team)
  99 +function _M:loadDefinition(dir, team, incompatible)
100 100 local mod_def = loadfile(team and (dir.."/mod/init.lua") or (dir.."/init.lua"))
101 101 -- print("Loading module definition from", team and (dir.."/mod/init.lua") or (dir.."/init.lua"))
102 102 if mod_def then
... ... @@ -116,7 +116,8 @@ function _M:loadDefinition(dir, team)
116 116 mod.version_string = self:versionString(mod)
117 117 if not __available_engines.__byname[eng_req] then
118 118 print("Module mismatch engine version "..mod.version_string.." using engine "..eng_req)
119   - return
  119 + if incompatible then mod.incompatible = true
  120 + else return end
120 121 end
121 122
122 123 -- Make a function to activate it
... ... @@ -186,7 +187,9 @@ function _M:instanciate(mod, name, new_game, no_reboot)
186 187 popup.__showup = nil
187 188 core.display.forceRedraw()
188 189
189   - util.showMainMenu(false, mod.engine[4], ("%d.%d.%d"):format(mod.engine[1], mod.engine[2], mod.engine[3]), mod.version_string, name, new_game)
  190 + local eng_v = nil
  191 + if not mod.incompatible then eng_v = ("%d.%d.%d"):format(mod.engine[1], mod.engine[2], mod.engine[3]) end
  192 + util.showMainMenu(false, mod.engine[4], eng_v, mod.version_string, name, new_game)
190 193 return
191 194 end
192 195
... ...
... ... @@ -28,7 +28,7 @@ function _M:init(t)
28 28 self.title = assert(t.title, "no checkbox title")
29 29 self.text = t.text or ""
30 30 self.checked = t.default
31   - self.fct = assert(t.fct, "no checkbox fct")
  31 + self.fct = t.fct or function() end
32 32 self.on_change = t.on_change
33 33
34 34 Base.init(self, t)
... ...
... ... @@ -962,7 +962,7 @@ function util.showMainMenu(no_reboot, reboot_engine, reboot_engine_version, rebo
962 962
963 963 if no_reboot then
964 964 local Module = require("engine.Module")
965   - local ms = Module:listModules()
  965 + local ms = Module:listModules(true)
966 966 local mod = ms[__load_module]
967 967 Module:instanciate(mod, __player_name, __player_new, true)
968 968 else
... ...
... ... @@ -23,6 +23,7 @@ local Dialog = require "engine.ui.Dialog"
23 23 local ListColumns = require "engine.ui.ListColumns"
24 24 local Textzone = require "engine.ui.Textzone"
25 25 local Separator = require "engine.ui.Separator"
  26 +local Checkbox = require "engine.ui.Checkbox"
26 27 local Button = require "engine.ui.Button"
27 28
28 29 module(..., package.seeall, class.inherit(Dialog))
... ... @@ -32,11 +33,12 @@ function _M:init()
32 33
33 34 self.c_desc = Textzone.new{width=math.floor(self.iw / 3 * 2 - 10), height=self.ih, text=""}
34 35
35   - self.c_switch = Button.new{width=math.floor(self.iw / 3 - 40), text="Show all versions", fct=function() self:switchVersions() end}
  36 + self.c_switch = Checkbox.new{default=false, width=math.floor(self.iw / 3 - 40), title="Show all versions", on_change=function() self:switch() end}
  37 + self.c_compat = Checkbox.new{default=false, width=math.floor(self.iw / 3 - 40), title="Show incompatible", on_change=function() self:switch() end}
36 38
37 39 self:generateList()
38 40
39   - self.c_list = ListColumns.new{width=math.floor(self.iw / 3 - 10), height=self.ih - 10 - self.c_switch.h, scrollbar=true, columns={
  41 + self.c_list = ListColumns.new{width=math.floor(self.iw / 3 - 10), height=self.ih - 10 - self.c_switch.h - self.c_compat.h, scrollbar=true, columns={
40 42 {name="Game Module", width=80, display_prop="name"},
41 43 {name="Version", width=20, display_prop="version_txt"},
42 44 }, list=self.list, fct=function(item) end, select=function(item, sel) self:select(item) end}
... ... @@ -44,7 +46,8 @@ function _M:init()
44 46 self:loadUI{
45 47 {left=0, top=0, ui=self.c_list},
46 48 {right=0, top=0, ui=self.c_desc},
47   - {left=0, bottom=0, ui=self.c_switch},
  49 + {left=0, bottom=self.c_compat.h, ui=self.c_switch},
  50 + {left=0, bottom=0, ui=self.c_compat},
48 51 {left=self.c_list.w + 5, top=5, ui=Separator.new{dir="horizontal", size=self.ih - 10}},
49 52 }
50 53 self:setFocus(self.c_list)
... ... @@ -64,16 +67,16 @@ function _M:select(item)
64 67 end
65 68
66 69 function _M:generateList()
67   - local list = Module:listModules()
  70 + local list = Module:listModules(self.c_compat.checked)
68 71 self.list = {}
69 72 for i = 1, #list do
70 73 for j, mod in ipairs(list[i].versions) do
71   - if not self.all_versions and j > 1 then break end
  74 + if not self.c_switch.checked and j > 1 then break end
72 75 if not mod.is_boot then
73 76 mod.name = tstring{{"font","bold"}, {"color","GOLD"}, mod.name, {"font","normal"}}
74 77 mod.fct = function(mod)
75 78 if mod.no_get_name then
76   - Module:instanciate(mod, "player", true)
  79 + Module:instanciate(mod, "player", true, false)
77 80 else
78 81 game:registerDialog(require('engine.dialogs.GetText').new("Enter your character's name", "Name", 2, 25, function(text)
79 82 local savename = text:gsub("[^a-zA-Z0-9_-.]", "_")
... ... @@ -88,7 +91,11 @@ function _M:generateList()
88 91 end
89 92 end
90 93 mod.version_txt = ("%d.%d.%d"):format(mod.version[1], mod.version[2], mod.version[3])
91   - mod.zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="#{bold}##GOLD#"..mod.long_name.."#WHITE##{normal}#\n\n"..mod.description}
  94 + local tstr = tstring{{"font","bold"}, {"color","GOLD"}, mod.long_name, true, true}
  95 + if mod.incompatible then tstr:add({"font","bold"}, {"color","LIGHT_RED"}, "This game is not compatible with your version of T-Engine, you can still try it but it might break.", true, true) end
  96 + tstr:add({"font","normal"}, {"color","WHITE"})
  97 + tstr:merge(mod.description:toTString())
  98 + mod.zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=tstr}
92 99
93 100 table.insert(self.list, mod)
94 101 end
... ... @@ -96,11 +103,8 @@ function _M:generateList()
96 103 end
97 104 end
98 105
99   -function _M:switchVersions()
100   - self.all_versions = not self.all_versions
  106 +function _M:switch()
101 107 self:generateList()
102 108 self.c_list.list = self.list
103 109 self.c_list:generate()
104   - self.c_switch.text = self.all_versions and "Show only new versions" or "Show all versions"
105   - self.c_switch:generate()
106 110 end
... ...