Raised This Month: $40 Target: $400
 10% 

[Clientprefs] Easy way to add submenu to the cookie settings menu.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bijleveldje
Junior Member
Join Date: Aug 2016
Old 08-10-2018 , 19:08   [Clientprefs] Easy way to add submenu to the cookie settings menu.
Reply With Quote #1

This is a variant for the SetCookiePrefabMenu function, because i hate the way that function works.
The difference with this function is that the callback is called after the cookie value has changed, and the SetCookiePrefabMenu is called when only the submenu is selected.

PHP Code:
#if defined _cookiemenu_included_
  #endinput
#endif
#define _cookiemenu_included_

/**
 * Defines a cookiemenu callback. 
 *
 * @param client            Client that changed his cookie value
 * @param selection            Bool of the client value
 * @noreturn
 */
typedef CookiemenuCallback = function void(int clientbool selection);

/**
 * Registers a cookie menu item, with a callback that is fired after the cookie value is changes
 *
 * @param cookie    Cookie handle
 * @param type        Cookiemenu type
 * @param display     String to display in the menu
 * @param callback     CookiemenuCallback, callback function
 * @noreturn
 */
public void SetCookieMenu(Handle cookieCookieMenu type, const char[] displayCookiemenuCallback callback) {
    
DataPack pack = new DataPack();
    
pack.WriteCell(view_as<int>(cookie));
    
pack.WriteFunction(callback);

    switch(
type) {
        case 
CookieMenu_YesNoCookieMenu_YesNo_Int: {
            
SetCookieMenuItem(CookieHandler_YesNopackdisplay);
        }

        case 
CookieMenu_OnOffCookieMenu_OnOff_Int: {
            
SetCookieMenuItem(CookieHandler_OnOffpackdisplay);
        }
    }
}

static 
void CookieHandler_YesNo(int clientCookieMenuAction actionany infochar[] bufferint maxlen) {
    
Menu menu = new Menu(MenuHandler_CookieMenu);

    
DataPack pack view_as<DataPack>(info);
    
pack.Reset(false);

    
char sPack[64];
    
IntToString(view_as<int>(pack), sPacksizeof(sPack));

    
menu.AddItem(sPack"Yes");
    
menu.AddItem(sPack"No");
    
menu.ExitButton true;

    
menu.Display(client10);
}

static 
void CookieHandler_OnOff(int clientCookieMenuAction actionany infochar[] bufferint maxlen) {
    
Menu menu = new Menu(MenuHandler_CookieMenu);

    
char sPack[64];
    
IntToString(view_as<int>(info), sPacksizeof(sPack));

    
menu.AddItem(sPack"On");
    
menu.AddItem(sPack"Off");
    
menu.ExitButton true;

    
menu.Display(client10);
}

static 
int MenuHandler_CookieMenu(Menu menuMenuAction actionint param1int param2) {
    if(
action == MenuAction_Select) {
        
char info[64];
        
menu.GetItem(param2infosizeof(info));

        
DataPack pack view_as<DataPack>(StringToInt(info));

        
pack.Reset(false);

        
Handle cookie view_as<Handle>(pack.ReadCell());

        switch (
param2) {
            
//Yes/On
            
case 0: {
                
SetClientCookie(param1cookie"1");
            }
            
//No/Off
            
case 1: {
                
SetClientCookie(param1cookie"0");
            }
        }

        
Call_StartFunction(nullpack.ReadFunction());

        
Call_PushCell(param1);
        
Call_PushCell(view_as<bool>(!param2));

        
int result;
        
Call_Finish(result);
    }

    if(
action == MenuAction_End) {
        
delete menu;
    }

If you have any suggestions to make this better, please post them below.
Bijleveldje is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:56.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode