All pastes #984589 Raw Edit

YSI_menu.own

public cpp v1 · immutable
·published 2008-04-14 12:34 UTC
rendered paste body
/*----------------------------------------------------------------------------*-					============================					Y Sever Includes - Menu Core					============================Description:	Allows you to define menus with as many rows as you like and handles the	pages internally, allowing you to simply process the rows selected as if it	was one huge long menu.Legal:	Copyright (C) 2007 Alex "Y_Less" Cole	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., 51 Franklin Street, Fifth Floor, Boston,	MA 02110-1301, USA.Version:	0.0.1Changelog:	23/11/07:		First version.Functions:	Public:		-	Core:		-	Stock:		-	Static:		-	Inline:		-	API:		-Callbacks:	-Definitions:	-Enums:	-Macros:	-Tags:	-Variables:	Global:		-	Static:		-Commands:	-Compile options:	--*----------------------------------------------------------------------------*/#if !defined MAX_MENU_LINE	#define MAX_MENU_LINE (32)#endif#define NO_MENU     (-1)#define NO_MENU_ROW (-1)enum e_MENU_FLAGS (<<= 1){	e_MENU_FLAGS_NONE,	e_MENU_FLAGS_TWO = 1,	e_MENU_FLAGS_ACTIVE}enum E_MENU_DATA{	E_MENU_DATA_TITLE[MAX_MENU_LINE],	E_MENU_DATA_FIRST,	e_MENU_FLAGS:E_MENU_DATA_DATA,	Float:E_MENU_DATA_X,	Float:E_MENU_DATA_Y,	Float:E_MENU_DATA_C1,	Float:E_MENU_DATA_C2}enum E_MENU_ROW{	E_MENU_ROW_NEXT,	e_MENU_FLAGS:E_MENU_ROW_DATA,	E_MENU_ROW_COL1[MAX_MENU_LINE],	E_MENU_ROW_COL1[MAX_MENU_LINE],}enum E_PLAYER_MENU{	Menu:E_PLAYER_MENU_REAL,	E_PLAYER_MENU_MENU,	E_PLAYER_MENU_PAGE}static	YSI_g_sMenuData[MAX_DYN_MENUS][E_MENU_DATA],	YSI_g_sMenuItems[MAX_MENU_ROWS][E_MENU_ROW],	YSI_g_sPlayerMenus[MAX_PLAYERS][E_PLAYER_MENU],	YSI_g_sUnusedRows;#define Menu_IsValid(%1) \	((%1) >= 0 && (%1) < MAX_DYN_MENUS && YSI_g_sMenuData[(%1)][E_MENU_ROW_DATA] & e_MENU_FLAGS_ACTIVE)Menu_Menu(){	YSI_g_sUnusedRows = 0	for (new i = 0; i < MAX_MENU_ROWS - 1; i++)	{		YSI_g_sMenuItems[i][E_MENU_ROW_NEXT] = i + 1;	}	YSI_g_sMenuItems[MAX_MENU_ROWS - 1][E_MENU_ROW_NEXT] = NO_MENU_ROW;}stock Menu_Create(title[], rows, Float:x, Float:y, Float:row1wirdth, Float:row2width = 0.0){	new		i;	for (i = 0; i < MAX_DYN_MENUS; i++)	{		if (!(YSI_g_sMenuData[i][E_MENU_DATA_DATA] & e_MENU_FLAGS_ACTIVE)) break;	}	if (i == MAX_DYN_MENUS) return NO_MENU;	YSI_g_sMenuData[i][E_MENU_DATA_DATA] = e_MENU_FLAGS_ACTIVE | ((rows == 2) ? e_MENU_FLAGS_TWO : e_MENU_FLAGS_NONE);	YSI_g_sMenuData[i][E_MENU_DATA_FIRST] = NO_MENU_ROW;	YSI_g_sMenuData[i][E_MENU_DATA_X] = x;	YSI_g_sMenuData[i][E_MENU_DATA_Y] = y;	YSI_g_sMenuData[i][E_MENU_DATA_C1] = row1width;	YSI_g_sMenuData[i][E_MENU_DATA_C2] = row2width;	strcpy(YSI_g_sMenuData[i][E_MENU_DATA_TITLE], title, MAX_MENU_LINE);	return i;}stock Menu_AddRow(menuid, col1[], col2[] = ""){	if (!Menu_IsValid(menuid)) return NO_MENU_ROW;	if (YSI_g_sUnusedRows == NO_MENU_ROW) return NO_MENU_ROW;	new		row = YSI_g_sUnusedRows;	YSI_g_sUnusedRows = YSI_g_sMenuItems[row][E_MENU_ROW_NEXT];	strcpy(YSI_g_sMenuItems[row][E_MENU_ROW_COL1], col1, MAX_MENU_LINE);	strcpy(YSI_g_sMenuItems[row][E_MENU_ROW_COL2], col2, MAX_MENU_LINE);	YSI_g_sMenuItems[row][E_MENU_ROW_DATA] = e_MENU_FLAGS_ACTIVE | ((col2[0]) ? e_MENU_FLAGS_TWO : e_MENU_FLAGS_NONE);		new		last = NO_MENU_ROW,		cur = YSI_g_sMenuData[menu][E_MENU_DATA_FIRST];	while (cur != NO_MENU_ROW)	{		last = cur;		cur = YSI_g_sMenuItems[last][E_MENU_ROW_NEXT];	}	if (last == NO_MENU_ROW)	{		YSI_g_sMenuData[menu][E_MENU_DATA_FIRST] = row;	}	else	{		YSI_g_sMenuItems[last][E_MENU_ROW_NEXT] = row;	}	YSI_g_sMenuItems[cur][E_MENU_ROW_NEXT] = NO_MENU_ROW;	return row;}stock Menu_ShowForPlayer(playerid, menuid){	if (!Menu_IsValid(menuid)) return 0;	YSI_g_sPlayerMenus[MAX_PLAYERS][E_PLAYER_MENU_REAL];		// TO-DO:	// Show the menu and determine pages	return 1;}Menu_OnPlayerSelectMenuRow(playerid, row){	// TO-DO	// Determine if they selected a real row or back/next from the system	// If back/next alter page	// If real row call OnPlayerSelectMenuRowEx with the row}