aboutsummaryrefslogtreecommitdiff
path: root/src/script/scripting_mainmenu.cpp
blob: d79864a9544330ad53383203098d7b86d791efc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "scripting_mainmenu.h"
#include "mods.h"
#include "cpp_api/s_internal.h"
#include "lua_api/l_base.h"
#include "lua_api/l_mainmenu.h"
#include "lua_api/l_sound.h"
#include "lua_api/l_util.h"
#include "lua_api/l_settings.h"

extern "C" {
#include "lualib.h"
}

#define MAINMENU_NUM_ASYNC_THREADS 4


MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
{
	setGuiEngine(guiengine);

	SCRIPTAPI_PRECHECKHEADER

	lua_getglobal(L, "core");
	int top = lua_gettop(L);

	lua_newtable(L);
	lua_setglobal(L, "gamedata");

	// Initialize our lua_api modules
	initializeModApi(L, top);
	lua_pop(L, 1);

	// Push builtin initialization type
	lua_pushstring(L, "mainmenu");
	lua_setglobal(L, "INIT");

	infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
}

/******************************************************************************/
void MainMenuScripting::initializeModApi(lua_State *L, int top)
{
	// Initialize mod API modules
	ModApiMainMenu::Initialize(L, top);
	ModApiUtil::Initialize(L, top);
	ModApiSound::Initialize(L, top);

	// Register reference classes (userdata)
	LuaSettings::Register(L);

	// Register functions to async environment
	ModApiMainMenu::InitializeAsync(asyncEngine);
	ModApiUtil::InitializeAsync(asyncEngine);

	// Initialize async environment
	//TODO possibly make number of async threads configurable
	asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS);
}

/******************************************************************************/
void MainMenuScripting::step()
{
	asyncEngine.step(getStack());
}

/******************************************************************************/
unsigned int MainMenuScripting::queueAsync(const std::string &serialized_func,
		const std::string &serialized_param)
{
	return asyncEngine.queueAsyncJob(serialized_func, serialized_param);
}

#n344'>344
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="512"
   height="512"
   viewBox="0 0 135.46666 135.46667"
   version="1.1"
   id="svg8"
   inkscape:version="0.92.1 r15371"
   sodipodi:docname="debug_btn.svg"
   inkscape:export-filename="/home/stu/Desktop/icons/png/debug_btn.png"
   inkscape:export-xdpi="24"
   inkscape:export-ydpi="24">
  <defs
     id="defs2">
    <marker
       style="overflow:visible"
       refY="0.0"
       refX="0.0"
       orient="auto"
       id="DistanceX">
      <path
         id="path4687"
         style="stroke:#000000; stroke-width:0.5"
         d="M 3,-3 L -3,3 M 0,-5 L  0,5" />
    </marker>
    <pattern
       y="0"
       x="0"
       width="8"
       patternUnits="userSpaceOnUse"
       id="Hatch"
       height="8">
      <path
         id="path4690"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M8 4 l-4,4" />
      <path
         id="path4692"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M6 2 l-4,4" />
      <path
         id="path4694"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M4 0 l-4,4" />
    </pattern>
    <marker
       style="overflow:visible"
       refY="0.0"
       refX="0.0"
       orient="auto"
       id="DistanceX-3">
      <path
         id="path4756"
         style="stroke:#000000; stroke-width:0.5"
         d="M 3,-3 L -3,3 M 0,-5 L  0,5" />
    </marker>
    <pattern
       y="0"
       x="0"
       width="8"
       patternUnits="userSpaceOnUse"
       id="Hatch-6"
       height="8">
      <path
         id="path4759"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M8 4 l-4,4" />
      <path
         id="path4761"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M6 2 l-4,4" />
      <path
         id="path4763"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M4 0 l-4,4" />
    </pattern>
    <marker
       style="overflow:visible"
       refY="0.0"
       refX="0.0"
       orient="auto"
       id="DistanceX-7">
      <path
         id="path4920"
         style="stroke:#000000; stroke-width:0.5"
         d="M 3,-3 L -3,3 M 0,-5 L  0,5" />
    </marker>
    <pattern
       y="0"
       x="0"
       width="8"
       patternUnits="userSpaceOnUse"
       id="Hatch-5"
       height="8">
      <path
         id="path4923"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M8 4 l-4,4" />
      <path
         id="path4925"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M6 2 l-4,4" />
      <path
         id="path4927"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M4 0 l-4,4" />
    </pattern>
    <symbol
       id="*Model_Space" />
    <symbol
       id="*Paper_Space" />
    <marker
       style="overflow:visible"
       refY="0.0"
       refX="0.0"
       orient="auto"
       id="DistanceX-35">
      <path
         id="path4984"
         style="stroke:#000000; stroke-width:0.5"
         d="M 3,-3 L -3,3 M 0,-5 L  0,5" />
    </marker>
    <pattern
       y="0"
       x="0"
       width="8"
       patternUnits="userSpaceOnUse"
       id="Hatch-62"
       height="8">
      <path
         id="path4987"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M8 4 l-4,4" />
      <path
         id="path4989"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M6 2 l-4,4" />
      <path
         id="path4991"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M4 0 l-4,4" />
    </pattern>
    <marker
       style="overflow:visible"
       refY="0.0"
       refX="0.0"
       orient="auto"
       id="DistanceX-9">
      <path
         id="path5044"
         style="stroke:#000000; stroke-width:0.5"
         d="M 3,-3 L -3,3 M 0,-5 L  0,5" />
    </marker>
    <pattern
       y="0"
       x="0"
       width="8"
       patternUnits="userSpaceOnUse"
       id="Hatch-1"
       height="8">
      <path
         id="path5047"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M8 4 l-4,4" />
      <path
         id="path5049"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M6 2 l-4,4" />
      <path
         id="path5051"
         stroke-width="0.25"
         stroke="#000000"
         linecap="square"
         d="M4 0 l-4,4" />
    </pattern>
  </defs>
  <sodipodi:namedview
     id="base"
     pagecolor="#404040"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0"
     inkscape:pageshadow="2"
     inkscape:zoom="0.61928482"
     inkscape:cx="-121.31078"
     inkscape:cy="141.55076"
     inkscape:document-units="mm"
     inkscape:current-layer="layer1"
     showgrid="true"
     units="px"
     inkscape:window-width="1920"
     inkscape:window-height="1023"
     inkscape:window-x="0"
     inkscape:window-y="34"
     inkscape:window-maximized="1"
     inkscape:pagecheckerboard="false"
     inkscape:snap-global="true"
     inkscape:snap-grids="false">
    <inkscape:grid
       type="xygrid"
       id="grid16"
       spacingx="4.2333333"
       spacingy="4.2333333"
       empspacing="1"
       color="#40ff40"
       opacity="0.1254902"
       empcolor="#40ff40"
       empopacity="0.25098039" />
  </sodipodi:namedview>
  <metadata
     id="metadata5">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
        <cc:license
           rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
      </cc:Work>
      <cc:License
         rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
        <cc:permits
           rdf:resource="http://creativecommons.org/ns#Reproduction" />
        <cc:permits
           rdf:resource="http://creativecommons.org/ns#Distribution" />
        <cc:requires
           rdf:resource="http://creativecommons.org/ns#Notice" />
        <cc:requires
           rdf:resource="http://creativecommons.org/ns#Attribution" />
        <cc:permits
           rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
        <cc:requires
           rdf:resource="http://creativecommons.org/ns#ShareAlike" />
      </cc:License>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(0,-161.53332)">
    <g
       id="g4960"
       transform="matrix(0.356623,0,0,0.356623,38.15173,-196.45162)"
       style="stroke:#ffffff;stroke-width:1.40204081;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">
      <g
         id="g4934"
         inkscape:label="0"
         style="stroke:#ffffff;stroke-width:1.40204081;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
      <g
         id="g4940"
         inkscape:label="OpenJsCad"
         style="stroke:#ffffff;stroke-width:1.40204081;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">
        <path
           style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:1.40204081;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
           d="m 39.984833,1063.9015 -3.428448,0.3376 -1.443251,2.4866 -1.853336,4.4442 -0.931739,3.4444 -0.307197,2.2939 -0.003,1.0665 0.191273,1.4737 -0.201415,2.8328 -0.908554,1.5085 -8.44071,1.6795 -1.41862,-1.0448 -1.269369,-2.5402 -0.388347,-1.436 -0.410078,-0.9825 -1.16214,-2.004 -2.177924,-2.8242 -3.413958,-3.398 -2.283698,-1.7447 -3.2980381,0.9999 -3.0372074,1.6258 -0.3825491,2.8474 -0.013043,4.8166 0.4593482,3.5372 0.5941108,2.2373 0.4057338,0.9868 0.7404643,1.2882 0.8984102,2.6938 -0.2637272,1.7417 -7.1554054,4.7819 -1.7098778,-0.4231 -2.146042,-1.862 -0.9056565,-1.1752 -0.7564036,-0.7521 -1.8417418,-1.407 -3.0922714,-1.7751 -4.452928,-1.8345 -2.779276,-0.7361 -2.663353,2.1852 -2.186616,2.6648 0.739015,2.7778 1.831599,4.4529 1.777983,3.0937 1.404129,1.8389 0.752056,0.7564 1.176629,0.9085 1.862028,2.1446 0.423122,1.7114 -4.780413,7.1554 -1.741758,0.2622 -2.693782,-0.8984 -1.289654,-0.7404 -0.985354,-0.4058 -2.238781,-0.5941 -3.53713,-0.4579 -4.816639,0.01 -2.848832,0.3825 -1.622935,3.0401 -1.002742,3.2966 1.746104,2.2852 3.396572,3.4125 2.824197,2.1779 2.004036,1.1636 0.983904,0.4101 1.434559,0.3869 2.540184,1.2693 1.047662,1.4172 -1.680897,8.4422 -1.50846,0.91 -2.832891,0.1999 -1.475133,-0.1898 h -1.063603 l -2.296743,0.3058 -3.441491,0.9317 -4.447133,1.8533 -2.485119,1.4447 -0.337629,3.427 0.337629,3.43 2.485119,1.4432 4.447133,1.8533 3.441491,0.9318 2.296743,0.3072 h 1.063603 l 1.475133,-0.1913 2.832891,0.2 1.50846,0.91 1.680897,8.4421 -1.047662,1.4187 -2.540184,1.2693 -1.434559,0.3869 -0.983904,0.4101 -2.004036,1.1636 -2.824197,2.175 -3.396572,3.414 -1.746104,2.2851 1.002742,3.2981 1.622935,3.0386 2.848832,0.3811 4.816639,0.012 3.53713,-0.4579 2.238781,-0.5927 0.985354,-0.4072 1.289654,-0.739 2.693782,-0.8984 1.741758,0.2608 4.780413,7.1569 -0.423122,1.7099 -1.862028,2.1446 -1.176629,0.9085 -0.752056,0.7564 -1.404129,1.8389 -1.777983,3.0922 -1.831599,4.4559 -0.739015,2.7763 2.186616,2.6648 2.663353,2.1852 2.779276,-0.7361 4.452928,-1.8345 3.0922714,-1.7751 1.8417418,-1.4056 0.7564036,-0.752 0.9056565,-1.1781 2.146042,-1.862 1.7098778,-0.4231 7.1554054,4.7833 0.2637272,1.7417 -0.8984102,2.6938 -0.7404643,1.2882 -0.4057338,0.9854 -0.5941108,2.2402 -0.4593482,3.5371 0.013043,4.8167 0.3825491,2.8473 3.0372074,1.6244 3.2980381,0.9999 2.283698,-1.7432 3.413958,-3.3995 2.177924,-2.8242 1.16214,-2.004 0.410078,-0.9839 0.388347,-1.4332 1.269369,-2.5416 1.41862,-1.0447 8.44071,1.678 0.908554,1.5099 0.201415,2.8314 -0.191273,1.4751 0.003,1.0665 0.307197,2.2953 0.931739,3.443 1.853336,4.4456 1.443251,2.4852 3.428448,0.339 3.429902,-0.339 1.443252,-2.4852 1.853336,-4.4456 0.928839,-3.443 0.30865,-2.2953 0.003,-1.0665 -0.189826,-1.4751 0.198521,-2.8314 0.911455,-1.5099 8.44071,-1.678 1.41862,1.0447 1.269369,2.5416 0.386893,1.4332 0.410085,0.9839 1.163587,2.004 2.177917,2.8242 3.412511,3.3995 2.285152,1.7432 3.296588,-0.9999 3.038654,-1.6244 0.382553,-2.8473 0.01016,-4.8167 -0.456447,-3.5371 -0.594117,-2.2402 -0.40573,-0.9854 -0.740467,-1.2882 -0.898412,-2.6938 0.263728,-1.7417 7.153958,-4.7833 1.711327,0.4231 2.144596,1.862 0.907101,1.1781 0.756403,0.752 1.840293,1.4056 3.093726,1.7751 4.452927,1.8345 2.77638,0.7361 2.664803,-2.1852 2.18517,-2.6648 -0.73612,-2.7763 -1.8345,-4.4559 -1.775089,-3.0922 -1.405577,-1.8389 -0.752055,-0.7564 -1.17663,-0.9085 -1.860578,-2.1446 -0.424575,-1.7099 4.781869,-7.1569 1.741753,-0.2608 2.693782,0.8984 1.28966,0.739 0.98535,0.4072 2.23879,0.5927 3.53713,0.4579 4.81663,-0.012 2.84738,-0.3811 v 0.01 l 1.62439,-3.0386 0.99984,-3.2995 -1.74321,-2.2822 -3.39801,-3.414 -2.8242,-2.1779 -2.00404,-1.1622 -0.98245,-0.41 -1.43601,-0.3898 -2.54163,-1.2694 -1.04477,-1.4172 1.67945,-8.4421 1.50846,-0.9071 2.83434,-0.2015 1.47224,0.1913 h 1.0665 l 2.29529,-0.3086 3.44294,-0.9303 4.44569,-1.8534 2.48656,-1.4432 0.33763,-3.4299 -0.33763,-3.4299 -2.48656,-1.4404 -4.44569,-1.8548 -3.44294,-0.9302 -2.29529,-0.3087 h -1.0665 l -1.47224,0.1913 -2.83434,-0.2014 -1.50846,-0.9086 -1.67945,-8.4407 1.04477,-1.4186 2.54163,-1.2694 1.43601,-0.3883 0.98245,-0.4101 2.00404,-1.1621 2.8242,-2.178 3.39801,-3.4139 1.74321,-2.2837 -0.99984,-3.2981 -1.62439,-3.0401 -2.84738,-0.3811 -4.81663,-0.012 -3.53713,0.4594 -2.23879,0.5941 -0.98535,0.4057 -1.28966,0.7405 -2.693782,0.8984 -1.741753,-0.2637 -4.781869,-7.1554 0.424575,-1.7099 1.860578,-2.146 1.17663,-0.9071 0.752055,-0.755 1.405577,-1.8417 1.775089,-3.0923 1.8345,-4.4529 0.73612,-2.7793 -2.18517,-2.6648 -2.664803,-2.1852 -2.77638,0.739 -4.452927,1.8316 -3.093726,1.778 -1.840293,1.4041 -0.756403,0.7521 -0.907101,1.1766 -2.144596,1.8621 -1.711327,0.4231 -7.153958,-4.7804 -0.263728,-1.7432 0.898412,-2.6924 0.740467,-1.2896 0.40573,-0.9854 0.594117,-2.2388 0.456447,-3.5371 -0.01016,-4.8166 -0.382553,-2.8503 -3.038654,-1.6229 -3.296588,-1.0013 -2.285152,1.7461 -3.412511,3.3965 -2.177917,2.8242 -1.163587,2.0041 -0.410085,0.9839 -0.386893,1.4331 -1.269369,2.5416 -1.41862,1.0477 -8.442156,-1.6809 -0.910009,-1.5099 -0.198521,-2.8315 0.189826,-1.4751 -0.003,-1.0636 -0.30865,-2.2982 -0.928839,-3.44 -1.853336,-4.4486 -1.443252,-2.4837 z m -0.240543,40.0198 c 25.773221,-10e-5 46.666641,20.855 46.666634,46.5812 0,25.7262 -20.89342,46.5813 -46.666634,46.5811 -25.773213,2e-4 -46.6666339,-20.8549 -46.6666309,-46.5811 -6.7e-6,-25.7262 20.8934179,-46.5813 46.6666309,-46.5812 z"
           id="path4936"
           inkscape:connector-curvature="0"
           sodipodi:nodetypes="cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccscsc" />
      </g>
    </g>
    <g
       id="g5020"
       transform="matrix(0.35552611,-0.02794902,0.02794902,0.35552611,64.796165,-192.13622)"
       style="stroke:#ffffff;stroke-width:1.40204084;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">
      <g
         id="g5000"
         inkscape:label="OpenJsCad"