Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-21-2010, 11:19 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Draw bitmap numbers

Made these simple functions to display numbers as images instead of text. Details such as these can make a lot of difference in presentation

PHP Code:
function DrawNumber(ind,num,ix,iy,center) {
  if (
this.("oldindex_" ind) > num.length()) hideimgs(ind,ind this.("oldindex_" ind));

  
temp.charmap "0123456789/:";
  
temp.numimg  "state.png";
  
temp.numx    0;
  
temp.numy    81;
  
temp.numw    14
  
temp.numh    16;
  
temp.offset  3;
  
temp.coffset center * ((num.length()*(numw-offset))/2);

  for (
temp.i=0;i<num.length();i++) {
    
with (findimg(ind+i)) {
      
image num.substring(i,1) == " " "" numimg;
      
x     ix coffset + (numw offset)*i;
      
y     iy;
      
partx numx charmap.pos(num.substring(i,1))*numw;
      
party numy;
      
partw numw;
      
parth numh;
      
layer 4;
    }
  }
  
this.("oldindex_" ind) = num.length();
}

function 
DrawCustomNumbers(ind,num,ix,iy,img,chars,numx,numy,numw,numh,offx,center) {
  if (
this.("oldindex_" ind) > num.length()) hideimgs(ind,ind this.("oldindex_" ind));

  
temp.coffset center * ((num.length()*(numw-offx))/2);
  if (
temp.numw == nulltemp.numw 16;
  if (
temp.numh == nulltemp.numh 16;

  for (
temp.i=0;i<num.length();i++) {
    
with (findimg(ind+i)) {
      
image num.substring(i,1) == " " "" img;
      
x     ix coffset + (numw offx)*i;
      
y     iy;
      
partx numx chars.pos(num.substring(i,1))*numw;
      
party numy;
      
partw numw;
      
parth numh;
      
layer 4;
    }
  }
  
this.("oldindex_" ind) = num.length();

There are two functions. One is simple, one is not-so-simple.

DrawNumber: This is the simple function. What it does is display numbers using state.png. Thus, it is limited to the characters defined in that, "0123456789/:" and spaces. If you'd like, you could simply take this function and customize the variables defined in it. Parameters are:

DrawNumber(index,text,x,y[,center?]);

Index is the starting index to display the images. text is what you wish to display. I recommend sending it as a string to assure gscript doesn't mess up the values. And the last parameter is whether you want the text centered on the x-position or not. You can omit this if you'd like, and it just won't center it. An example of using it:

DrawNumber(200,"0123 456",20,150);
DrawNumber(200,player.mp,20,150,true);
DrawNumber(200,03242,20,150);




DrawCustomNumbers: This is the complicated version. This lets you define all the parameters so that you can use a customized image instead of state.png. The parameters are:

DrawNumber(index,text,x,y,charactermap,partx,party ,partw,parth,spacing[,center?]);

The character map is the layout of all the characters as they are in the image. This must be a string. For example, the character map for state.png is "0123456789/:". Partx/y/h/w should be fairly self-explanatory. These will define the startx/y of the number map in an image(typically 0,0 but may be different if in a gui template). Partw/h define the width and height of the characters. As precautionary, these will default to 16,16 if they are not defined. Lastly is the spacing. This will offset the space between the images when they are drawn. Example of usage:

DrawCustomNumbers(200,draw,20,150,"dusty_defaultnu mbers.png","0123456789/:.",0,0,14,16,3,true);


Oh yes, and both functions already account for spaces. You do not need to account for them in your character maps.

edit: obligatory screenshot attached. Also, I may eventually add the ability to perhaps center the text...
Attached Thumbnails
Click image for larger version

Name:	graal_1271889429.png
Views:	317
Size:	171.8 KB
ID:	50944  

Last edited by DustyPorViva; 04-22-2010 at 01:40 AM..
Reply With Quote
  #2  
Old 04-21-2010, 11:57 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
I like that, any chance of get functions for the width and height? I imagine those will come if you make the center function though.
__________________
Quote:
Reply With Quote
  #3  
Old 04-22-2010, 12:19 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by fowlplay4 View Post
I like that, any chance of get functions for the width and height? I imagine those will come if you make the center function though.
What do you mean get functions? Performing the centering and such is actually fairly simple. x - ((text.length()*(partw-offset))/2). I was just thinking of how I could easily add the ability to define such an option as the complex function is already quiet long with parameters.
Reply With Quote
  #4  
Old 04-22-2010, 01:09 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
I meant.. getStateTextWidth(text) + getStateTextHeight(text)
__________________
Quote:
Reply With Quote
  #5  
Old 04-22-2010, 01:11 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by fowlplay4 View Post
I meant.. getStateTextWidth(text) + getStateTextHeight(text)
Hmmmm... I could possibly allow something like:
text = "012345";
DrawNumber(index,text,x + DrawCenter(text),y);
Reply With Quote
  #6  
Old 04-22-2010, 01:41 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Okay, I've updated it and just added a parameter for centering. Also fixed a major bug where it wasn't hiding left-over images after being updated.
Reply With Quote
  #7  
Old 04-22-2010, 05:42 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Not bad, not bad at all.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
Reply


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 11:27 PM.


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