1--       _________ __                 __
2--      /   _____//  |_____________ _/  |______     ____  __ __  ______
3--      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
4--      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
5--     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
6--             \/                  \/          \//_____/            \/
7--  ______________________                           ______________________
8--                        T H E   W A R   B E G I N S
9--         Stratagus - A free fantasy real time strategy game engine
10--
11--	(c) Copyright 2013 by Kyran Jackson
12--
13--      This program is free software; you can redistribute it and/or modify
14--      it under the terms of the GNU General Public License as published by
15--      the Free Software Foundation; either version 2 of the License, or
16--      (at your option) any later version.
17--
18--      This program is distributed in the hope that it will be useful,
19--      but WITHOUT ANY WARRANTY; without even the implied warranty of
20--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21--      GNU General Public License for more details.
22--
23--      You should have received a copy of the GNU General Public License
24--      along with this program; if not, write to the Free Software
25--      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26--
27
28OldRunSinglePlayerGameMenu = RunSinglePlayerGameMenu
29
30function StartCustomGame_Lua()
31	RunSinglePlayerGameMenu = NewRunSinglePlayerGameMenu
32
33	SetTrainingQueue(false)
34
35end
36
37function CleanCustomGame_Lua()
38	RunSinglePlayerGameMenu = OldRunSinglePlayerGameMenu
39
40	SetTrainingQueue(true)
41end
42
43function NewRunSinglePlayerGameMenu()
44  local menu = WarMenu()
45  local offx = (Video.Width - 640) / 2
46  local offy = (Video.Height - 480) / 2
47  local d
48  local race
49  local resources
50  local opponents
51  local numunits
52  local gametype
53  local mapl
54  local descriptionl
55  local tilesetdd
56
57  menu:addLabel(wargus.Name .. " V" .. wargus.Version .. ", " .. wargus.Copyright, offx + 320, (Video.Height - 90) + 18*4, Fonts["small"]) -- Copyright information.
58
59  menu:addLabel(_("Scenario:"), offx + 16, offy + 360, Fonts["game"], false)
60  mapl = menu:addLabel(string.sub(mapname, 6), offx + 16, offy + 360 + 24, Fonts["game"], false)
61  descriptionl = menu:addLabel("descriptionl", offx + 16 + 70, offy + 360, Fonts["game"], false)
62
63  menu:addLabel(_("~<Single Player Game Setup~>"), offx + 640/2 + 12, offy + 192)
64  menu:addFullButton(_("S~!elect Scenario"), "e", offx + 640 - 224 - 16, offy + 360 + 36*0,
65    function()
66      local oldmapname = mapname
67      RunSelectScenarioMenu()
68      if (mapname ~= oldmapname) then
69        GetMapInfo(mapname)
70        MapChanged()
71      end
72    end)
73  menu:addFullButton(_("~!Start Game"), "s", offx + 640 - 224 - 16, offy + 360 + 36*1,
74    function()
75      local tilesetFilename = {nil, "summer.lua", "swamp.lua", "wasteland.lua", "winter.lua"};
76
77      GameSettings.Presets[0].Race = race:getSelected()
78      GameSettings.Resources = resources:getSelected()
79      GameSettings.Opponents = opponents:getSelected()
80      GameSettings.NumUnits = numunits:getSelected()
81      GameSettings.GameType = gametype:getSelected() - 1
82      GameSettings.Tileset = tilesetFilename[tilesetdd:getSelected() + 1]
83	    IsSkirmishClassic = true
84      RunMap(mapname, nil, wc2.preferences.FogOfWar, 0)
85      menu:stop()
86    end)
87  menu:addFullButton(_("~!Cancel Game"), "c", offx + 640 - 224 - 16, offy + 360 + 36*2, function() CleanCustomGame_Lua(); menu:stop(1); RunSinglePlayerTypeMenu() end)
88
89  menu:addLabel(_("~<Your Race:~>"), offx + 40, offy + (10 + 240) - 20, Fonts["game"], false)
90  race = menu:addDropDown({_("Map Default"), _("Human"), _("Orc")}, offx + 40, offy + 10 + 240,
91    function(dd) end)
92  race:setSize(152, 20)
93
94  menu:addLabel(_("~<Resources:~>"), offx + 220, offy + (10 + 240) - 20, Fonts["game"], false)
95  resources = menu:addDropDown({_("Map Default"), _("Low"), _("Medium"), _("High")}, offx + 220, offy + 10 + 240,
96    function(dd) end)
97  resources:setSize(152, 20)
98
99  menu:addLabel(_("~<Units:~>"), offx + 640 - 224 - 16, offy + (10 + 240) - 20, Fonts["game"], false)
100  numunits = menu:addDropDown({_("Map Default"), _("One Peasant Only")}, offx + 640 - 224 - 16, offy + 10 + 240,
101    function(dd) end)
102  numunits:setSize(190, 20)
103
104  local opponents_list = {_("Map Default"), _("1 Opponent"), _("2 Opponents"),
105    _("3 Opponents"), _("4 Opponents"), _("5 Opponents"), _("6 Opponents"), _("7 Opponents")}
106
107  menu:addLabel(_("~<Opponents:~>"), offx + 40, offy + (10 + 300) - 20, Fonts["game"], false)
108  opponents = menu:addDropDown(opponents_list, offx + 40, offy + 10 + 300,
109    function(dd) end)
110  opponents:setSize(152, 20)
111
112  menu:addLabel("~<Game Type:~>", offx + 220, offy + (10 + 300) - 20, Fonts["game"], false)
113  gametype = menu:addDropDown({_("Use map settings"), _("Melee"), _("Free for all"), _("Top vs bottom"), _("Left vs right"), _("Man vs Machine")}, offx + 220, offy + 10 + 300,
114    function(dd) end)
115  gametype:setSize(152, 20)
116
117  menu:addLabel(_("~<Tileset:~>"), offx + 640 - 224 - 16, offy + (10 + 300) - 20, Fonts["game"], false)
118  tilesetdd = menu:addDropDown({_("Map Default"), _("Summer"), _("Swamp"), _("Wasteland"), _("Winter")}, offx + 640 - 224 - 16, offy + 10 + 300,
119    function(dd) end)
120  tilesetdd:setSize(190, 20)
121
122  function MapChanged()
123    mapl:setCaption(string.sub(mapname, 6))
124    mapl:adjustSize()
125
126    descriptionl:setCaption(mapinfo.description ..
127      " (" .. mapinfo.w .. " x " .. mapinfo.h .. ")")
128    descriptionl:adjustSize()
129
130    local o = {}
131    for i=1,mapinfo.nplayers do
132      table.insert(o, opponents_list[i])
133    end
134    opponents:setList(o)
135	opponents:setSize(152, 20)
136  end
137
138  GetMapInfo(mapname)
139  MapChanged()
140
141  menu:run()
142end
143
144StartCustomGame_Lua()
145
146RunSinglePlayerGameMenu()
147