Hello
I would like to show Clan/Alliance crest in HTML window.
This code: <img src="Crest.crest_1_"+clan.getCrestId()+"" width=16 height=16> works well, it's showing the crest
The problem is, every crest sent from client have got 2 pixels(on the top) of white space.
It looks something like that: http://imgur.com/gRhzbt7
So i can see 2 options:
1. Do something in HTML to cut 2 pixels at the top of the image
2. Use the code that can do it and send cutten image to the client with new ID.
Any idea how to do it?
Crest
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
- Szponiasty
- Advanced User
- Posts: 557
- Joined: Mon Apr 21, 2008 1:31 pm
- Location: Eastern Poland
Re: Crest
You can use my code if you want. I haven't been able to figure out nothing better so far. Problem is that crests have unsupported dimension, client fills rest with garbage, that is transparent when showed above char. But with garbage in htmls :/ Tried converting between multiple DDS subtypes, nothing helps.
Code: Select all
/* * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */package handlers.dochandlers; import com.l2jserver.Config;import com.l2jserver.gameserver.datatables.ClanTable;import com.l2jserver.gameserver.ext.handlers.IDocParser;import com.l2jserver.gameserver.model.L2Clan;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import java.util.logging.Level; /** * ==============================================<br> * HtmStyling - DocParser sample, showing some basic HTML styling.<br> * ==============================================<br> * @author Szponiasty([email protected]) / MMOPlay.eu */public class HtmElements implements IDocParser{ private int extractClanId(String inp) { if (inp.contains("%clan_crest_")) { // fetch clan id int start = inp.indexOf("%clan_crest_"); int end = inp.indexOf("_%", start + 1); // found if (start > 0 && end > start) { String clanIdS = inp.substring(start + "%clan_crest_".length(), end); int clanId = -1; try { clanId = Integer.parseInt(clanIdS); } catch (Exception e) { _log.log(Level.WARNING, "[!!!] " + getClass().getSimpleName() + ": exception " + e.getMessage() + " - can't parse clan id string: [" + clanIdS + "]", e); inp = inp.replaceAll("("+clanIdS+")", "0"); } return clanId; } } return -1; } private String getCrestCode(int clanId) { String htm = "<table fixwidth=24 border=0 cellpadding=0 cellspacing=0>\n" + " <tr>\n" + " <td fixwidth=8>\n" + " <table fixwidth=8 border=0 cellpadding=0 cellspacing=0 background=\"$ally_crest_id\">\n" + " <tr>\n" + " <td fixwidth=8><img height=4 width=8 src=\"L2UI.SquareBlack\"><br1> </td>\n" + " </tr>\n" + " </table>\n" + " </td>\n" + " <td fixwidth=16>\n" + " <table fixwidth=16 border=0 cellpadding=0 cellspacing=0 background=\"$clan_crest_id\">\n" + " <tr>\n" + " <td fixwidth=16><img height=4 width=16 src=\"L2UI.SquareBlack\"><br1> </td>\n" + " </tr>\n" + " </table>\n" + " </td>\n" + " </tr>\n" + "</table>"; L2Clan clan = clanId > 0 ? ClanTable.getInstance().getClan(clanId) : null; if (clan != null && (clan.getCrestId() > 0 || clan.getAllyCrestId() > 0)) { String allyCrest = clan.getAllyCrestId() > 0 ? "Crest.crest_"+Config.SERVER_ID+"_"+String.valueOf(clan.getAllyCrestId()) : "L2UI.SquareBlank"; htm = htm.replace("$ally_crest_id", allyCrest); String clanCrest = clan.getCrestId() > 0 ? "Crest.crest_"+Config.SERVER_ID + "_" +String.valueOf(clan.getCrestId()) : "L2UI.SquareBlank"; htm = htm.replace("$clan_crest_id", clanCrest); return htm; } return " "; } /** * this is the worker method that is called when someone uses an command. * * @return command success */ @Override public String parse(String input, String ext, L2PcInstance cha) { String out = input; if (out != null) { // simple prot. against possible infinite loop in damaged/incorrect htmls int counter = 0; // workaround for showing clan and ally crests. to use, simply put "%clan_crest_%CLAN_ID%_%" into your html, and this will be replaced with // html code displaying that clan's crest (+ally crest if set). while(out.contains("%clan_crest_") && counter < 50) { counter++; int clanId = extractClanId(out); out = out.replace("%clan_crest_" + String.valueOf(clanId) + "_%", getCrestCode(clanId)); } } return out; } /** * this method is called at initialization to register all the item ids automatically * * @return all known itemIds */ @Override public String[] getFileExtensions() { return new String[]{".htm", ".html", null}; } /** * @return true == this parser will be executed once, on every requestm to load files with getFileExtensions() extensions, by core HtmCache manager. HtmCache will then<br> * provide parsed files, to any requester (until server reboot or forced //reload html is performed). */ @Override public boolean getParseOnceOnLoad() { return false; } /** * @return true == this parser will be executed, before sending html to client, not on load from datapack (use eg. when you wish to allow other parsers run first, or manipulate your * html manually). */ @Override public boolean getParseOnSend() { return true; }}
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
-
- Posts: 113
- Joined: Sun Mar 28, 2010 6:17 pm
Re: Crest
Yeah this solution works well, not bad way to hide part of the image.
Thx for sharing it with me.
By the way, i think it's better to not show L2UI.SquareBlank in case clan doesn't have a crest because it doesn't look so good.
I made it like that:
Thx for sharing it with me.
By the way, i think it's better to not show L2UI.SquareBlank in case clan doesn't have a crest because it doesn't look so good.
I made it like that:
Code: Select all
private String getCrestHtml(int clanCrestId, int allyCrestId) { StringBuilder builder = new StringBuilder(); builder.append("<table fixwidth=24 border=0 cellpadding=0 cellspacing=0>"); builder.append(" <tr>"); builder.append(" <td fixwidth=8>"); if(allyCrestId > 0) { builder.append(" <table fixwidth=8 border=0 cellpadding=0 cellspacing=0 background=\"Crest.crest_1_"+allyCrestId+"\""); builder.append(" <tr>"); builder.append(" <tr>"); builder.append(" <td fixwidth=8><img height=4 width=8 src=\"L2UI.SquareBlack\"><br1> </td>"); builder.append(" </tr>"); builder.append(" </table>"); } else builder.append("<br>"); builder.append(" </td>"); builder.append(" <td fixwidth=16>"); if(clanCrestId > 0) { builder.append(" <table fixwidth=16 border=0 cellpadding=0 cellspacing=0 background=\"Crest.crest_1_"+clanCrestId+"\">"); builder.append(" <tr>"); builder.append(" <td fixwidth=16><img height=4 width=16 src=\"L2UI.SquareBlack\"><br1> </td>"); builder.append(" </tr>"); builder.append(" </table>"); } else builder.append("<br>"); builder.append(" </td>"); builder.append(" </tr>"); builder.append("</table>"); return builder.toString(); }