aboutsummaryrefslogtreecommitdiff
path: root/views/script/menu_global.js
blob: 371359199e06f96aa9fa823bc3bbe6803a8e8b26 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
let menuOpen = true;

if (native) {global.$ = require('jquery');} else {var script = document.createElement('script');script.src = '../webinit/jquery.js';script.type = 'text/javascript';document.getElementsByTagName('head')[0].appendChild(script);}
$("#box").fadeOut(0);
window.addEventListener('load', () => {
    setTimeout(() => {
        $("#box").fadeIn(500);
    }, 1000)
})

$("body").focus();
keysEnabled = true;
$(document).keydown(function(e) {
    if (keysEnabled) {
        if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32) { // enter
            if ($(".services").is(":visible")) {
                selectOption();
            } else {
                $(".services").show();
            }
            menuOpen = !menuOpen;
        }
        if (e.keyCode === 38 || e.keyCode === 90) { // up
            Sound.menu();
            var selected = $(".selected");
            $(".services li").removeClass("selected");
            if (selected.prev().length === 0) {
                selected.siblings().last().addClass("selected");
            } else {
                selected.prev().addClass("selected");
            }
        }
        if (e.keyCode === 40 || e.keyCode === 83) { // down
            Sound.menu();
            var selected = $(".selected");
            $(".services li").removeClass("selected");
            if (selected.next().length === 0) {
                selected.siblings().first().addClass("selected");
            } else {
                selected.next().addClass("selected");
            }
        }
        if (e.keyCode === 27 || e.keyCode === 8) { // esc
            keysEnabled = false;
            Sound.click();
            setTimeout(() => {
                require('@electron/remote').getCurrentWindow().close();
            }, 250)
        }
    }
});

function selectOption() {
    item = document.querySelector(".selected a").id;
    Sound.click();

    switch (item) {
        case 'single':
            scenar("start", "happy");
            keysEnabled = false;
            require('electron').ipcRenderer.send('prefademusic', "");
            $("#box").fadeOut(500);
            setTimeout(() => {
                info("MenuWindow", "Switching control to GameWindow");
                location.href = "game.html?sp";
            }, 1000)
            break;
        case 'online':
            keysEnabled = false;
            require('electron').ipcRenderer.send('prefademusic', "");
            $("#box").fadeOut(500);
            setTimeout(() => {
                info("MenuWindow", "Switching control to GameWindow");
                location.href = "game.html?online";
            }, 1000)
            break;
        case 'play':
            keysEnabled = false;
            require('electron').ipcRenderer.send('prefademusic', "");
            $("#box").fadeOut(500);
            setTimeout(() => {
                info("MenuWindow", "Switching control to GameWindow");
                location.href = "game.html";
            }, 1000)
            break;
        case 'settings':
            keysEnabled = false;
            $("#box").fadeOut(500);
            setTimeout(() => {
                info("MenuWindow", "Switching control to OptnWindow");
                location.href = "settings.html";
            }, 1000)
            break;
        case 'stats':
            keysEnabled = false;
            require('electron').ipcRenderer.send('prefademusic', "");
            $("#box").fadeOut(500);
            setTimeout(() => {
                info("MenuWindow", "Switching control to OptnWindow");
                location.href = "stats.html";
            }, 1000)
            break;
        case 'credits':
            keysEnabled = false;
            require('electron').ipcRenderer.send('prefademusic', "");
            $("#box").fadeOut(500);
            setTimeout(() => {
                info("MenuWindow", "Switching control to OptnWindow");
                location.href = "credits.html";
            }, 1000)
            break;
        case 'quit':
            keysEnabled = false;
            require('electron').ipcRenderer.send('prefademusic', "");
            info("MenuWindow", "Quitting game");
            Sound.click();
            setTimeout(() => {
                require('@electron/remote').getCurrentWindow().close();
            }, 250)
            break;
    }
}