I need to understand clickable textdraws
#1

Hey guys. I need your help.
So I have the following picture:



3 textdraws and the code for them is this:
PHP код:
new PlayerText:Textdraw0[MAX_PLAYERS];
new 
PlayerText:Textdraw1[MAX_PLAYERS];
new 
PlayerText:Textdraw2[MAX_PLAYERS];
Textdraw0[playerid] = CreatePlayerTextDraw(playerid35.666641137.303726"New Textdraw");
PlayerTextDrawLetterSize(playeridTextdraw0[playerid], 0.4499991.600000);
PlayerTextDrawAlignment(playeridTextdraw0[playerid], 1);
PlayerTextDrawColor(playeridTextdraw0[playerid], -1);
PlayerTextDrawSetShadow(playeridTextdraw0[playerid], 0);
PlayerTextDrawSetOutline(playeridTextdraw0[playerid], 1);
PlayerTextDrawBackgroundColor(playeridTextdraw0[playerid], 51);
PlayerTextDrawFont(playeridTextdraw0[playerid], 1);
PlayerTextDrawSetProportional(playeridTextdraw0[playerid], 1);
PlayerTextDrawSetSelectable(playeridTextdraw0[playerid], true);
Textdraw1[playerid] = CreatePlayerTextDraw(playerid35.666645150.333389"New Textdraw");
PlayerTextDrawLetterSize(playeridTextdraw1[playerid], 0.4499991.600000);
PlayerTextDrawAlignment(playeridTextdraw1[playerid], 1);
PlayerTextDrawColor(playeridTextdraw1[playerid], -1);
PlayerTextDrawSetShadow(playeridTextdraw1[playerid], 0);
PlayerTextDrawSetOutline(playeridTextdraw1[playerid], 1);
PlayerTextDrawBackgroundColor(playeridTextdraw1[playerid], 51);
PlayerTextDrawFont(playeridTextdraw1[playerid], 1);
PlayerTextDrawSetProportional(playeridTextdraw1[playerid], 1);
PlayerTextDrawSetSelectable(playeridTextdraw1[playerid], true);
Textdraw2[playerid] = CreatePlayerTextDraw(playerid35.666645162.533340"New Textdraw");
PlayerTextDrawLetterSize(playeridTextdraw2[playerid], 0.4499991.600000);
PlayerTextDrawAlignment(playeridTextdraw2[playerid], 1);
PlayerTextDrawColor(playeridTextdraw2[playerid], -1);
PlayerTextDrawSetShadow(playeridTextdraw2[playerid], 0);
PlayerTextDrawSetOutline(playeridTextdraw2[playerid], 1);
PlayerTextDrawBackgroundColor(playeridTextdraw2[playerid], 51);
PlayerTextDrawFont(playeridTextdraw2[playerid], 1);
PlayerTextDrawSetProportional(playeridTextdraw2[playerid], 1);
PlayerTextDrawSetSelectable(playeridTextdraw2[playerid], true); 
I want to make a fully functional menu, but I'm having trouble understanding how the selection works. I saw that some scripts have menuse that are controllable via both keyboard and mouse. That's exactly my goal here. To create a menu that will look almost like the old GTASA menus, but it should have mouse control ability. What I need from you guys is to explain to me how the selection works and use this as an example. I did research on wiki but it didn't help much. I will everyone who helps me.
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=328267
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
I know how to put the effect on clicking. My problem is with the selection. Moving the selection with the keyboard and triggering it with a designated button.
In the old menus you had the movement buttons for scrolling through lines, space for selecting, F or enter for going back. I want to make the same thing here.
Reply
#4

https://sampwiki.blast.hk/wiki/CreateMenu - Is that what you mean?
Reply
#5

yes, I want to recreate that sort of menu, but I need to recreate it using textdraws, because they have the mouse control option.
Reply
#6

Good luck with that.. I suggest using that menu system instead of making things complicated for your self. If you do use the menu code there must a way to use the "mouse control option".
Reply
#7

You use a variable to check if a player is viewing a menu or not. Then you use another variable to store the current menu choice which will change under OnPlayerKeyStateChange when a player uses the KEY_UP or KEY_DOWN buttons. When the player key state changes, you highlight that particular row using TextdrawSetColor or you can even offset the row to give a shadow effect using the YSI plugin continued by kurta999. Make sure you check for all cases like (selection row number isn't greater than the number of rows itself..)
Reply
#8

oh that
like this --
pawn Код:
new bool:IsViewingMenu[MAX_PLAYERS];//on top
new current[MAX_PLAYERS] = -1;//specifies the current text draw on which player pointer is

IsViewingMenu[playerid] = true;//when u show menu to the player using TextDrawShowForplayer

public OnPlayerUpdate(playerid)
{

if(IsViewingMenu[playerid])
{
new Keys,ud,lr;
GetPlayerKeys(playerid,Keys,ud,lr);//for getting player keys up and down you can read about this in wiki
if(ud == KEY_DOWN && cuurent[playerid] != 4)//to do nothing when the pointer is at last text draw,i.e., 4
{

current[playerid]++;
switch(current[playerid])
{
case 0 : PlayerTextDrawColor(playerid, Textdraw0[playerid], 0xFF0000FF); //setting current text draw color to red
case 1 :
{
PlayerTextDrawColor(playerid, Textdraw0[playerid], -1);//setting old text draw color to back to white
PlayerTextDrawColor(playerid, Textdraw1[playerid], 0xFF0000FF);
}
case 2 :
{
PlayerTextDrawColor(playerid, Textdraw1[playerid], -1);//setting old text draw color to back to white
PlayerTextDrawColor(playerid, Textdraw2[playerid], 0xFF0000FF);
}
//like this for others too

}//end of switch

else if(ud == KEY_UP && (cuurent[playerid] != -1 || current[playerid] != 0))//to do nothing when pointer is nowhere or at first textdraw ,i.e, 0
{
current[playerid]--;
switch(current[playerid])
{
case 0 :
{
PlayerTextDrawColor(playerid, Textdraw0[playerid], 0xFF0000FF);//setting current pointer color to red
PlayerTextDrawColor(playerid, Textdraw1[playerid], -1);//setting textdraw color where pointer "was" back to white
}
case 1 :
{
PlayerTextDrawColor(playerid, Textdraw1[playerid], 0xFF0000FF);//setting current pointer color to red
PlayerTextDrawColor(playerid, Textdraw2[playerid], -1);//setting textdraw color where pointer "was" back to white
}
//like this for others
}//end of switch

}

}
return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(IsViewingMenu[playerid])
{
if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE) && current[playerid] != -1)//change to key whatever u want
{
switch(current[playerid])
{
case 0://player is on menu item 1 do something
case 1://player is on menu item 2
}
}
}
return 1;
}

//this all when u hide menu or player disconnects
current[playerid] = -1;
IsViewingMenu[playerid] = false;
Reply
#9

Quote:
Originally Posted by Death1300
Посмотреть сообщение
Good luck with that.. I suggest using that menu system instead of making things complicated for your self. If you do use the menu code there must a way to use the "mouse control option".
The old menu doesn't offer mouse control. Even if it did, I'd still take the text draw style, because it offers great flexibility with text fonts, shapes, colors, etc.
My attention is now towards BroZeus's code. I've tried to add it on my FS and filled in the gaps, but for some reason I get errors.
Here's what I've got (I have bolded the lines with problems):
Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT
#include <a_samp>

new PlayerText:Textdraw0[MAX_PLAYERS];
new PlayerText:Textdraw1[MAX_PLAYERS];
new PlayerText:Textdraw2[MAX_PLAYERS];

new bool:IsViewingMenu[MAX_PLAYERS];//on top
new current[MAX_PLAYERS] = -1;//specifies the current text draw on which player pointer is

Textdraw0[playerid] = CreatePlayerTextDraw(playerid, 35.666641, 137.303726, "New Textdraw");
PlayerTextDrawLetterSize(playerid, Textdraw0[playerid], 0.449999, 1.600000);
PlayerTextDrawAlignment(playerid, Textdraw0[playerid], 1);
PlayerTextDrawColor(playerid, Textdraw0[playerid], -1);
PlayerTextDrawSetShadow(playerid, Textdraw0[playerid], 0);
PlayerTextDrawSetOutline(playerid, Textdraw0[playerid], 1);
PlayerTextDrawBackgroundColor(playerid, Textdraw0[playerid], 51);
PlayerTextDrawFont(playerid, Textdraw0[playerid], 1);
PlayerTextDrawSetProportional(playerid, Textdraw0[playerid], 1);
PlayerTextDrawSetSelectable(playerid, Textdraw0[playerid], true);

Textdraw1[playerid] = CreatePlayerTextDraw(playerid, 35.666645, 150.333389, "New Textdraw");
PlayerTextDrawLetterSize(playerid, Textdraw1[playerid], 0.449999, 1.600000);
PlayerTextDrawAlignment(playerid, Textdraw1[playerid], 1);
PlayerTextDrawColor(playerid, Textdraw1[playerid], -1);
PlayerTextDrawSetShadow(playerid, Textdraw1[playerid], 0);
PlayerTextDrawSetOutline(playerid, Textdraw1[playerid], 1);
PlayerTextDrawBackgroundColor(playerid, Textdraw1[playerid], 51);
PlayerTextDrawFont(playerid, Textdraw1[playerid], 1);
PlayerTextDrawSetProportional(playerid, Textdraw1[playerid], 1);
PlayerTextDrawSetSelectable(playerid, Textdraw1[playerid], true);

Textdraw2[playerid] = CreatePlayerTextDraw(playerid, 35.666645, 162.533340, "New Textdraw");
PlayerTextDrawLetterSize(playerid, Textdraw2[playerid], 0.449999, 1.600000);
PlayerTextDrawAlignment(playerid, Textdraw2[playerid], 1);
PlayerTextDrawColor(playerid, Textdraw2[playerid], -1);
PlayerTextDrawSetShadow(playerid, Textdraw2[playerid], 0);
PlayerTextDrawSetOutline(playerid, Textdraw2[playerid], 1);
PlayerTextDrawBackgroundColor(playerid, Textdraw2[playerid], 51);
PlayerTextDrawFont(playerid, Textdraw2[playerid], 1);
PlayerTextDrawSetProportional(playerid, Textdraw2[playerid], 1);
PlayerTextDrawSetSelectable(playerid, Textdraw2[playerid], true);

#if defined FILTERSCRIPT
#else
main()
{
	print("\n----------------------------------");
	print(" -----------------------------------");
	print("----------------------------------\n");
}
#endif


public OnPlayerUpdate(playerid)
{
	if(IsViewingMenu[playerid])
	{
		new Keys,ud,lr;
		GetPlayerKeys(playerid,Keys,ud,lr);//for getting player keys up and down you can read about this in wiki
		if(ud == KEY_DOWN && current[playerid] != 4)//to do nothing when the pointer is at last text draw,i.e., 4
		{

			current[playerid]++;
			switch(current[playerid])
			{
				case 0 : PlayerTextDrawColor(playerid, Textdraw0[playerid], 0xFF0000FF); //setting current text draw color to red
				case 1 : 
				{
					PlayerTextDrawColor(playerid, Textdraw0[playerid], -1);//setting old text draw color to back to white
					PlayerTextDrawColor(playerid, Textdraw1[playerid], 0xFF0000FF);
				}
				case 2 : 
				{
					PlayerTextDrawColor(playerid, Textdraw1[playerid], -1);//setting old text draw color to back to white
					PlayerTextDrawColor(playerid, Textdraw2[playerid], 0xFF0000FF);
				}
				case 3 : 
				{
					PlayerTextDrawColor(playerid, Textdraw2[playerid], -1);//setting old text draw color to back to white
				}
		}//end of switch
		else if(ud == KEY_UP && (current[playerid] != -1 || current[playerid] != 0))//to do nothing when pointer is nowhere or at first textdraw ,i.e, 0
		{
			current[playerid]--;
			switch(current[playerid])
			{
				case 0 : 
				{
					PlayerTextDrawColor(playerid, Textdraw0[playerid], 0xFF0000FF);//setting current pointer color to red
					PlayerTextDrawColor(playerid, Textdraw1[playerid], -1);//setting textdraw color where pointer "was" back to white
				}
				case 1 : 
				{
					PlayerTextDrawColor(playerid, Textdraw1[playerid], 0xFF0000FF);//setting current pointer color to red
					PlayerTextDrawColor(playerid, Textdraw2[playerid], -1);//setting textdraw color where pointer "was" back to white
				}
				case 3 : 
				{
					PlayerTextDrawColor(playerid, Textdraw2[playerid], 0xFF0000FF);//setting current pointer color to red
					PlayerTextDrawColor(playerid, Textdraw3[playerid], -1);//setting textdraw color where pointer "was" back to white
				}
				case 4 : 
				{
					PlayerTextDrawColor(playerid, Textdraw3[playerid], 0xFF0000FF);//setting current pointer color to red
				}
			}//end of switch

		}

	}
return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(IsViewingMenu[playerid])
	{
		if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE) && current[playerid] != -1)//change to key whatever u want
		{
			switch(current[playerid])
			{
				case 0://player is on menu item 1 do something
				case 1://player is on menu item 2

			}
		}
	}
return 1;
}

/*this all when u hide menu or player disconnects
current[playerid] = -1;
IsViewingMenu[playerid] = false;/*
and here are the errors:
Код:
TD_test.pwn(13) : error 010: invalid function or declaration
TD_test.pwn(24) : error 010: invalid function or declaration
TD_test.pwn(35) : error 010: invalid function or declaration

TD_test.pwn(85) : warning 217: loose indentation
TD_test.pwn(85) : error 029: invalid expression, assumed zero
TD_test.pwn(85) : warning 215: expression has no effect
TD_test.pwn(85) : error 001: expected token: ";", but found "if"

TD_test.pwn(103) : error 017: undefined symbol "Textdraw3"
TD_test.pwn(103) : warning 215: expression has no effect
TD_test.pwn(103) : error 001: expected token: ";", but found "]"
TD_test.pwn(103) : error 029: invalid expression, assumed zero
TD_test.pwn(103) : fatal error 107: too many error messages on one line

Compilation aborted.[Finished in 0.2s with exit code 1]
Reply
#10

guys, help me, please!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)