~melchizedek6809/WolkenWelten

ref: 19a5ae3cc7ddc83c7cd41598efcaf8af9dfff1f7 WolkenWelten/client/src/menu/mainmenu.c -rw-r--r-- 3.3 KiB
19a5ae3cBen (X13/Arch) Increased melee range for chars/animals 7 months ago
                                                                                
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
/*
 * Wolkenwelten - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mainmenu.h"

#include "../main.h"
#include "../gui/gui.h"
#include "../gui/menu.h"
#include "../gui/textInput.h"
#include "../gui/widget.h"
#include "../menu/singleplayer.h"
#include "../menu/multiplayer.h"
#include "../menu/options.h"
#include "../misc/options.h"
#include "../../../common/src/cto.h"
#include "../../../common/src/misc/misc.h"

#include <stdio.h>
#include <string.h>

widget *mainMenu;

widget *buttonSP;
widget *buttonQuit;
widget *buttonReturnToGame;
widget *buttonExitToMenu;

static void focusMainMenu(){
	widgetFocus(gameRunning ? buttonReturnToGame : buttonSP);
}

static void handlerSingleplayer(widget *wid){
	(void)wid;
	openSingleplayerMenu();
}
static void handlerMultiplayer(widget *wid){
	(void)wid;
	openMultiplayerMenu();
}

static void handlerOptions(widget *wid){
	(void)wid;
	openOptionsMenu();

}
static void handlerAttribution(widget *wid){
	(void)wid;
	closeAllMenus();
	openAttributions();
}

static void handlerQuit(widget *wid){
	(void)wid;
	quit = true;
}

static void handlerReturnToGame(widget *wid){
	(void)wid;
	if(!gameRunning){return;}
	closeAllMenus();
	widgetFocus(widgetGameScreen);
}

static void handlerExitToMenu(widget *wid){
	(void)wid;
	if(!gameRunning){return;}
	menuCloseGame();
	openMainMenu();
	focusMainMenu();
}

void initMainMenu(){
	mainMenu = widgetNewCP(wPanel,rootMenu,-1,0,0,-1);
	widgetNewCP  (wSpace ,mainMenu,16,0,256,0);
	buttonSP = widgetNewCPLH(wButton,mainMenu,16,0,256,32,"Singleplayer","click",handlerSingleplayer);
	widgetNewCPLH(wButton,mainMenu,16,0,256,32,"Multiplayer","click",handlerMultiplayer);
	widgetNewCP  (wHR ,mainMenu,16,0,256,32);
	widgetNewCPLH(wButton,mainMenu,16,0,256,32,"Options","click",handlerOptions);
	widgetNewCPLH(wButton,mainMenu,16,0,256,32,"Attribution","click",handlerAttribution);
	widgetNewCP  (wHR ,mainMenu,16,0,256,32);
	buttonQuit         = widgetNewCPLH(wButton,mainMenu,16,0,256,32,"Quit","click",handlerQuit);
	buttonExitToMenu   = widgetNewCPLH(wButton,mainMenu,16,0,256,32,"Exit to Menu","click",handlerExitToMenu);
	buttonReturnToGame = widgetNewCPLH(wButton,mainMenu,16,0,256,32,"Return to Game","click",handlerReturnToGame);

	widgetLayVert(mainMenu,16);
}

void openMainMenu(){
	closeAllMenus();
	if(gameRunning){
		buttonQuit->flags         |=  WIDGET_HIDDEN;
		buttonExitToMenu->flags   &= ~WIDGET_HIDDEN;
		buttonReturnToGame->flags &= ~WIDGET_HIDDEN;
	}else{
		buttonQuit->flags         &= ~WIDGET_HIDDEN;
		buttonExitToMenu->flags   |=  WIDGET_HIDDEN;
		buttonReturnToGame->flags |=  WIDGET_HIDDEN;
	}
	widgetSlideW(mainMenu, 288);
	mainMenu->gw = 288;
	focusMainMenu();
}

void closeMainMenu(){
	widgetSlideW(mainMenu, 0);
}