Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   making a custom GUI button - help (https://forums.graalonline.com/forums/showthread.php?t=134268328)

khortez 06-16-2013 09:28 AM

making a custom GUI button - help
 
i need some help in making a custom button. so far the only way i have figured to work is using GuiBitmapButtonCtrl. if there is another way please tell me (like a different function or anything really). if not then does the image need to be a certain size or something? like if it needs to be 32x32. is it also possible to resize it? like i would using parth partx etc for other GUI images.

here is my current attempt. (it's halved)

PHP Code:

     new GuiBitmapButtonCtrl("Button_Test") {
          
extent = {
            
100100
          
};
          
position = {
            
1010
          
};
          
normalbitmap "c_inventorytest6-13-2013.png";
          
mouseoverbitmap "c_inventorytest6-13-2013.png";
          
pressedbitmap "c_inventorytest6-13-2013.png";
          
text "Press me!";
        } 

i'm just not sure if there is more that i can do and i just haven't found it yet..or if that's just about it. thanks for any help

Chompy 06-16-2013 01:57 PM

Firstly, I'm not sure why you have the 4 ending brackets at the end of your script, when you only have one opening bracket.

And here's a tip, when you're scripting, make sure your starting brackets and the ending brackets line up. Makes it much easier to debug your code.

PHP Code:

function onCreated() {
| if (
== 2) {
| | if (
== 1) {
| | | 
// do something here
| | }
| }


You see how they line up? Make sure you do that :)


To further answer you question, I suggest you remove extent and position. Also, even though you define them as arrays you can't access them as arrays, so you should do extent = "123 321"; instead. (What I mean by that you can't access them as arrays, is that there is currently no support for reading the first value of for example extent, by using extent[0] - atleast this is what the wiki states)


Instead of extent and position I suggest you use resize(x, y, width, height);
This will place your guicontrol at x and y (relative to the parent gui control if it's a child. If this is the parent gui control, use screen coordinates) and resize the width and height to the values specified respectively.


And the use of partx, party, partw, parth is for clipping the image, using only a section of the image:

GuiControls don't really use partx, party etc etc besides GuiShowImgCtrl and GuiDrawingPanel, I suggest you use this instead:

PHP Code:

new GuiBitmapCtrl("Button_Test") {
  
resize(temp.sxtemp.sy1121);
  
alpha 2;
  
bitmap "image.png";
  
bitmaprectangle  = {0,0,32,32};


You see the use of bitmaprectangle? It starts to cut out a section of the provided image, allowing you to use a specified area of your bitmap.

The array values are as follows:
NPC Code:

bitmaprectangle = {startx, starty, width from startx, height from starty};



--

If you have any more questions or wondering about something else, just ask :)

khortez 06-16-2013 05:00 PM

thanks for the help, really appreciated. you know i saw resize but i guess i just took it for granted. it's nice compacting the script like that.

but at any rate, i'm still having an issue with the button. the image shows up, but it shows up odd. like all the colors and graphics are squished into each other. Even when i resize it and make the window bigger to look at it as a whole; it looks odd. how do i fix that?

also i was playing with bitmaprectangle, and i could be using it wrong, but it didn't even so much as budge the button. at least from what it seemed. so far the only thing that works the way i want it to on the button. is when i press it. when i do that it works fine but i need a bit more then that though. thanks again for the help i may need some more unfortunately.

basically just trying to resize the button and make it look like the way it should is my key issue.

Twinny 06-16-2013 05:07 PM

Quote:

Originally Posted by Chompy (Post 1719310)
Also, even though you define them as arrays you can't access them as arrays, so you should do extent = "123 321"; instead. (What I mean by that you can't access them as arrays, is that there is currently no support for reading the first value of for example extent, by using extent[0] - atleast this is what the wiki states)

I used to do this purely to piss Skyld off :)

cbk1994 06-16-2013 07:58 PM

Quote:

Originally Posted by Chompy (Post 1719310)
Instead of extent and position I suggest you use resize(x, y, width, height);

Or even better, just use width/height/x/y :). Otherwise you run in to additional trouble (e.g. how do you center a window using resize? you must store the width/height in a different variable first anyway).

khortez 06-16-2013 10:20 PM

PHP Code:

function onPlayerChats(){
           if(
player.chat == ":gui"){
           
this.on = !this.on;
           
         if(
this.on){
         new 
GuiBitmapButtonCtrl("Button_Test"){
         
Button_Test.visible true;
         
resize(20020600800);
        
        
        
normalbitmap "c_inventorytest6-13-2013.png";
        
mouseoverbitmap "c_inventorytest6-13-2013.png";
        
pressedbitmap "c_inventorytest6-13-2013.png";
        
bitmaprectangle  = {100,100,90,92}; //hasn't clipped the image at all - 
        
text "Press me!";                //for me. am i doing something -
                                           //wrong? 
        
}
       }else{
         
player.chat "Button off!";
         
Button_Test.visible false;
         
Button_Test.destroy();
       }
      }    
     } 

this is what i have right now; i tried using the whole inventory image, thinking i could resize it and just use a portion of it as a button. except i still have yet been able to resize it. the image seems to either stretch the colors, or squish them together o.o. i'll keep trying but i'm not really sure how to fix that. any ideas? thanks for all the help and tips everyone.

cbk1994 06-16-2013 10:32 PM

khortez, please style your code before posting it. It's difficult for us to read your code if it's not styled properly. You should be indenting your code as you write it, but if you find that impossible, use Jer's GS2 Beautifier before you post. This is the third time in the past 3 days you've posted poorly-formatted code. It just makes it harder for us to help you (look at Chompy's first post above to see why).

Thanks.

khortez 06-16-2013 11:02 PM

Quote:

Originally Posted by cbk1994 (Post 1719325)
khortez, please style your code before posting it. It's difficult for us to read your code if it's not styled properly. You should be indenting your code as you write it, but if you find that impossible, use Jer's GS2 Beautifier before you post. This is the third time in the past 3 days you've posted poorly-formatted code. It just makes it harder for us to help you (look at Chompy's first post above to see why).

Thanks.

i understand; im not sure what to tell you. ive tried doing what chompy said. furthermore i used fp4s site. twice to maybe 3 times. aside from the comments that i added in the code.. what you see is what the beautifier came out as. i'm not trying to make it harder. in fact i'm trying to make it as easy as possible so i can move onto the next thing.


i'll try it again however:


PHP Code:

function onPlayerChats() {
  if (
player.chat == ":gui") {
    
this.on = !this.on;

    if (
this.on) {
      new 
GuiBitmapButtonCtrl("Button_Test") {
        
Button_Test.visible true;
        
resize(20020600800);


        
normalbitmap "c_inventorytest6-13-2013.png";
        
mouseoverbitmap "c_inventorytest6-13-2013.png";
        
pressedbitmap "c_inventorytest6-13-2013.png";
        
bitmaprectangle = {
          
1001009092
        
}; //hasn't clipped the image at all -  
        
text "Press me!"//for me. am i doing something - 
        //wrong?  
      
}
    } else {
      
player.chat "Button off!";
      
Button_Test.visible false;
      
Button_Test.destroy();
    }
  } 

this is what the beautifier did with the comments added

Emera 06-16-2013 11:19 PM

Looks like you're missing a curly bracket to me at the end of your code.

khortez 06-16-2013 11:41 PM

i apologize if it's hard to read everyone, i'll continue trying to make it easier for you all. still thanks for the help. as for the brackets; idk the code works fine for me/RC hasn't complained to me about anything. just i still can't get the image to look exactly the way i want it.

Tim_Rocks 06-16-2013 11:48 PM

I'd recommend creating the button in a GuiWindowCtrl within onCreated. There's no need to destroy the button every time; just hide it (obj.visible = false).

khortez 06-17-2013 12:28 AM

1 Attachment(s)
Quote:

Originally Posted by Tim_Rocks (Post 1719330)
I'd recommend creating the button in a GuiWindowCtrl within onCreated. There's no need to destroy the button every time; just hide it (obj.visible = false).

aiight; though i didn't give it a parent cuz i just wanted to see if i could get the button to show the way i been trying to set it.

alright i'ma remake the code and try to give you guys a picture example of what i'm trying to fix.

the picture i provided is exactly what it looks like. of course i use a different image in the script but thats overall what it looks like; it gets the entire thing and puts it on the map like that and it looks nothing like a button. i can press it like a button and it'll do stuff. but it doesn't look the part at all. and i dunno how to resize it. i used different methods, even some said here but it didn't do anything. i'll try the ones mentioned here again though. now that i remade the code hopefully ill get a better look at it and see if i shoulda done something different. other then that any way of fixing that via script?


edit: ahh i think i mighta found a way actually. ill try this then. still any helpful comments/input etc is appreciated. thanks all

editx2: Nope. nevermind what i did, i thought would work but it did not. back to square one. any help please? lol

also emera you was right, in that last script i was missing a bracket. noticed it when i tried reusing the code in a different weapon. not sure how it got deleted though. it was there before. anyway thanks


All times are GMT +2. The time now is 05:39 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.