Reworked storing key bindings.
This commit is contained in:
@@ -92,7 +92,6 @@ import com.l2jmobius.gameserver.data.xml.impl.SpawnsData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.StaticObjectData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.TeleportersData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.TransformData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.UIData;
|
||||
import com.l2jmobius.gameserver.datatables.AugmentationData;
|
||||
import com.l2jmobius.gameserver.datatables.BotReportTable;
|
||||
import com.l2jmobius.gameserver.datatables.EventDroplist;
|
||||
@@ -313,7 +312,6 @@ public class GameServer
|
||||
CrestTable.getInstance();
|
||||
TeleportLocationTable.getInstance();
|
||||
TeleportersData.getInstance();
|
||||
UIData.getInstance();
|
||||
MatchingRoomManager.getInstance();
|
||||
PetitionManager.getInstance();
|
||||
CursedWeaponsManager.getInstance();
|
||||
|
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* 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.data.xml.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||
import com.l2jmobius.gameserver.model.ActionKey;
|
||||
|
||||
/**
|
||||
* UI Data parser.
|
||||
* @author Zoey76
|
||||
*/
|
||||
public class UIData implements IGameXmlReader
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(UIData.class.getName());
|
||||
|
||||
private final Map<Integer, List<ActionKey>> _storedKeys = new HashMap<>();
|
||||
private final Map<Integer, List<Integer>> _storedCategories = new HashMap<>();
|
||||
|
||||
protected UIData()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
_storedKeys.clear();
|
||||
_storedCategories.clear();
|
||||
parseDatapackFile("data/ui/ui_en.xml");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _storedKeys.size() + " keys " + _storedCategories.size() + " categories.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseDocument(Document doc, File f)
|
||||
{
|
||||
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
|
||||
{
|
||||
if ("list".equalsIgnoreCase(n.getNodeName()))
|
||||
{
|
||||
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
|
||||
{
|
||||
if ("category".equalsIgnoreCase(d.getNodeName()))
|
||||
{
|
||||
parseCategory(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCategory(Node n)
|
||||
{
|
||||
final int cat = parseInteger(n.getAttributes(), "id");
|
||||
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
|
||||
{
|
||||
if ("commands".equalsIgnoreCase(d.getNodeName()))
|
||||
{
|
||||
parseCommands(cat, d);
|
||||
}
|
||||
else if ("keys".equalsIgnoreCase(d.getNodeName()))
|
||||
{
|
||||
parseKeys(cat, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCommands(int cat, Node d)
|
||||
{
|
||||
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
|
||||
{
|
||||
if ("cmd".equalsIgnoreCase(c.getNodeName()))
|
||||
{
|
||||
addCategory(_storedCategories, cat, Integer.parseInt(c.getTextContent()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseKeys(int cat, Node d)
|
||||
{
|
||||
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
|
||||
{
|
||||
if ("key".equalsIgnoreCase(c.getNodeName()))
|
||||
{
|
||||
final ActionKey akey = new ActionKey(cat);
|
||||
for (int i = 0; i < c.getAttributes().getLength(); i++)
|
||||
{
|
||||
final Node att = c.getAttributes().item(i);
|
||||
final int val = Integer.parseInt(att.getNodeValue());
|
||||
switch (att.getNodeName())
|
||||
{
|
||||
case "cmd":
|
||||
{
|
||||
akey.setCommandId(val);
|
||||
break;
|
||||
}
|
||||
case "key":
|
||||
{
|
||||
akey.setKeyId(val);
|
||||
break;
|
||||
}
|
||||
case "toggleKey1":
|
||||
{
|
||||
akey.setToogleKey1(val);
|
||||
break;
|
||||
}
|
||||
case "toggleKey2":
|
||||
{
|
||||
akey.setToogleKey2(val);
|
||||
break;
|
||||
}
|
||||
case "showType":
|
||||
{
|
||||
akey.setShowStatus(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
addKey(_storedKeys, cat, akey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a category to the stored categories.
|
||||
* @param map the map to store the category
|
||||
* @param cat the category
|
||||
* @param cmd the command
|
||||
*/
|
||||
public static void addCategory(Map<Integer, List<Integer>> map, int cat, int cmd)
|
||||
{
|
||||
map.computeIfAbsent(cat, k -> new ArrayList<>()).add(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and insert an Action Key into the stored keys.
|
||||
* @param map the map to store the key
|
||||
* @param cat the category
|
||||
* @param akey the action key
|
||||
*/
|
||||
public static void addKey(Map<Integer, List<ActionKey>> map, int cat, ActionKey akey)
|
||||
{
|
||||
map.computeIfAbsent(cat, k -> new ArrayList<>()).add(akey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the categories
|
||||
*/
|
||||
public Map<Integer, List<Integer>> getCategories()
|
||||
{
|
||||
return _storedCategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the keys
|
||||
*/
|
||||
public Map<Integer, List<ActionKey>> getKeys()
|
||||
{
|
||||
return _storedKeys;
|
||||
}
|
||||
|
||||
public static UIData getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final UIData _instance = new UIData();
|
||||
}
|
||||
}
|
@@ -55,8 +55,6 @@ public abstract class IdFactory
|
||||
"SELECT charId FROM character_skills WHERE charId >= ? AND charId < ?",
|
||||
"SELECT charId FROM character_skills_save WHERE charId >= ? AND charId < ?",
|
||||
"SELECT charId FROM character_subclasses WHERE charId >= ? AND charId < ?",
|
||||
"SELECT charId FROM character_ui_actions WHERE charId >= ? AND charId < ?",
|
||||
"SELECT charId FROM character_ui_categories WHERE charId >= ? AND charId < ?",
|
||||
"SELECT charId FROM characters WHERE charId >= ? AND charId < ?",
|
||||
"SELECT clanid FROM characters WHERE clanid >= ? AND clanid < ?",
|
||||
"SELECT clan_id FROM clan_data WHERE clan_id >= ? AND clan_id < ?",
|
||||
@@ -192,8 +190,6 @@ public abstract class IdFactory
|
||||
cleanCount += stmt.executeUpdate("DELETE FROM character_skills_save WHERE character_skills_save.charId NOT IN (SELECT charId FROM characters);");
|
||||
cleanCount += stmt.executeUpdate("DELETE FROM character_subclasses WHERE character_subclasses.charId NOT IN (SELECT charId FROM characters);");
|
||||
cleanCount += stmt.executeUpdate("DELETE FROM character_instance_time WHERE character_instance_time.charId NOT IN (SELECT charId FROM characters);");
|
||||
cleanCount += stmt.executeUpdate("DELETE FROM character_ui_actions WHERE character_ui_actions.charId NOT IN (SELECT charId FROM characters);");
|
||||
cleanCount += stmt.executeUpdate("DELETE FROM character_ui_categories WHERE character_ui_categories.charId NOT IN (SELECT charId FROM characters);");
|
||||
|
||||
// Items
|
||||
cleanCount += stmt.executeUpdate("DELETE FROM items WHERE items.owner_id NOT IN (SELECT charId FROM characters) AND items.owner_id NOT IN (SELECT clan_id FROM clan_data) AND items.owner_id != -1;");
|
||||
|
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.UIData;
|
||||
|
||||
/**
|
||||
* UI Keys Settings class.
|
||||
* @author mrTJO, Zoey76
|
||||
*/
|
||||
public class UIKeysSettings
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(UIKeysSettings.class.getName());
|
||||
|
||||
private final int _playerObjId;
|
||||
private Map<Integer, List<ActionKey>> _storedKeys;
|
||||
private Map<Integer, List<Integer>> _storedCategories;
|
||||
private boolean _saved = true;
|
||||
|
||||
public UIKeysSettings(int playerObjId)
|
||||
{
|
||||
_playerObjId = playerObjId;
|
||||
loadFromDB();
|
||||
}
|
||||
|
||||
public void storeAll(Map<Integer, List<Integer>> catMap, Map<Integer, List<ActionKey>> keyMap)
|
||||
{
|
||||
_saved = false;
|
||||
_storedCategories = catMap;
|
||||
_storedKeys = keyMap;
|
||||
}
|
||||
|
||||
public void storeCategories(Map<Integer, List<Integer>> catMap)
|
||||
{
|
||||
_saved = false;
|
||||
_storedCategories = catMap;
|
||||
}
|
||||
|
||||
public Map<Integer, List<Integer>> getCategories()
|
||||
{
|
||||
return _storedCategories;
|
||||
}
|
||||
|
||||
public void storeKeys(Map<Integer, List<ActionKey>> keyMap)
|
||||
{
|
||||
_saved = false;
|
||||
_storedKeys = keyMap;
|
||||
}
|
||||
|
||||
public Map<Integer, List<ActionKey>> getKeys()
|
||||
{
|
||||
return _storedKeys;
|
||||
}
|
||||
|
||||
public void loadFromDB()
|
||||
{
|
||||
getCatsFromDB();
|
||||
getKeysFromDB();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Categories and Mapped Keys into GameServer DataBase
|
||||
*/
|
||||
public void saveInDB()
|
||||
{
|
||||
String query;
|
||||
if (_saved)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
query = "REPLACE INTO character_ui_categories (`charId`, `catId`, `order`, `cmdId`) VALUES ";
|
||||
for (int category : _storedCategories.keySet())
|
||||
{
|
||||
int order = 0;
|
||||
for (int key : _storedCategories.get(category))
|
||||
{
|
||||
query += "(" + _playerObjId + ", " + category + ", " + (order++) + ", " + key + "),";
|
||||
}
|
||||
}
|
||||
query = query.substring(0, query.length() - 1) + "; ";
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(query))
|
||||
{
|
||||
statement.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Exception: saveInDB(): " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
query = "REPLACE INTO character_ui_actions (`charId`, `cat`, `order`, `cmd`, `key`, `tgKey1`, `tgKey2`, `show`) VALUES";
|
||||
for (List<ActionKey> keyLst : _storedKeys.values())
|
||||
{
|
||||
int order = 0;
|
||||
for (ActionKey key : keyLst)
|
||||
{
|
||||
query += key.getSqlSaveString(_playerObjId, order++) + ",";
|
||||
}
|
||||
}
|
||||
query = query.substring(0, query.length() - 1) + ";";
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(query))
|
||||
{
|
||||
statement.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Exception: saveInDB(): " + e.getMessage(), e);
|
||||
}
|
||||
_saved = true;
|
||||
}
|
||||
|
||||
public void getCatsFromDB()
|
||||
{
|
||||
if (_storedCategories != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_storedCategories = new HashMap<>();
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement stmt = con.prepareStatement("SELECT * FROM character_ui_categories WHERE `charId` = ? ORDER BY `catId`, `order`"))
|
||||
{
|
||||
stmt.setInt(1, _playerObjId);
|
||||
try (ResultSet rs = stmt.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
UIData.addCategory(_storedCategories, rs.getInt("catId"), rs.getInt("cmdId"));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Exception: getCatsFromDB(): " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (_storedCategories.isEmpty())
|
||||
{
|
||||
_storedCategories = UIData.getInstance().getCategories();
|
||||
}
|
||||
}
|
||||
|
||||
public void getKeysFromDB()
|
||||
{
|
||||
if (_storedKeys != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_storedKeys = new HashMap<>();
|
||||
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement stmt = con.prepareStatement("SELECT * FROM character_ui_actions WHERE `charId` = ? ORDER BY `cat`, `order`"))
|
||||
{
|
||||
stmt.setInt(1, _playerObjId);
|
||||
try (ResultSet rs = stmt.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int cat = rs.getInt("cat");
|
||||
final int cmd = rs.getInt("cmd");
|
||||
final int key = rs.getInt("key");
|
||||
final int tgKey1 = rs.getInt("tgKey1");
|
||||
final int tgKey2 = rs.getInt("tgKey2");
|
||||
final int show = rs.getInt("show");
|
||||
UIData.addKey(_storedKeys, cat, new ActionKey(cat, cmd, key, tgKey1, tgKey2, show));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Exception: getKeysFromDB(): " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (_storedKeys.isEmpty())
|
||||
{
|
||||
_storedKeys = UIData.getInstance().getKeys();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSaved()
|
||||
{
|
||||
return _saved;
|
||||
}
|
||||
}
|
@@ -148,7 +148,6 @@ import com.l2jmobius.gameserver.model.TeleportBookmark;
|
||||
import com.l2jmobius.gameserver.model.TeleportWhereType;
|
||||
import com.l2jmobius.gameserver.model.TimeStamp;
|
||||
import com.l2jmobius.gameserver.model.TradeList;
|
||||
import com.l2jmobius.gameserver.model.UIKeysSettings;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Attackable;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
@@ -845,9 +844,6 @@ public final class L2PcInstance extends L2Playable
|
||||
_PvPRegTask = null;
|
||||
}
|
||||
|
||||
// Character UI
|
||||
private UIKeysSettings _uiKeySettings;
|
||||
|
||||
// Save responder name for log it
|
||||
private String _lastPetitionGmName = null;
|
||||
|
||||
@@ -6811,11 +6807,6 @@ public final class L2PcInstance extends L2Playable
|
||||
|
||||
player.restoreFriendList();
|
||||
|
||||
if (Config.STORE_UI_SETTINGS)
|
||||
{
|
||||
player.restoreUISettings();
|
||||
}
|
||||
|
||||
player.loadRecommendations();
|
||||
player.startRecoGiveTask();
|
||||
player.startOnlineTimeUpdateTask();
|
||||
@@ -7093,10 +7084,6 @@ public final class L2PcInstance extends L2Playable
|
||||
{
|
||||
storeRecipeShopList();
|
||||
}
|
||||
if (Config.STORE_UI_SETTINGS)
|
||||
{
|
||||
storeUISettings();
|
||||
}
|
||||
|
||||
final PlayerVariables vars = getScript(PlayerVariables.class);
|
||||
if (vars != null)
|
||||
@@ -12683,29 +12670,6 @@ public final class L2PcInstance extends L2Playable
|
||||
return super.isMovementDisabled() || (getMovieHolder() != null) || _fishing.isFishing();
|
||||
}
|
||||
|
||||
private void restoreUISettings()
|
||||
{
|
||||
_uiKeySettings = new UIKeysSettings(getObjectId());
|
||||
}
|
||||
|
||||
private void storeUISettings()
|
||||
{
|
||||
if (_uiKeySettings == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_uiKeySettings.isSaved())
|
||||
{
|
||||
_uiKeySettings.saveInDB();
|
||||
}
|
||||
}
|
||||
|
||||
public UIKeysSettings getUISettings()
|
||||
{
|
||||
return _uiKeySettings;
|
||||
}
|
||||
|
||||
public String getHtmlPrefix()
|
||||
{
|
||||
if (!Config.MULTILANG_ENABLE)
|
||||
|
@@ -16,64 +16,30 @@
|
||||
*/
|
||||
package com.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.network.PacketReader;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.UIData;
|
||||
import com.l2jmobius.gameserver.model.ActionKey;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.ConnectionState;
|
||||
import com.l2jmobius.gameserver.network.L2GameClient;
|
||||
|
||||
/**
|
||||
* Request Save Key Mapping client packet.
|
||||
* @author mrTJO, Zoey76
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RequestSaveKeyMapping implements IClientIncomingPacket
|
||||
{
|
||||
private final Map<Integer, List<ActionKey>> _keyMap = new HashMap<>();
|
||||
private final Map<Integer, List<Integer>> _catMap = new HashMap<>();
|
||||
public static final String UI_KEY_MAPPING_VAR = "UI_KEY_MAPPING";
|
||||
public static final String SPLIT_VAR = " ";
|
||||
private byte[] _uiKeyMapping;
|
||||
|
||||
@Override
|
||||
public boolean read(L2GameClient client, PacketReader packet)
|
||||
{
|
||||
int category = 0;
|
||||
|
||||
packet.readD(); // Unknown
|
||||
packet.readD(); // Unknown
|
||||
final int _tabNum = packet.readD();
|
||||
for (int i = 0; i < _tabNum; i++)
|
||||
final int dataSize = packet.readD();
|
||||
if (dataSize > 0)
|
||||
{
|
||||
final int cmd1Size = packet.readC();
|
||||
for (int j = 0; j < cmd1Size; j++)
|
||||
{
|
||||
UIData.addCategory(_catMap, category, packet.readC());
|
||||
}
|
||||
category++;
|
||||
|
||||
final int cmd2Size = packet.readC();
|
||||
for (int j = 0; j < cmd2Size; j++)
|
||||
{
|
||||
UIData.addCategory(_catMap, category, packet.readC());
|
||||
}
|
||||
category++;
|
||||
|
||||
final int cmdSize = packet.readD();
|
||||
for (int j = 0; j < cmdSize; j++)
|
||||
{
|
||||
final int cmd = packet.readD();
|
||||
final int key = packet.readD();
|
||||
final int tgKey1 = packet.readD();
|
||||
final int tgKey2 = packet.readD();
|
||||
final int show = packet.readD();
|
||||
UIData.addKey(_keyMap, i, new ActionKey(i, cmd, key, tgKey1, tgKey2, show));
|
||||
}
|
||||
_uiKeyMapping = packet.readB(dataSize);
|
||||
}
|
||||
packet.readD();
|
||||
packet.readD();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,10 +47,19 @@ public class RequestSaveKeyMapping implements IClientIncomingPacket
|
||||
public void run(L2GameClient client)
|
||||
{
|
||||
final L2PcInstance player = client.getActiveChar();
|
||||
if (!Config.STORE_UI_SETTINGS || (player == null) || (client.getConnectionState() != ConnectionState.IN_GAME))
|
||||
if (!Config.STORE_UI_SETTINGS || //
|
||||
(player == null) || //
|
||||
(_uiKeyMapping == null) || //
|
||||
(client.getConnectionState() != ConnectionState.IN_GAME))
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.getUISettings().storeAll(_catMap, _keyMap);
|
||||
|
||||
String uiKeyMapping = "";
|
||||
for (Byte b : _uiKeyMapping)
|
||||
{
|
||||
uiKeyMapping += b + SPLIT_VAR;
|
||||
}
|
||||
player.getVariables().set(UI_KEY_MAPPING_VAR, uiKeyMapping);
|
||||
}
|
||||
}
|
||||
|
@@ -16,124 +16,44 @@
|
||||
*/
|
||||
package com.l2jmobius.gameserver.network.serverpackets;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jmobius.commons.network.PacketWriter;
|
||||
import com.l2jmobius.gameserver.model.ActionKey;
|
||||
import com.l2jmobius.gameserver.model.UIKeysSettings;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.OutgoingPackets;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ExUISetting implements IClientOutgoingPacket
|
||||
{
|
||||
private final UIKeysSettings _uiSettings;
|
||||
private int buffsize, categories;
|
||||
public static final String UI_KEY_MAPPING_VAR = "UI_KEY_MAPPING";
|
||||
public static final String SPLIT_VAR = " ";
|
||||
private final byte[] _uiKeyMapping;
|
||||
|
||||
public ExUISetting(L2PcInstance player)
|
||||
{
|
||||
_uiSettings = player.getUISettings();
|
||||
calcSize();
|
||||
}
|
||||
|
||||
private void calcSize()
|
||||
{
|
||||
int size = 16; // initial header and footer
|
||||
int category = 0;
|
||||
final int numKeyCt = _uiSettings.getKeys().size();
|
||||
for (int i = 0; i < numKeyCt; i++)
|
||||
if (player.getVariables().hasVariable(UI_KEY_MAPPING_VAR))
|
||||
{
|
||||
size++;
|
||||
if (_uiSettings.getCategories().containsKey(category))
|
||||
{
|
||||
final List<Integer> catElList1 = _uiSettings.getCategories().get(category);
|
||||
size = size + catElList1.size();
|
||||
}
|
||||
category++;
|
||||
size++;
|
||||
if (_uiSettings.getCategories().containsKey(category))
|
||||
{
|
||||
final List<Integer> catElList2 = _uiSettings.getCategories().get(category);
|
||||
size = size + catElList2.size();
|
||||
}
|
||||
category++;
|
||||
size = size + 4;
|
||||
if (_uiSettings.getKeys().containsKey(i))
|
||||
{
|
||||
final List<ActionKey> keyElList = _uiSettings.getKeys().get(i);
|
||||
size = size + (keyElList.size() * 20);
|
||||
}
|
||||
_uiKeyMapping = player.getVariables().getByteArray(UI_KEY_MAPPING_VAR, SPLIT_VAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
_uiKeyMapping = null;
|
||||
}
|
||||
buffsize = size;
|
||||
categories = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.EX_UI_SETTING.writeId(packet);
|
||||
|
||||
packet.writeD(buffsize);
|
||||
packet.writeD(categories);
|
||||
|
||||
int category = 0;
|
||||
|
||||
final int numKeyCt = _uiSettings.getKeys().size();
|
||||
packet.writeD(numKeyCt);
|
||||
for (int i = 0; i < numKeyCt; i++)
|
||||
if (_uiKeyMapping != null)
|
||||
{
|
||||
if (_uiSettings.getCategories().containsKey(category))
|
||||
{
|
||||
final List<Integer> catElList1 = _uiSettings.getCategories().get(category);
|
||||
packet.writeC(catElList1.size());
|
||||
for (int cmd : catElList1)
|
||||
{
|
||||
packet.writeC(cmd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.writeC(0x00);
|
||||
}
|
||||
category++;
|
||||
|
||||
if (_uiSettings.getCategories().containsKey(category))
|
||||
{
|
||||
final List<Integer> catElList2 = _uiSettings.getCategories().get(category);
|
||||
packet.writeC(catElList2.size());
|
||||
for (int cmd : catElList2)
|
||||
{
|
||||
packet.writeC(cmd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.writeC(0x00);
|
||||
}
|
||||
category++;
|
||||
|
||||
if (_uiSettings.getKeys().containsKey(i))
|
||||
{
|
||||
final List<ActionKey> keyElList = _uiSettings.getKeys().get(i);
|
||||
packet.writeD(keyElList.size());
|
||||
for (ActionKey akey : keyElList)
|
||||
{
|
||||
packet.writeD(akey.getCommandId());
|
||||
packet.writeD(akey.getKeyId());
|
||||
packet.writeD(akey.getToogleKey1());
|
||||
packet.writeD(akey.getToogleKey2());
|
||||
packet.writeD(akey.getShowStatus());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.writeD(0x00);
|
||||
}
|
||||
packet.writeD(_uiKeyMapping.length);
|
||||
packet.writeB(_uiKeyMapping);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.writeD(0);
|
||||
}
|
||||
packet.writeD(0x11);
|
||||
packet.writeD(0x10);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user