Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-16-2013, 10:28 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
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)

Graal Script 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

Last edited by khortez; 06-17-2013 at 05:27 AM..
Reply With Quote
  #2  
Old 06-16-2013, 02:57 PM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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.

Graal Script 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:

Graal Script 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
__________________
Reply With Quote
  #3  
Old 06-16-2013, 06:00 PM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
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.

Last edited by khortez; 06-16-2013 at 10:39 PM..
Reply With Quote
  #4  
Old 06-16-2013, 06:07 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by Chompy View Post
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
Reply With Quote
  #5  
Old 06-16-2013, 08:58 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Chompy View Post
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).
__________________
Reply With Quote
  #6  
Old 06-16-2013, 11:20 PM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Graal Script 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.
Reply With Quote
  #7  
Old 06-16-2013, 11:32 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #8  
Old 06-17-2013, 12:02 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
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:


Graal Script 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
Reply With Quote
  #9  
Old 06-17-2013, 12:19 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Looks like you're missing a curly bracket to me at the end of your code.
Reply With Quote
  #10  
Old 06-17-2013, 12:41 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
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.
Reply With Quote
  #11  
Old 06-17-2013, 12:48 AM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
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).
__________________
Reply With Quote
  #12  
Old 06-17-2013, 01:28 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Quote:
Originally Posted by Tim_Rocks View Post
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
Attached Thumbnails
Click image for larger version

Name:	MyGuiButton.png
Views:	113
Size:	157.3 KB
ID:	55432  

Last edited by khortez; 06-17-2013 at 05:18 AM..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 +2. The time now is 10:02 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.