Флажки в html диалогах

Сергей53338

Единомышленник
Участник
Сообщения
9
Розыгрыши
0
Репутация
0
Реакции
0
Баллы
183
Хроники
  1. Chaotic Throne: High Five
Исходники
Присутствуют
Сборка
l2-scripts
Всем привет. Есть у кого пример html диалога с использованием флажков 1773619043220.webp , ползунков 1773619057341.webp и кнопки выбора 1773619074307.webp как в настройках л2? нужно внедрить такие диалоги со стороны сервера к НПС, а пример не могу найти. я так понимаю все это дело со стороны клиента (интерфейс настроек) содержится в interface.xdat, но там совсем все по другому и как преобразовать в стандартный серверный html диалог я хз
 
Всем привет. Есть у кого пример html диалога с использованием флажковПосмотреть вложение 94274, ползунковПосмотреть вложение 94275 и кнопки выбораПосмотреть вложение 94276 как в настройках л2? нужно внедрить такие диалоги со стороны сервера к НПС, а пример не могу найти. я так понимаю все это дело со стороны клиента (интерфейс настроек) содержится в interface.xdat, но там совсем все по другому и как преобразовать в стандартный серверный html диалог я хз
Ну на клиенте сальва можно точно вызвать всплывающий список на остальных хз ниже пример
Код:
        <td width=80 align=left>
            <combobox width=40 var=selectid list="1;2;3;4;5;6;7;8;9;10">
        </td>
 
Ну на клиенте сальва можно точно вызвать всплывающий список на остальных хз ниже пример
Код:
        <td width=80 align=left>
            <combobox width=40 var=selectid list="1;2;3;4;5;6;7;8;9;10">
        </td>
комбобоксы и на хф так же работают, а вот слайдеров в html вроде нету
пример комбобокса можешь посмотреть в комюнить хтмл (баффер) где есть выбор цели на кого накладывать баф

Но я бы посоветовал все же перейти к UI клиента, там возможностей куда больше чем в html
 
Ну про выпадающие списки уже выше написали, а флажки тупо кнопками с соответствующими текстурами разве что только делать.

как-то так, с юзом в кнопках текстур L2UI.CheckBox и L2UI.CheckBox_checked к примеру.

L2_XfoQkrabZA.webp

Единственный вот минус этого - каждое изменение любого чекбокса - это отправка на сервер байпасса и перегенерация всей хтмлки с последующей отправкой клиенту.
 
Последнее редактирование:
Ну про выпадающие списки уже выше написали, а флажки тупо кнопками с соответствующими текстурами разве что только делать.

как-то так, с юзом в кнопках текстур L2UI.CheckBox и L2UI.CheckBox_checked к примеру.

Посмотреть вложение 94296

Единственный вот минус этого - каждое изменение любого чекбокса - это отправка на сервер байпасса и перегенерация всей хтмлки с последующей отправкой клиенту.
Поделись пожалуйста этой HTML'лкой, чтоб самому не изобретать велосипед.
 
Да там особо ничего нет
HTML:
<html noscrollbar>
<title>Настройки</title>
<body>
<table border=0 cellpadding=0 cellspacing=0 height=505 width=770>
<tr>
    %_menu_%
    <td width=662 valign=top>
        <center>
        <br><font name=hs12 color=00FF00>Дополнительные настройки</font><img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Отключить повышение уровня на основном классе</td>
                <td width=30 align=right>%no_exp_0%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Отключить повышение уровня на двойном классе</td>
                <td width=30 align=right>%no_exp_1%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Отключить показ дополнительной информации об NPC при Shift+Click по нему</td>
                <td width=30 align=right>%no_shift%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Показывать шансы дропа и спойла предметов с мобов, без учета штрафа от разницы уровней</td>
                <td width=30 align=right>%no_level_penalty%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Отключить показ игроков, сидящих в режиме покупки/продажи</font></td>
                <td width=30 align=right>%no_traders%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Отключить особую AFK-анимацию для владельцев замков</font></td>
                <td width=30 align=right>%no_idle_anim%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Показывать шанс успешного прохождения дебаффов</td>
                <td width=30 align=right>%show_chance%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Автоматическое изучение умений <font color=999999>(если это разрешено настройками сервера)</font></td>
                <td width=30 align=right>%auto_learn%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Автоматический подбор обычного дропа <font color=999999>(некоторые предметы подбираются автоматически в любом случае)</font></td>
                <td width=30 align=right>%auto_loot_i%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Автоматический подбор хербов</td>
                <td width=30 align=right>%auto_loot_h%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Автоматически отклонять приглашения на PvP-эвенты</td>
                <td width=30 align=right>%auto_dei%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Автоматически принимать приглашения в группу от друзей</td>
                <td width=30 align=right>%auto_jpf%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=600>Автоматически принимать приглашения в группу от игроков из вашего клана</td>
                <td width=30 align=right>%auto_jpc%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=400>Время поддержки персонажа в игре при вылете из нее <font color=999999>(в секундах)</font></td>
                <td width=150 align=right>%t_no_carrier%</td>
                <td width=30 align=right><edit width=30 var="noCarrier" type="number"></td>
                <td width=80 height=30 align=right>%b_no_carrier%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=515>Язык для диалогов NPC, некоторых системных сообшений и т.д.<font color=LEVEL>*</font></td>
                <td width=40 align=right>%b_lang_ru%</td>
                <td width=40 align=right>%b_lang_en%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        <table width=660>
            <tr>
                <td width=490>Транслитерация сообщений игроков в чате</td>
                <td width=40 align=right>%b_translit_lat%</td>
                <td width=40 align=right>%b_translit_on%</td>
                <td width=40 align=right>%b_translit_off%</td>
            </tr>
        </table>
        <img src="L2UI.SquareGray" width=660 height=1><img src="L2UI.SquareBlank" width=660 height=2>
        </center>
        <br>
        <font color=LEVEL>*</font> Диалог у NPC будет показан на выбранном языке только в том случае, если он существует на сервере.%%
        В дополнительной информации об NPC (Shift+Click) и в некоторых услугах, размещенных в Community Board названия%%
        предметов/умений/квестов могут зависеть от выбранного языка.
    </td>
</tr>
</table>
</body>
</html>
А сами чекбоксы и т.д. генерятся кодом коммунки
Java:
package handler.commands.community;

import java.util.StringTokenizer;

import l2p.gameserver.config.CustomConfig;
import l2p.gameserver.config.OtherConfig;
import l2p.gameserver.enums.SubClassType;
import l2p.gameserver.enums.players.Language;
import l2p.gameserver.holders.variables.Variables;
import l2p.gameserver.model.Player;
import l2p.gameserver.network.s2c.ShowBoard;
import l2p.gameserver.utils.HtmlUtils;
import l2p.gameserver.utils.HtmlUtils.ButtonType;

/**
 * @author Gaikotsu
 */
public class CommunityConfig extends AbstractCommunityCommand
{
    private String[] _commands = new String[] { "_config" };

    @Override
    public String[] getCommands()
    {
        return _commands;
    }

    @Override
    public void useCommand(Player player, String bypass)
    {
        if (bypass.startsWith("_config;no_exp_0;"))
        {
            player.getVariables().setBlockExp(SubClassType.BASE, getValue(bypass, 0), true);
        }
        else if (bypass.startsWith("_config;no_exp_1;"))
        {
            player.getVariables().setBlockExp(SubClassType.DUAL, getValue(bypass, 0), true);
        }
        else if (bypass.startsWith("_config;no_exp_2;"))
        {
            player.getVariables().setBlockExp(SubClassType.SUB, getValue(bypass, 0), true);
        }
        else if (bypass.startsWith("_config;no_shift;"))
        {
            player.getVariables().setNotUseShift(getValue(bypass, false), true);
        }
        else if (bypass.startsWith("_config;no_level_penalty;"))
        {
            player.getVariables().setNotUseLevelPenalty(getValue(bypass, false), true);
        }
        else if (bypass.startsWith("_config;no_idle_anim;"))
        {
            player.getVariables().setNotUseIdleAnim(getValue(bypass, false), true);
        }
        else if (bypass.startsWith("_config;no_traders;"))
        {
            player.getVariables().setNotShowTraders(getValue(bypass, false), true);
        }
        else if (bypass.startsWith("_config;show_chance;"))
        {
            player.getVariables().setShowChance(getValue(bypass, false), true);
        }
        else if (bypass.startsWith("_config;auto_dei;"))
        {
            player.getVariables().setAutoDeclineEventInvite(getValue(bypass, false), true);
        }
        else if (bypass.startsWith("_config;auto_learn;"))
        {
            if (getValue(bypass, false))
            {
                if (OtherConfig.AUTO_LEARN_SKILLS)
                    player.getVariables().setAutoLearn(true, true);
                else
                    player.sendPopupMessage("Автоматическое изучение умений не включено, т.к. запрещено настройками сервера.");
            }
            else
                player.getVariables().setAutoLearn(false, true);
        }
        else if (bypass.startsWith("_config;auto_loot_i;"))
        {
            if (OtherConfig.AUTO_LOOT_INDIVIDUAL)
                player.getVariables().setAutoLoot(getValue(bypass, false), true);
            else
                player.sendPopupMessage("Индивидуальное включение и выключение автоподбора запрещено настройками сервера.");

        }
        else if (bypass.startsWith("_config;auto_loot_h;"))
        {
            if (OtherConfig.AUTO_LOOT_INDIVIDUAL)
                player.getVariables().setAutoLootHerbs(getValue(bypass, false), true);
            else
                player.sendPopupMessage("Индивидуальное включение и выключение автоподбора запрещено настройками сервера.");
        }
        else if (bypass.startsWith("_config;auto_jpf;"))
        {
            if (getValue(bypass, false))
                player.getVariables().addAutoJoinParty(Variables.F_FRIEND, true);
            else
                player.getVariables().removeAutoJoinParty(Variables.F_FRIEND, true);
        }
        else if (bypass.startsWith("_config;auto_jpc;"))
        {
            if (getValue(bypass, false))
                player.getVariables().addAutoJoinParty(Variables.F_CLAN, true);
            else
                player.getVariables().removeAutoJoinParty(Variables.F_CLAN, true);
        }
        else if (bypass.startsWith("_config;lang;"))
        {
            String value = getValue(bypass, "ru");

            if (value.equalsIgnoreCase("ru"))
                player.getVariables().setLang(Language.RUSSIAN, true);
            else if (value.equalsIgnoreCase("en"))
                player.getVariables().setLang(Language.ENGLISH, true);
        }
        else if (bypass.startsWith("_config;translit;"))
        {
            String value = getValue(bypass, "off");

            if (value.equalsIgnoreCase("on"))
                player.getVariables().setVar(Variables.TRANSLIT, "tc");
            else if (value.equalsIgnoreCase("lat"))
                player.getVariables().setVar(Variables.TRANSLIT, "tl");
            else
                player.getVariables().unsetVar(Variables.TRANSLIT);
        }
        else if (bypass.startsWith("_config;no_carrier;"))
        {
            int value = getValue(bypass, CustomConfig.NO_CARRIER_DEF_TIME);

            if (value > CustomConfig.NO_CARRIER_MAX_TIME)
                value = CustomConfig.NO_CARRIER_MAX_TIME;
            else if (value < CustomConfig.NO_CARRIER_MIN_TIME)
                value = CustomConfig.NO_CARRIER_MIN_TIME;

            player.getVariables().setVar(Variables.NO_CARRIER, value);
        }

        String html = getHtml("config.htm", player, true);

        html = html.replace("%no_exp_0%", HtmlUtils.checkBox("bypass _config;no_exp_0", player.getVariables().isBlockExp(SubClassType.BASE)));
        html = html.replace("%no_exp_1%", HtmlUtils.checkBox("bypass _config;no_exp_1", player.getVariables().isBlockExp(SubClassType.DUAL)));
        html = html.replace("%no_exp_2%", HtmlUtils.checkBox("bypass _config;no_exp_2", player.getVariables().isBlockExp(SubClassType.SUB)));
        html = html.replace("%no_shift%", HtmlUtils.checkBox("bypass _config;no_shift", player.getVariables().isNotUseShift()));
        html = html.replace("%no_level_penalty%", HtmlUtils.checkBox("bypass _config;no_level_penalty", player.getVariables().isNotUseLevelPenalty()));
        html = html.replace("%no_idle_anim%", HtmlUtils.checkBox("bypass _config;no_idle_anim", player.getVariables().isNotUseIdleAnim()));
        html = html.replace("%no_traders%", HtmlUtils.checkBox("bypass _config;no_traders", player.getVariables().isNotShowTraders()));
        html = html.replace("%show_chance%", HtmlUtils.checkBox("bypass _config;show_chance", player.getVariables().isShowChance()));
        html = html.replace("%auto_learn%", HtmlUtils.checkBox("bypass _config;auto_learn", player.getVariables().isAutoLearn()));
        html = html.replace("%auto_loot_i%", HtmlUtils.checkBox("bypass _config;auto_loot_i", player.getVariables().isAutoLoot(), OtherConfig.AUTO_LOOT_INDIVIDUAL));
        html = html.replace("%auto_loot_h%", HtmlUtils.checkBox("bypass _config;auto_loot_h", player.getVariables().isAutoLootHerbs(), OtherConfig.AUTO_LOOT_INDIVIDUAL));
        html = html.replace("%auto_dei%", HtmlUtils.checkBox("bypass _config;auto_dei", player.getVariables().isAutoDeclineEventInvite()));
        html = html.replace("%auto_jpf%", HtmlUtils.checkBox("bypass _config;auto_jpf", player.getVariables().isAutoJoinParty(Variables.F_FRIEND)));
        html = html.replace("%auto_jpc%", HtmlUtils.checkBox("bypass _config;auto_jpc", player.getVariables().isAutoJoinParty(Variables.F_CLAN)));

        html = html.replace("%b_lang_ru%", HtmlUtils.button(ButtonType.SMALL, "RU", "bypass _config;lang;ru", player.getVariables().getLang() == Language.RUSSIAN, 40));
        html = html.replace("%b_lang_en%", HtmlUtils.button(ButtonType.SMALL, "EN", "bypass _config;lang;en", player.getVariables().getLang() == Language.ENGLISH, 40));

        String tl = player.getVariables().getVar(Variables.TRANSLIT, "off");

        html = html.replace("%b_translit_lat%", HtmlUtils.button(ButtonType.SMALL, "Лат.", "bypass _config;translit;lat", tl.equalsIgnoreCase("tl"), 40));
        html = html.replace("%b_translit_on%", HtmlUtils.button(ButtonType.SMALL, "Вкл.", "bypass _config;translit;on", tl.equalsIgnoreCase("tc"), 40));
        html = html.replace("%b_translit_off%", HtmlUtils.button(ButtonType.SMALL, "Выкл.", "bypass _config;translit;off", tl.equalsIgnoreCase("off"), 40));

        html = html.replace("%b_no_carrier%", HtmlUtils.button(ButtonType.SMALL, "Установить", "bypass _config;no_carrier; $noCarrier", !CustomConfig.NO_CARRIER_ENABLED, 75));
        html = html.replace("%t_no_carrier%", CustomConfig.NO_CARRIER_ENABLED ? "Текущее значение: <font color=LEVEL>" + player.getVariables().getVar(Variables.NO_CARRIER, CustomConfig.NO_CARRIER_DEF_TIME) + "</font> сек." : "<font color=FF0000>Функция отключена</font>");

        ShowBoard.separateAndSend(html, player);
    }

    private static String getValue(String str, String _def)
    {
        StringTokenizer st = new StringTokenizer(str, ";");

        if (st.countTokens() < 3)
            return _def;

        st.nextToken();
        st.nextToken();
        return st.nextToken().trim();
    }

    private static boolean getValue(String str, boolean _def)
    {
        StringTokenizer st = new StringTokenizer(str, ";");

        if (st.countTokens() < 3)
            return _def;

        st.nextToken();
        st.nextToken();
        return st.nextToken().trim().equals("1");
    }

    private static int getValue(String str, int _def)
    {
        StringTokenizer st = new StringTokenizer(str, ";");

        if (st.countTokens() < 3)
            return _def;

        st.nextToken();
        st.nextToken();
        return Integer.valueOf(st.nextToken().trim());
    }
}
Ну и отдельный класс еще вот для генерации разных HTML-элементов
Java:
package l2p.gameserver.utils;

import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import l2p.gameserver.config.OtherConfig;
import l2p.gameserver.data.holder.StringHolder;
import l2p.gameserver.enums.classes.ClassId;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.instances.NpcInstance;
import l2p.gameserver.model.skills.Skill;
import l2p.gameserver.network.components.CustomMessage;
import l2p.gameserver.network.components.NpcString;
import l2p.gameserver.network.components.SysString;
import l2p.gameserver.network.s2c.NpcHtmlMessage;

public class HtmlUtils
{
    public static final String PREV_BUTTON = "<button value=\"&$1037;\" action=\"bypass %prev_bypass%\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
    public static final String NEXT_BUTTON = "<button value=\"&$1038;\" action=\"bypass %next_bypass%\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";

    public static enum LineType
    {
        BLANK("L2UI.SquareBlank"),
        BLACK("L2UI.SquareBlack"),
        WHITE("L2UI.SquareWhite"),
        GRAY("L2UI.SquareGray"),
        MB_ARROW("L2UI_CH3.minibar_arrow"),
        MB_FOOD("L2UI_CH3.minibar_food"),
        MB_MAGIC("L2UI_CH3.minibar_magic"),
        MB_WATER("L2UI_CH3.minibar_water");

        private final String _texture;

        private LineType(String texture)
        {
            _texture = texture;
        }

        public String getTexture()
        {
            return _texture;
        }
    }

    public static enum ButtonType
    {
        SMALL("L2UI_CT1.Button_DF_Small", "L2UI_CT1.Button_DF_Small_Down", -1, 24),
        NORMAL("L2UI_CT1.Button_DF", "L2UI_CT1.Button_DF_Down", -1, 26),
        LARGE("L2UI_CT1.Button_DF_Large", "L2UI_CT1.Button_DF_Large_Down", -1, 35),
        UP("L2UI_CH3.UpButton", "L2UI_CH3.upbutton_down", 15, 15),
        DOWN("L2UI_CH3.DownButton", "L2UI_CH3.downbutton_down", 15, 15),
        PREV("L2UI_CH3.prev1", "L2UI_CH3.prev1_down", 15, 15),
        NEXT("L2UI_CH3.next1", "L2UI_CH3.next1_down", 15, 15),
        ABOUT("L2UI_CH3.aboutotpicon", "L2UI_CH3.aboutotpicon_down", 15, 15),
        INPUT("L2UI_CT1.Button_DF_Input", "L2UI_CT1.Button_DF_Input_Down", 15, 15),
        LIST("L2UI_CT1.PostWnd_DF_Btn_List", "L2UI_CT1.PostWnd_DF_Btn_List_Down", 15, 15),
        OLYMPIAD_APPLY("L2UI_CT1.OlympiadWnd_DF_Apply", "L2UI_CT1.OlympiadWnd_DF_Apply_Down", 197, 29),
        OLYMPIAD_BACK("L2UI_CT1.OlympiadWnd_DF_Back", "L2UI_CT1.OlympiadWnd_DF_Back_Down", 197, 29),
        OLYMPIAD_BUY_EQUIP("L2UI_CT1.OlympiadWnd_DF_BuyEquip", "L2UI_CT1.OlympiadWnd_DF_BuyEquip_Down", 197, 29),
        OLYMPIAD_BUY_ETC("L2UI_CT1.OlympiadWnd_DF_BuyEtc", "L2UI_CT1.OlympiadWnd_DF_BuyEtc_Down", 197, 29),
        OLYMPIAD_FIGHT_1("L2UI_CT1.OlympiadWnd_DF_Fight1None", "L2UI_CT1.OlympiadWnd_DF_Fight1None_Down", 197, 29),
        OLYMPIAD_FIGHT_3("L2UI_CT1.OlympiadWnd_DF_Fight3None", "L2UI_CT1.OlympiadWnd_DF_Fight3None_Down", 197, 29),
        OLYMPIAD_HERO_CONFIRM("L2UI_CT1.OlympiadWnd_DF_HeroConfirm", "L2UI_CT1.OlympiadWnd_DF_HeroConfirm_Down", 197, 29),
        OLYMPIAD_INFO("L2UI_CT1.OlympiadWnd_DF_Info", "L2UI_CT1.OlympiadWnd_DF_Info_Down", 197, 29),
        OLYMPIAD_REWARD("L2UI_CT1.OlympiadWnd_DF_Reward", "L2UI_CT1.OlympiadWnd_DF_Reward_Down", 197, 29),
        OLYMPIAD_WATCH("L2UI_CT1.OlympiadWnd_DF_Watch", "L2UI_CT1.OlympiadWnd_DF_Watch_Down", 197, 29);

        private final String _fore;
        private final String _back;
        private final int _width;
        private final int _height;

        private ButtonType(String fore, String back, int width, int height)
        {
            _fore = fore;
            _back = back;
            _width = width;
            _height = height;
        }

        public String getFore()
        {
            return _fore;
        }

        public String getBack()
        {
            return _back;
        }

        public int getWidth()
        {
            return _width;
        }

        public int getWidth(int width)
        {
            return _width > 0 ? _width : width;
        }

        public int getHeight()
        {
            return _height;
        }

        public int getHeight(int height)
        {
            return _height > 0 ? _height : height;
        }
    }

    public static enum BarType
    {
        LARGE_CP("L2UI_CT1.Gauge_DF_Large_CP_Center", "L2UI_CT1.Gauge_DF_Large_CP_bg_Center", 16),
        LARGE_HP("L2UI_CT1.Gauge_DF_Large_HP_Center", "L2UI_CT1.Gauge_DF_Large_HP_bg_Center", 16),
        LARGE_MP("L2UI_CT1.Gauge_DF_Large_MP_Center", "L2UI_CT1.Gauge_DF_Large_MP_bg_Center", 16),
        LARGE_VP("L2UI_CT1.Gauge_DF_Large_VP_Center", "L2UI_CT1.Gauge_DF_Large_VP_bg_Center", 16),
        LARGE_EXP("L2UI_CT1.Gauge_DF_Large_EXP_Center", "L2UI_CT1.Gauge_DF_Large_EXP_bg_Center", 16),
        ATTR_FIRE("L2UI_CT1.Gauge_DF_Attribute_Fire_Center", "L2UI_CT1.Gauge_DF_Attribute_Fire_bg_Center", 8),
        ATTR_WATER("L2UI_CT1.Gauge_DF_Attribute_Water_Center", "L2UI_CT1.Gauge_DF_Attribute_Water_bg_Center", 8),
        ATTR_WIND("L2UI_CT1.Gauge_DF_Attribute_Wind_Center", "L2UI_CT1.Gauge_DF_Attribute_Wind_bg_Center", 8),
        ATTR_EARTH("L2UI_CT1.Gauge_DF_Attribute_Earth_Center", "L2UI_CT1.Gauge_DF_Attribute_Earth_bg_Center", 8),
        ATTR_DIVINE("L2UI_CT1.Gauge_DF_Attribute_Divine_Center", "L2UI_CT1.Gauge_DF_Attribute_Divine_bg_Center", 8),
        ATTR_DARK("L2UI_CT1.Gauge_DF_Attribute_Dark_Center", "L2UI_CT1.Gauge_DF_Attribute_Dark_bg_Center", 8);

        private final String _fore;
        private final String _back;
        private final int _height;

        private BarType(String fore, String back, int height)
        {
            _fore = fore;
            _back = back;
            _height = height;
        }

        public String getFore()
        {
            return _fore;
        }

        public String getBack()
        {
            return _back;
        }

        public int getHeight()
        {
            return _height;
        }

        public int getHeight(int height)
        {
            return height > 0 ? height : _height;
        }
    }

    public static String getResidenceName(int id)
    {
        return "&%" + id + ";";
    }

    public static String getResidenceLoc(int id)
    {
        return "&^" + id + ";";
    }

    public static String getResidenceDesc(int id)
    {
        return "&*" + id + ";";
    }

    public static String getNpcName(int npcId)
    {
        return "&@" + npcId + ";";
    }

    public static String getItemName(int itemId)
    {
        return "&#" + itemId + ";";
    }

    public static String getSysString(SysString sysString)
    {
        return getSysString(sysString.getId());
    }

    public static String getSysString(int id)
    {
        return "&$" + id + ";";
    }

    public static String getClassName(int classId)
    {
        return "<ClassId>" + classId + "</ClassId>";
    }

    public static String getClassName(ClassId classId)
    {
        return "<ClassId>" + classId.getId() + "</ClassId>";
    }

    public static String getNpcString(NpcString id, Object... params)
    {
        return getNpcString(id.getId(), params);
    }

    public static String getNpcString(int id, Object... params)
    {
        String replace = "<fstring";

        if (params.length > 0)
            for (int i = 0; i < params.length; i++)
                replace += " p" + (i + 1) + "=\"" + String.valueOf(params[i]) + "\"";

        replace += ">" + id + "</fstring>";
        return replace;
    }

    public static String getItemName(int id, Player player)
    {
        return StringHolder.getInstance().getItem(id, player, true);
    }

    public static String getNpcName(int id, Player player)
    {
        return StringHolder.getInstance().getNpc(id, true);
    }

    public static String getSkillName(int id, int level, Player player)
    {
        return StringHolder.getInstance().getSkill(id, level, player);
    }

    public static String getSkillName(Skill skill, Player player)
    {
        return StringHolder.getInstance().getSkill(skill.getDisplayedId(), skill.getDisplayedLevel(), player);
    }

    public static String getQuestName(int id, Player player)
    {
        return StringHolder.getInstance().getQuest(id, player);
    }

    /**
     * Работает как обычный trim(), но в дополнение заменяет кавычки на нестандартные UTF8, удяляет все двойные пробелы и убирает символы <>
     *
     * @param str    - исходная строка
     *
     * @return    - обработанная строка
     */
    public final static String trim(String str)
    {
        str = str.trim().replaceAll("\"", "״").replaceAll("'", "´").replaceAll("<", StringUtils.EMPTY).replaceAll(">", StringUtils.EMPTY);
        int length;

        do
        {
            length = str.length();
            str = str.replaceAll("  ", " ");
        }
        while (length > str.length());

        return str;
    }

    public final static String line(LineType type, int width)
    {
        return line(type, width, 1);
    }

    public final static String line(LineType type, int width, int height)
    {
        return line(type.getTexture(), width, height);
    }

    public final static String line(String texture, int width, int height)
    {
        return String.format("<table border=0 cellpadding=0 cellspacing=0><tr><td><img src=\"%s\" width=%d height=%d></td></tr></table>", texture, width, height);
    }

    public final static String button(ButtonType type, String value, String action)
    {
        return button(type.getFore(), type.getBack(), value, action, null, null, type.getWidth(), type.getHeight());
    }

    public final static String button(ButtonType type, String value, String action, int width)
    {
        return button(type.getFore(), type.getBack(), value, action, null, null, width, type.getHeight());
    }

    public final static String button(ButtonType type, String value, String action, int width, int height)
    {
        return button(type.getFore(), type.getBack(), value, action, null, null, width, height);
    }

    public final static String button(ButtonType type, String value, String action, String msg, String tooltip)
    {
        return button(type.getFore(), type.getBack(), value, action, msg, tooltip, type.getWidth(), type.getHeight());
    }

    public final static String button(ButtonType type, String value, String action, String msg, String tooltip, int width)
    {
        return button(type.getFore(), type.getBack(), value, action, msg, tooltip, width, type.getHeight());
    }

    public final static String button(ButtonType type, String value, String action, boolean pressed)
    {
        if (!pressed)
            return button(type.getFore(), type.getBack(), value, action, null, null, type.getWidth(), type.getHeight());
        else
            return pressedButton(type.getBack(), value, type.getWidth(), type.getHeight());
    }

    public final static String button(ButtonType type, String value, String action, boolean pressed, int width)
    {
        if (!pressed)
            return button(type.getFore(), type.getBack(), value, action, null, null, width, type.getHeight());
        else
            return pressedButton(type.getBack(), value, width, type.getHeight());
    }

    public final static String button(ButtonType type, String value, String action, boolean pressed, int width, int height)
    {
        if (!pressed)
            return button(type.getFore(), type.getBack(), value, action, null, null, width, height);
        else
            return pressedButton(type.getBack(), value, width, height);
    }

    public final static String button(ButtonType type, String value, String action, String msg, String tooltip, int width, int height)
    {
        return button(type.getFore(), type.getBack(), value, action, msg, tooltip, type.getWidth(width), type.getHeight(height));
    }

    public final static String button(String fore, String back, String value, String action, String msg, String tooltip, int width, int height)
    {
        if (msg != null)
        {
            if (tooltip != null)
                return String.format("<button value=\"%s\" action=\"%s\" msg=\"%s\" tooltip=\"%s\" width=%d height=%d fore=\"%s\" back=\"%s\">", value, action, msg, tooltip, width, height, fore, back);
            else
                return String.format("<button value=\"%s\" action=\"%s\" msg=\"%s\" width=%d height=%d fore=\"%s\" back=\"%s\">", value, action, msg, width, height, fore, back);
        }
        else
        {
            if (tooltip != null)
                return String.format("<button value=\"%s\" action=\"%s\" tooltip=\"%s\" width=%d height=%d fore=\"%s\" back=\"%s\">", value, action, tooltip, width, height, fore, back);
            else
                return String.format("<button value=\"%s\" action=\"%s\" width=%d height=%d fore=\"%s\" back=\"%s\">", value, action, width, height, fore, back);
        }
    }

    public final static String pressedButton(ButtonType type, String text)
    {
        return pressedButton(type.getBack(), text, type.getWidth(), type.getHeight());
    }

    public final static String pressedButton(ButtonType type, String text, int width)
    {
        return pressedButton(type.getBack(), text, width, type.getHeight());
    }

    public final static String pressedButton(ButtonType type, String text, int width, int height)
    {
        return pressedButton(type.getBack(), text, type.getWidth(width), type.getHeight(height));
    }

    public final static String pressedButton(String back, String text, int width, int height)
    {
        return String.format("<table height=%d border=0 cellpadding=0 cellspacing=0><tr><td width=%d background=\"%s\" align=center>%s</td></tr></table>", height, width, back, text);
    }

    public final static String checkBox(String action, boolean checked)
    {
        return checkBox(action, checked, true);
    }

    public final static String checkBox(String action, boolean checked, boolean enabled)
    {
        if (enabled)
        {
            if (checked)
                return String.format("<button value=\" \" action=\"%s;%s\" width=15 height=15 fore=\"L2UI.CheckBox_checked\" back=\"L2UI.CheckBox_checked\">", action, 0);
            else
                return String.format("<button value=\" \" action=\"%s;%s\" width=15 height=15 fore=\"L2UI.CheckBox\" back=\"L2UI.CheckBox\">", action, 1);
        }
        else
        {
            if (checked)
                return "<img src=\"L2UI.CheckBox_checked\" width=15 height=15>";
            else
                return "<img src=\"L2UI.CheckBox\" width=15 height=15>";
        }
    }

    public static String bar(BarType type, int width, int current)
    {
        return bar(type.getFore(), type.getBack(), width, type.getHeight(0), current);
    }

    public static String bar(BarType type, int width, int height, int current)
    {
        return bar(type.getFore(), type.getBack(), width, type.getHeight(height), current);
    }

    public static String bar(String fore, String back, int width, int height, int current)
    {
        return String.format("<table border=0 cellpadding=0 cellspacing=0><tr><td width=%d height=%d background=\"%s\"><img src=\"%s\" width=%d height=%d></td></tr></table>", width, height + 2, back, fore, current, height);
    }

    //
    //
    //

    public final static void showFile(Player player, NpcInstance npc, String filename, String... replaces)
    {
        showFile(player, npc, filename, 0, 0, replaces);
    }

    public final static void showFile(Player player, NpcInstance npc, String filename, int val, String... replaces)
    {
        showFile(player, npc, filename, val, 0, replaces);
    }

    public final static void showFile(Player player, NpcInstance npc, String filename, int val, int type, String... replaces)
    {
        NpcHtmlMessage html = new NpcHtmlMessage(player, npc, filename, val, type);

        if (replaces != null && replaces.length > 0)
        {
            if (replaces.length % 2 != 0)
            {
                LogUtils.warn("HTML: Error in replaces definition. HTML file: " + filename + ", npc: " + (npc != null ? npc.getName() : "null"));
                return;
            }

            for (int i = 0; i < replaces.length; i = i + 2)
                html.replace(replaces[i], replaces[i + 1]);
        }

        player.sendPacket(html);
    }

    //
    //
    //

    public final static void showText(String text, Player player, NpcInstance npc)
    {
        showText(text, 0, player, npc);
    }

    public final static void showText(String text, int type, Player player, NpcInstance npc)
    {
        NpcHtmlMessage html = new NpcHtmlMessage(player, npc, type);
        html.setHtml(text);
        player.sendPacket(html);
    }

    //
    //
    //

    public final static void show(String text, Player player, NpcInstance npc, Object... arg)
    {
        show(text, 0, player, npc, arg);
    }

    public final static void show(String text, int type, Player player, NpcInstance npc, Object... arg)
    {
        if (text == null || player == null)
            return;

        NpcHtmlMessage msg = new NpcHtmlMessage(player, npc, type);

        // приводим нашу html-ку в нужный вид
        if (text.endsWith(".html") || text.endsWith(".htm"))
            msg.setFile(text);
        else
            msg.setHtml(bbParse(text));

        if (arg != null && arg.length % 2 == 0)
            for (int i = 0; i < arg.length; i = +2)
                msg.replace(String.valueOf(arg[i]), arg[i + 1]);

        player.sendPacket(msg);
    }

    public final static void show(CustomMessage message, Player self)
    {
        show(message.toString(), self, null);
    }

    //
    //
    //

    public static String replace(String str, String regex, int flags, String replace)
    {
        return Pattern.compile(regex, flags).matcher(str).replaceAll(replace);
    }

    public static boolean matches(String str, String regex, int flags)
    {
        return Pattern.compile(regex, flags).matcher(str).matches();
    }

    public static String bbParse(String str)
    {
        if (str == null)
            return null;

        str = str.replace("\r", StringUtils.EMPTY);
        str = str.replaceAll("(\\s|\"|\'|\\(|^|\n)\\*(.*?)\\*(\\s|\"|\'|\\)|\\?|\\.|!|:|;|,|$|\n)", "$1<font color=\"LEVEL\">$2</font>$3"); // *S1*
        str = str.replaceAll("(\\s|\"|\'|\\(|^|\n)\\$(.*?)\\$(\\s|\"|\'|\\)|\\?|\\.|!|:|;|,|$|\n)", "$1<font color=\"00FFFF\">$2</font>$3");// $S1$
        //s = replace(s, "^!(.*?)$", Pattern.MULTILINE, "<font color=\"FFFFFF\">$1</font>\n\n");
        str = str.replaceAll("%%\\s*\n", "<br1>");
        str = str.replaceAll("\n\n+", "<br>");
        //s = replace(s, "\\[([^\\]\\|]*?)\\|([^\\]]*?)\\]", Pattern.DOTALL, "<a action=\"bypass -h $1\">$2</a>");
        str = replace(str, "\\[([^\\]\\|]*?)\\|([^\\]]*?)\\|([^\\]]*?)\\]", Pattern.DOTALL, "<button ALIGN=LEFT ICON=\"$1\" action=\"bypass -h $2\">$3</button>");
        str = replace(str, "\\[([^\\]\\|]*?)\\|([^\\]]*?)\\]", Pattern.DOTALL, "<button ALIGN=LEFT ICON=\"NORMAL\" action=\"bypass -h $1\">$2</button>");
        str = str.replaceAll(" @M:", "\" msg=\"");
        str = str.replaceAll(" @W:", "\" width=\"");
        str = str.replaceAll(" @T:", "\" tooltip=\"");
        str = str.replaceAll("%need_dialog%", "<font color=\"00FFFF\">TODO: корректный текст диалога (если он у вас есть - поделитесь с администрацией)</font>");
        str = str.replaceAll("%free_teleport_level%", String.valueOf(OtherConfig.FREE_TELEPORT_MAX_LEVEL));
        return str;
    }
}
 

Logan22

Баллов: 41
лучший!
Назад
Сверху Снизу