summaryrefslogtreecommitdiff
path: root/source/ui_mods.c
blob: 2aced90095733050c846ba9fcdd38ca26c23d066 (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
123
124
125
126
127
128
129
130
131
132
/*
Copyright (C) 2003-2006 Andrey Nazarov

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include "ui_local.h"


/*
=======================================================================

MODS MENU

=======================================================================
*/

#define ID_LIST		102

#define MAX_LISTED_MODS		32

typedef struct modsMenu_s {
	menuFrameWork_t	menu;
	menuList_t list;
	menuStatic_t banner;
	int numMods;
	char *names[MAX_LISTED_MODS+1];
	char *directories[MAX_LISTED_MODS];
	char **modlist;
	int lastClick;
} modsMenu_t;

static modsMenu_t	m_mods;

static int ModsMenu_Callback( int id, int msg, int param ) {
	switch( msg ) {
	case QM_ACTIVATE:		
		cvar.Set( "game", m_mods.directories[m_mods.list.curvalue] );
		cmd.ExecuteText( EXEC_APPEND, "fs_restart" );
		UI_ForceMenuOff();
		return QMS_SILENT;
	case QM_DESTROY:
		if( m_mods.modlist ) {
			fs.FreeFileList( m_mods.modlist );
			m_mods.modlist = NULL;
		}
		break;
	default:
		break;
	}

	return QMS_NOTHANDLED;
}

static void ModsMenu_Init( void ) {
	int i;
	char *p;
	char *current;

	memset( &m_mods, 0, sizeof( m_mods ) );

	m_mods.names[0] = "Quake II";
	m_mods.directories[0] = "";

	current = cvar.VariableString( "game" );
	
	if( ( m_mods.modlist = fs.ListFiles( "$modlist", NULL, 0, &m_mods.numMods ) ) != NULL ) {
		if( m_mods.numMods > MAX_LISTED_MODS - 1 ) {
			m_mods.numMods = MAX_LISTED_MODS - 1;
		}
		for( i=0 ; i<m_mods.numMods ; i++ ) {
			m_mods.directories[i + 1] = m_mods.modlist[i];
			if( ( p = strchr( m_mods.modlist[i], '\n' ) ) != NULL ) {
				*p = 0; // TODO: file list should remain read-only...
				m_mods.names[i + 1] = p + 1;
			} else {
				m_mods.names[i + 1] = m_mods.modlist[i];
			}

			if( *current && !strcmp( m_mods.modlist[i], current ) ) {
				m_mods.list.curvalue = i + 1;
			}
		}

		m_mods.names[i + 1] = NULL;
	}

	m_mods.menu.callback = ModsMenu_Callback;

	m_mods.list.generic.type	= MTYPE_LIST;
	m_mods.list.generic.id		= ID_LIST;
	m_mods.list.generic.flags	= QMF_HASFOCUS;
	m_mods.list.generic.x		= ( uis.glconfig.vidWidth - 300 ) / 2;
	m_mods.list.generic.y		= 32;
	m_mods.list.generic.width	= 0;
	m_mods.list.generic.height	= uis.glconfig.vidHeight - 64;
	m_mods.list.generic.name	= NULL;
	m_mods.list.mlFlags			= MLF_HIDE_SCROLLBAR_EMPTY;
	m_mods.list.itemnames		= ( const char ** )m_mods.names;
	m_mods.list.numcolumns		= 1;
	m_mods.list.columns[0].width	= 300;
	m_mods.list.columns[0].name	= NULL;
	m_mods.list.columns[0].uiFlags	= UI_CENTER;

	UI_SetupDefaultBanner( &m_mods.banner, "Mods" );

	m_mods.menu.statusbar = "Press Enter to load";

	Menu_AddItem( &m_mods.menu, (void *)&m_mods.list );
	Menu_AddItem( &m_mods.menu, (void *)&m_mods.banner );

}


void M_Menu_Mods_f( void ) {
	ModsMenu_Init();
	UI_PushMenu( &m_mods.menu );
}