shockys
July 13th, 2010, 07:06
Purpose: To add hovering for your world map icon, and giving it an actionID.
Difficulty: 1/10, if you have common sense and basic client/Java knowledge.
Assumed Knowledge: Basic client knowledge, basic Java knowledge.
Classes Modified: client.java and Sprite.java
Client Base: Only the registered members can see the link.
I do not give permission for my tutorials to be converted to non-renamed and released.
NOTE: This will only work right away for my refactored base. You can configure it for yours, but this is for mine.
Step 1: Getting the sprite to load.
Download this sprite(save it): Only the registered members can see the link. Make sure it is saved as mapiconh.png, in the Sprites folder.
Now, to make the sprite load correctly, we must edit Sprite.java, and client.java. First, lets do Sprite.java. In Sprite.java, find:
} else if (img.equalsIgnoreCase("mapicon")) {
simply replace it with:
} else if (img.equalsIgnoreCase("mapicon") || img.equalsIgnoreCase("mapiconh")) {
Now save and close Sprite.java. Open up client.java, and find:
worldMapIcon = new Sprite("mapicon");
Under it, add:
worldMapIconH = new Sprite("mapiconh");
Find:
private Sprite worldMapIcon;
Under it, add:
private Sprite worldMapIconH;
Find:
worldMapIcon = null;
Under it, add:
worldMapIconH = null;
That will load the sprite. But you aren't finished.
Step 2: Getting the mouse-over to work.
Find "public int logIconHPos = 0;", and below that add:
public int worldMapHPos = 0;
Then find "public void processMapAreaClick() {", and replace that method with:
public void processMapAreaClick() {
if(super.mouseX >= 742 && super.mouseX <= 764 && super.mouseY >= 1 && super.mouseY <= 23) {
logIconHPos = 1;
} else {
logIconHPos = 0;
}
if(super.mouseX >= 527 && super.mouseX <= 560 && super.mouseY >= 126 && super.mouseY <= 159) {
worldMapHPos = 1;
} else {
worldMapHPos = 0;
}
}
Now find "public void drawWorldMapButton() {", and replace that whole method with:
public void drawWorldMapButton() {
if(worldMapHPos == 0) {
worldMapIcon.drawSprite(8, 124);
} else if(worldMapHPos == 1) {
worldMapIconH.drawSprite(8, 124);
}
}
This will make it so if you mouse over the world map icon, it draws the hover sprite.
Step 3: Making it a button with an action.
Find "public void rightClickMapArea() {", and replace the entire method with:
private void rightClickMapArea() {
if(super.mouseX >= 742 && super.mouseX <= 764 && super.mouseY >= 1 && super.mouseY <= 23 && tabInterfaceIDs[10] != -1) {
menuActionName[1] = "Logout";
menuActionID[1] = 1004;
menuActionRow = 2;
} else if(super.mouseX >= 527 && super.mouseX <= 560 && super.mouseY >= 126 && super.mouseY <= 159) {
menuActionName[1] = "World Map";
menuActionID[1] = 1005;
menuActionRow = 2;
}
}
Now find "if(l == 1004) {" and above that, add:
if(l == 1005) {
//World map action
pushMessage("The world map feature is currently disabled.", 0, "");
}
Now I don't know what you want it to do, but you can make it do anything you want by putting it in there.
__________________________
Now thats it, you're done. Save, compile, try it out. If you have any errors, feel free to ask about them.
Credits to Galkon.
Difficulty: 1/10, if you have common sense and basic client/Java knowledge.
Assumed Knowledge: Basic client knowledge, basic Java knowledge.
Classes Modified: client.java and Sprite.java
Client Base: Only the registered members can see the link.
I do not give permission for my tutorials to be converted to non-renamed and released.
NOTE: This will only work right away for my refactored base. You can configure it for yours, but this is for mine.
Step 1: Getting the sprite to load.
Download this sprite(save it): Only the registered members can see the link. Make sure it is saved as mapiconh.png, in the Sprites folder.
Now, to make the sprite load correctly, we must edit Sprite.java, and client.java. First, lets do Sprite.java. In Sprite.java, find:
} else if (img.equalsIgnoreCase("mapicon")) {
simply replace it with:
} else if (img.equalsIgnoreCase("mapicon") || img.equalsIgnoreCase("mapiconh")) {
Now save and close Sprite.java. Open up client.java, and find:
worldMapIcon = new Sprite("mapicon");
Under it, add:
worldMapIconH = new Sprite("mapiconh");
Find:
private Sprite worldMapIcon;
Under it, add:
private Sprite worldMapIconH;
Find:
worldMapIcon = null;
Under it, add:
worldMapIconH = null;
That will load the sprite. But you aren't finished.
Step 2: Getting the mouse-over to work.
Find "public int logIconHPos = 0;", and below that add:
public int worldMapHPos = 0;
Then find "public void processMapAreaClick() {", and replace that method with:
public void processMapAreaClick() {
if(super.mouseX >= 742 && super.mouseX <= 764 && super.mouseY >= 1 && super.mouseY <= 23) {
logIconHPos = 1;
} else {
logIconHPos = 0;
}
if(super.mouseX >= 527 && super.mouseX <= 560 && super.mouseY >= 126 && super.mouseY <= 159) {
worldMapHPos = 1;
} else {
worldMapHPos = 0;
}
}
Now find "public void drawWorldMapButton() {", and replace that whole method with:
public void drawWorldMapButton() {
if(worldMapHPos == 0) {
worldMapIcon.drawSprite(8, 124);
} else if(worldMapHPos == 1) {
worldMapIconH.drawSprite(8, 124);
}
}
This will make it so if you mouse over the world map icon, it draws the hover sprite.
Step 3: Making it a button with an action.
Find "public void rightClickMapArea() {", and replace the entire method with:
private void rightClickMapArea() {
if(super.mouseX >= 742 && super.mouseX <= 764 && super.mouseY >= 1 && super.mouseY <= 23 && tabInterfaceIDs[10] != -1) {
menuActionName[1] = "Logout";
menuActionID[1] = 1004;
menuActionRow = 2;
} else if(super.mouseX >= 527 && super.mouseX <= 560 && super.mouseY >= 126 && super.mouseY <= 159) {
menuActionName[1] = "World Map";
menuActionID[1] = 1005;
menuActionRow = 2;
}
}
Now find "if(l == 1004) {" and above that, add:
if(l == 1005) {
//World map action
pushMessage("The world map feature is currently disabled.", 0, "");
}
Now I don't know what you want it to do, but you can make it do anything you want by putting it in there.
__________________________
Now thats it, you're done. Save, compile, try it out. If you have any errors, feel free to ask about them.
Credits to Galkon.