Merged with released L2J-Unity files.

This commit is contained in:
mobiusdev
2016-06-12 01:34:09 +00:00
parent e003e87887
commit 635557f5da
18352 changed files with 3245113 additions and 2892959 deletions

View File

@ -0,0 +1,48 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html;
import java.util.Collection;
/**
* @author UnAfraid
* @param <T>
*/
@FunctionalInterface
public interface IBodyHandler<T>
{
void apply(int pages, T type, StringBuilder sb);
default void create(Collection<T> elements, int pages, int start, int elementsPerPage, StringBuilder sb)
{
int i = 0;
for (T element : elements)
{
if (i++ < start)
{
continue;
}
apply(pages, element, sb);
if (i >= (elementsPerPage + start))
{
break;
}
}
}
}

View File

@ -0,0 +1,25 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html;
/**
* @author UnAfraid
*/
public interface IBypassFormatter
{
String formatBypass(String bypass, int page);
}

View File

@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html;
/**
* @author UnAfraid
*/
public interface IHtmlStyle
{
String applyBypass(String bypass, String name, boolean isEnabled);
String applySeparator();
}

View File

@ -0,0 +1,26 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html;
/**
* @author UnAfraid
*/
@FunctionalInterface
public interface IPageHandler
{
void apply(String bypass, int currentPage, int pages, StringBuilder sb, IBypassFormatter bypassFormatter, IHtmlStyle style);
}

View File

@ -0,0 +1,114 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import com.l2jmobius.gameserver.model.html.formatters.DefaultFormatter;
import com.l2jmobius.gameserver.model.html.pagehandlers.DefaultPageHandler;
import com.l2jmobius.gameserver.model.html.styles.DefaultStyle;
/**
* @author UnAfraid
* @param <T>
*/
public class PageBuilder<T>
{
private final Collection<T> _elements;
private final int _elementsPerPage;
private final String _bypass;
private int _currentPage = 0;
private IPageHandler _pageHandler = DefaultPageHandler.INSTANCE;
private IBypassFormatter _formatter = DefaultFormatter.INSTANCE;
private IHtmlStyle _style = DefaultStyle.INSTANCE;
private IBodyHandler<T> _bodyHandler;
private PageBuilder(Collection<T> elements, int elementsPerPage, String bypass)
{
_elements = elements;
_elementsPerPage = elementsPerPage;
_bypass = bypass;
}
public PageBuilder<T> currentPage(int currentPage)
{
_currentPage = Math.max(currentPage, 0);
return this;
}
public PageBuilder<T> bodyHandler(IBodyHandler<T> bodyHandler)
{
Objects.requireNonNull(bodyHandler, "Body Handler cannot be null!");
_bodyHandler = bodyHandler;
return this;
}
public PageBuilder<T> pageHandler(IPageHandler pageHandler)
{
Objects.requireNonNull(pageHandler, "Page Handler cannot be null!");
_pageHandler = pageHandler;
return this;
}
public PageBuilder<T> formatter(IBypassFormatter formatter)
{
Objects.requireNonNull(formatter, "Formatter cannot be null!");
_formatter = formatter;
return this;
}
public PageBuilder<T> style(IHtmlStyle style)
{
Objects.requireNonNull(style, "Style cannot be null!");
_style = style;
return this;
}
public PageResult build()
{
Objects.requireNonNull(_bodyHandler, "Body was not set!");
final int pages = (_elements.size() / _elementsPerPage) + ((_elements.size() % _elementsPerPage) > 0 ? 1 : 0);
final StringBuilder pagerTemplate = new StringBuilder();
if (pages > 1)
{
_pageHandler.apply(_bypass, _currentPage, pages, pagerTemplate, _formatter, _style);
}
if (_currentPage > pages)
{
_currentPage = pages - 1;
}
final int start = Math.max(_elementsPerPage * _currentPage, 0);
final StringBuilder sb = new StringBuilder();
_bodyHandler.create(_elements, pages, start, _elementsPerPage, sb);
return new PageResult(pages, pagerTemplate, sb);
}
public static <T> PageBuilder<T> newBuilder(Collection<T> elements, int elementsPerPage, String bypass)
{
return new PageBuilder<>(elements, elementsPerPage, bypass.trim());
}
public static <T> PageBuilder<T> newBuilder(T[] elements, int elementsPerPage, String bypass)
{
return new PageBuilder<>(Arrays.asList(elements), elementsPerPage, bypass.trim());
}
}

View File

@ -0,0 +1,49 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html;
/**
* @author UnAfraid
*/
public class PageResult
{
private final int _pages;
private final StringBuilder _pagerTemplate;
private final StringBuilder _bodyTemplate;
public PageResult(int pages, StringBuilder pagerTemplate, StringBuilder bodyTemplate)
{
_pages = pages;
_pagerTemplate = pagerTemplate;
_bodyTemplate = bodyTemplate;
}
public int getPages()
{
return _pages;
}
public StringBuilder getPagerTemplate()
{
return _pagerTemplate;
}
public StringBuilder getBodyTemplate()
{
return _bodyTemplate;
}
}

View File

@ -0,0 +1,33 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html.formatters;
import com.l2jmobius.gameserver.model.html.IBypassFormatter;
/**
* @author UnAfraid
*/
public class BypassParserFormatter implements IBypassFormatter
{
public static final BypassParserFormatter INSTANCE = new BypassParserFormatter();
@Override
public String formatBypass(String bypass, int page)
{
return bypass + " page=" + page;
}
}

View File

@ -0,0 +1,33 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html.formatters;
import com.l2jmobius.gameserver.model.html.IBypassFormatter;
/**
* @author UnAfraid
*/
public class DefaultFormatter implements IBypassFormatter
{
public final static DefaultFormatter INSTANCE = new DefaultFormatter();
@Override
public String formatBypass(String bypass, int page)
{
return bypass + " " + page;
}
}

View File

@ -0,0 +1,73 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html.pagehandlers;
import com.l2jmobius.gameserver.model.html.IBypassFormatter;
import com.l2jmobius.gameserver.model.html.IHtmlStyle;
import com.l2jmobius.gameserver.model.html.IPageHandler;
/**
* Creates pager with links 1 2 3 | 9 10 | 998 | 999
* @author UnAfraid
*/
public class DefaultPageHandler implements IPageHandler
{
public static final DefaultPageHandler INSTANCE = new DefaultPageHandler(2);
protected final int _pagesOffset;
public DefaultPageHandler(int pagesOffset)
{
_pagesOffset = pagesOffset;
}
@Override
public void apply(String bypass, int currentPage, int pages, StringBuilder sb, IBypassFormatter bypassFormatter, IHtmlStyle style)
{
final int pagerStart = Math.max(currentPage - _pagesOffset, 0);
final int pagerFinish = Math.min(currentPage + _pagesOffset + 1, pages);
// Show the initial pages in case we are in the middle or at the end
if (pagerStart > _pagesOffset)
{
for (int i = 0; i < _pagesOffset; i++)
{
sb.append(style.applyBypass(bypassFormatter.formatBypass(bypass, i), String.valueOf(i + 1), currentPage == i));
}
// Separator
sb.append(style.applySeparator());
}
// Show current pages
for (int i = pagerStart; i < pagerFinish; i++)
{
sb.append(style.applyBypass(bypassFormatter.formatBypass(bypass, i), String.valueOf(i + 1), currentPage == i));
}
// Show the last pages
if (pages > pagerFinish)
{
// Separator
sb.append(style.applySeparator());
for (int i = pages - _pagesOffset; i < pages; i++)
{
sb.append(style.applyBypass(bypassFormatter.formatBypass(bypass, i), String.valueOf(i + 1), currentPage == i));
}
}
}
}

View File

@ -0,0 +1,56 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html.pagehandlers;
import com.l2jmobius.gameserver.model.html.IBypassFormatter;
import com.l2jmobius.gameserver.model.html.IHtmlStyle;
import com.l2jmobius.gameserver.model.html.IPageHandler;
/**
* Creates pager with links << | < | > | >>
* @author UnAfraid
*/
public class NextPrevPageHandler implements IPageHandler
{
public static final NextPrevPageHandler INSTANCE = new NextPrevPageHandler();
@Override
public void apply(String bypass, int currentPage, int pages, StringBuilder sb, IBypassFormatter bypassFormatter, IHtmlStyle style)
{
// Beginning
sb.append(style.applyBypass(bypassFormatter.formatBypass(bypass, 0), "<<", (currentPage - 1) < 0));
// Separator
sb.append(style.applySeparator());
// Previous
sb.append(style.applyBypass(bypassFormatter.formatBypass(bypass, currentPage - 1), "<", currentPage <= 0));
sb.append(style.applySeparator());
sb.append(String.format("<td align=\"center\">Page: %d/%d</td>", currentPage + 1, pages + 1));
sb.append(style.applySeparator());
// Next
sb.append(style.applyBypass(bypassFormatter.formatBypass(bypass, currentPage + 1), ">", currentPage >= pages));
// Separator
sb.append(style.applySeparator());
// End
sb.append(style.applyBypass(bypassFormatter.formatBypass(bypass, pages), ">>", (currentPage + 1) > pages));
}
}

View File

@ -0,0 +1,60 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html.styles;
import com.l2jmobius.gameserver.model.html.IHtmlStyle;
/**
* @author UnAfraid
*/
public class ButtonsStyle implements IHtmlStyle
{
private static final String DEFAULT_PAGE_LINK_FORMAT = "<td><button action=\"%s\" value=\"%s\" width=\"%d\" height=\"%d\" back=\"%s\" fore=\"%s\"></td>";
private static final String DEFAULT_PAGE_TEXT_FORMAT = "<td>%s</td>";
private static final String DEFAULT_PAGER_SEPARATOR = "<td align=center> | </td>";
public static final ButtonsStyle INSTANCE = new ButtonsStyle(40, 15, "L2UI_CT1.Button_DF", "L2UI_CT1.Button_DF");
private final int _width;
private final int _height;
private final String _back;
private final String _fore;
public ButtonsStyle(int width, int height, String back, String fore)
{
_width = width;
_height = height;
_back = back;
_fore = fore;
}
@Override
public String applyBypass(String bypass, String name, boolean isEnabled)
{
if (isEnabled)
{
return String.format(DEFAULT_PAGE_TEXT_FORMAT, name);
}
return String.format(DEFAULT_PAGE_LINK_FORMAT, bypass, name, _width, _height, _back, _fore);
}
@Override
public String applySeparator()
{
return DEFAULT_PAGER_SEPARATOR;
}
}

View File

@ -0,0 +1,47 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 com.l2jmobius.gameserver.model.html.styles;
import com.l2jmobius.gameserver.model.html.IHtmlStyle;
/**
* @author UnAfraid
*/
public class DefaultStyle implements IHtmlStyle
{
private static final String DEFAULT_PAGE_LINK_FORMAT = "<td><a action=\"%s\">%s</a></td>";
private static final String DEFAULT_PAGE_TEXT_FORMAT = "<td>%s</td>";
private static final String DEFAULT_PAGER_SEPARATOR = "<td align=center> | </td>";
public static final DefaultStyle INSTANCE = new DefaultStyle();
@Override
public String applyBypass(String bypass, String name, boolean isEnabled)
{
if (isEnabled)
{
return String.format(DEFAULT_PAGE_TEXT_FORMAT, name);
}
return String.format(DEFAULT_PAGE_LINK_FORMAT, bypass, name);
}
@Override
public String applySeparator()
{
return DEFAULT_PAGER_SEPARATOR;
}
}