View Single Post
  #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