toolbar scrolling
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-09-30 16:00:58 -04:00
parent cfcaa23a3d
commit e0e90cdd1e
13 changed files with 148 additions and 38 deletions

View File

@ -856,6 +856,7 @@ Filter toolbar slots out of equip menu
(09/30/2024)
Fix attack tree checks
Disable client equip tests until can review
Toolbar scrolling
# TODO

View File

@ -112,6 +112,13 @@
"entityId"
]
},
{
"messageName" : "clientUpdateToolbar",
"description" : "Updates the server on the selected toolbar option",
"data" : [
"toolbarId"
]
},
{
"messageName" : "clientRequestPerformItemAction",
"description" : "Requests that the server have the entity perform its equipped item's action for the given equip point",

View File

@ -90,9 +90,8 @@ import electrosphere.engine.Main;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.entity.Entity;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.attack.ClientAttackTree;
import electrosphere.entity.state.attack.ShooterTree;
import electrosphere.entity.state.equip.ClientEquipState;
import electrosphere.entity.state.equip.ClientToolbarState;
import electrosphere.entity.state.inventory.InventoryUtils;
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree;
@ -140,6 +139,7 @@ public class ControlHandler {
public static final String ITEM_SECONDARY = "actionItemSecondary";
public static final String INPUT_CODE_PLACE_TERRAIN = "placeTerrain";
public static final String INPUT_CODE_REMOVE_TERRAIN = "removeTerrain";
public static final String TOOLBAR_SCROLL = "toolbarScroll";
//menu navigation
@ -327,6 +327,7 @@ public class ControlHandler {
handler.addControl(INPUT_CODE_DROP, new Control(ControlType.KEY,GLFW_KEY_Y,false,"Drop","Drops the currently equipped item"));
handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(ControlType.KEY,GLFW.GLFW_KEY_TAB,false,"Inventory","Opens the player's inventory"));
handler.addControl(ITEM_SECONDARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_RIGHT,false,"Secondary","Uses the secondary equipped item"));
handler.addControl(TOOLBAR_SCROLL, new Control(ControlType.MOUSE_SCROLL,0,false,"",""));
/*
Map the menu navigation controls
@ -883,6 +884,21 @@ public class ControlHandler {
controls.get(ITEM_SECONDARY).setOnRelease(new ControlMethod() {public void execute() {
ItemActions.releaseSecondaryItemAction();
}});
/**
* Toolbar scrolling
*/
mainGameControlList.add(controls.get(TOOLBAR_SCROLL));
controls.get(TOOLBAR_SCROLL).setOnScroll(new Control.ScrollCallback() {public void execute(ScrollEvent scrollEvent){
if(Globals.playerEntity != null && ClientToolbarState.getClientToolbarState(Globals.playerEntity) != null){
ClientToolbarState clientToolbarState = ClientToolbarState.getClientToolbarState(Globals.playerEntity);
if(scrollEvent.getScrollAmount() > 0){
clientToolbarState.attemptChangeSelection(clientToolbarState.getSelectedSlot() + 1);
} else {
clientToolbarState.attemptChangeSelection(clientToolbarState.getSelectedSlot() - 1);
}
}
}});
/*
Interact

View File

@ -405,7 +405,7 @@ public class ClientAttackTree implements BehaviorTree {
if(ClientToolbarState.getClientToolbarState(parent) != null){
ClientToolbarState clientToolbarState = ClientToolbarState.getClientToolbarState(parent);
Entity item = clientToolbarState.getCurrentPrimaryItem();
if(ItemUtils.isWeapon(item)){
if(item != null && ItemUtils.isWeapon(item)){
currentWeapon = item;
switch(ItemUtils.getWeaponClass(item)){
case "sword1h":

View File

@ -38,6 +38,11 @@ import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree;
*/
@SynchronizedBehaviorTree(name = "clientToolbarState", isServer = false, correspondingTree="serverToolbarState")
public class ClientToolbarState implements BehaviorTree {
/**
* The maximum number of toolbar slots
*/
public static final int MAX_TOOLBAR_SIZE = 10;
/**
* The selected toolbar slot
@ -237,6 +242,18 @@ public class ClientToolbarState implements BehaviorTree {
public Entity getCurrentPrimaryItem(){
return this.equippedEntity;
}
/**
* Attempts to change the selection to a new value
* @param value The value
*/
public void attemptChangeSelection(int value){
while(value < 0){
value = value + MAX_TOOLBAR_SIZE;
}
value = value % MAX_TOOLBAR_SIZE;
Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientUpdateToolbarMessage(value));
}
/**

View File

@ -295,6 +295,20 @@ public class ServerToolbarState implements BehaviorTree {
return realWorldItem;
}
/**
* Attempts to change the selection to a new value
* @param value The value
*/
public void attemptChangeSelection(int value){
while(value < 0){
value = value + ClientToolbarState.MAX_TOOLBAR_SIZE;
}
value = value % ClientToolbarState.MAX_TOOLBAR_SIZE;
this.removeVisuals();
this.setSelectedSlot(value);
this.visuallyEquipCurrentSlot();
}
/**
* <p> (initially) Automatically generated </p>
* <p>

View File

@ -9,6 +9,7 @@ import electrosphere.entity.Entity;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.equip.ClientEquipState;
import electrosphere.entity.state.equip.ClientToolbarState;
import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.net.parser.net.message.InventoryMessage;
import electrosphere.net.server.protocol.InventoryProtocol;
@ -143,12 +144,45 @@ public class ClientInventoryState implements BehaviorTree {
} break;
}
} break;
case SERVERCOMMANDEQUIPITEM: {
//translate equipper id
Entity equipper = Globals.clientSceneWrapper.getEntityFromServerId(message.getequipperId());
//spawn in world id
Entity inWorldEntity = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityId());
if(inWorldEntity != null){
//translate id
Globals.clientSceneWrapper.mapIdToId(inWorldEntity.getId(), message.getentityId());
switch(message.getcontainerType()){
case electrosphere.net.server.protocol.InventoryProtocol.INVENTORY_TYPE_NATURAL: {
throw new UnsupportedOperationException("unsupported!");
}
case electrosphere.net.server.protocol.InventoryProtocol.INVENTORY_TYPE_EQUIP: {
//grab equip state
ClientEquipState equipState = ClientEquipState.getEquipState(equipper);
//create entity from template in message
//get equippoint
String equipPointName = message.getequipPointId();
EquipPoint equipPoint = equipState.getEquipPoint(equipPointName);
//attach
equipState.attemptEquip(inWorldEntity, equipPoint);
}
case electrosphere.net.server.protocol.InventoryProtocol.INVENTORY_TYPE_TOOLBAR: {
//grab toolbar state
ClientToolbarState toolbarState = ClientToolbarState.getClientToolbarState(equipper);
//attach
toolbarState.attemptEquip(inWorldEntity);
}
}
} else {
throw new UnsupportedOperationException("todo");
}
} break;
case CLIENTUPDATETOOLBAR:
case CLIENTREQUESTADDNATURAL:
case CLIENTREQUESTADDTOOLBAR:
case CLIENTREQUESTEQUIPITEM:
case CLIENTREQUESTUNEQUIPITEM:
case CLIENTREQUESTPERFORMITEMACTION:
case SERVERCOMMANDEQUIPITEM:
break;
}
}

View File

@ -72,6 +72,10 @@ public class ServerInventoryState implements BehaviorTree {
ServerToolbarState serverToolbarState = ServerToolbarState.getServerToolbarState(parent);
serverToolbarState.attemptEquip(itemEnt, message.gettoolbarId());
} break;
case CLIENTUPDATETOOLBAR: {
ServerToolbarState serverToolbarState = ServerToolbarState.getServerToolbarState(parent);
serverToolbarState.attemptChangeSelection(message.gettoolbarId());
} break;
case CLIENTREQUESTPERFORMITEMACTION:
case SERVERCOMMANDUNEQUIPITEM:
case SERVERCOMMANDEQUIPITEM:

View File

@ -1,12 +1,8 @@
package electrosphere.net.client.protocol;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.state.equip.ClientEquipState;
import electrosphere.entity.state.equip.ClientToolbarState;
import electrosphere.entity.state.inventory.ClientInventoryState;
import electrosphere.entity.state.inventory.InventoryUtils;
import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.parser.net.message.InventoryMessage;
import electrosphere.net.template.ClientProtocolTemplate;
@ -35,36 +31,11 @@ public class InventoryProtocol implements ClientProtocolTemplate<InventoryMessag
break;
case SERVERCOMMANDEQUIPITEM: {
LoggerInterface.loggerNetworking.DEBUG("[CLIENT] EQUIP ITEM " + message.getentityId());
//translate equipper id
Entity equipper = Globals.clientSceneWrapper.getEntityFromServerId(message.getequipperId());
//spawn in world id
Entity inWorldEntity = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityId());
if(inWorldEntity != null){
//translate id
Globals.clientSceneWrapper.mapIdToId(inWorldEntity.getId(), message.getentityId());
switch(message.getcontainerType()){
case electrosphere.net.server.protocol.InventoryProtocol.INVENTORY_TYPE_NATURAL: {
throw new UnsupportedOperationException("unsupported!");
}
case electrosphere.net.server.protocol.InventoryProtocol.INVENTORY_TYPE_EQUIP: {
//grab equip state
ClientEquipState equipState = ClientEquipState.getEquipState(equipper);
//create entity from template in message
//get equippoint
String equipPointName = message.getequipPointId();
EquipPoint equipPoint = equipState.getEquipPoint(equipPointName);
//attach
equipState.attemptEquip(inWorldEntity, equipPoint);
}
case electrosphere.net.server.protocol.InventoryProtocol.INVENTORY_TYPE_TOOLBAR: {
//grab toolbar state
ClientToolbarState toolbarState = ClientToolbarState.getClientToolbarState(equipper);
//attach
toolbarState.attemptEquip(inWorldEntity);
}
if(Globals.playerEntity != null){
ClientInventoryState inventoryState;
if((inventoryState = InventoryUtils.clientGetInventoryState(Globals.playerEntity))!=null){
inventoryState.addNetworkMessage(message);
}
} else {
throw new UnsupportedOperationException("todo");
}
} break;
case REMOVEITEMFROMINVENTORY:
@ -95,6 +66,7 @@ public class InventoryProtocol implements ClientProtocolTemplate<InventoryMessag
}
}
break;
case CLIENTUPDATETOOLBAR:
case CLIENTREQUESTADDNATURAL:
case CLIENTREQUESTADDTOOLBAR:
case CLIENTREQUESTPERFORMITEMACTION:

View File

@ -17,6 +17,7 @@ public class InventoryMessage extends NetworkMessage {
CLIENTREQUESTUNEQUIPITEM,
CLIENTREQUESTADDTOOLBAR,
CLIENTREQUESTADDNATURAL,
CLIENTUPDATETOOLBAR,
CLIENTREQUESTPERFORMITEMACTION,
}
@ -139,6 +140,12 @@ public class InventoryMessage extends NetworkMessage {
} else {
return false;
}
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTUPDATETOOLBAR:
if(byteBuffer.getRemaining() >= TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTUPDATETOOLBAR_SIZE){
return true;
} else {
return false;
}
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTPERFORMITEMACTION:
return InventoryMessage.canParseclientRequestPerformItemActionMessage(byteBuffer);
}
@ -447,6 +454,20 @@ public class InventoryMessage extends NetworkMessage {
return rVal;
}
public static InventoryMessage parseclientUpdateToolbarMessage(CircularByteBuffer byteBuffer){
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTUPDATETOOLBAR);
stripPacketHeader(byteBuffer);
rVal.settoolbarId(ByteStreamUtils.popIntFromByteQueue(byteBuffer));
return rVal;
}
public static InventoryMessage constructclientUpdateToolbarMessage(int toolbarId){
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTUPDATETOOLBAR);
rVal.settoolbarId(toolbarId);
rVal.serialize();
return rVal;
}
public static boolean canParseclientRequestPerformItemActionMessage(CircularByteBuffer byteBuffer){
int currentStreamLength = byteBuffer.getRemaining();
List<Byte> temporaryByteQueue = new LinkedList<Byte>();
@ -666,6 +687,17 @@ public class InventoryMessage extends NetworkMessage {
rawBytes[2+i] = intValues[i];
}
break;
case CLIENTUPDATETOOLBAR:
rawBytes = new byte[2+4];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
//entity messaage header
rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTUPDATETOOLBAR;
intValues = ByteStreamUtils.serializeIntToBytes(toolbarId);
for(int i = 0; i < 4; i++){
rawBytes[2+i] = intValues[i];
}
break;
case CLIENTREQUESTPERFORMITEMACTION:
rawBytes = new byte[2+4+equipPointId.length()+4+4];
//message header

View File

@ -322,6 +322,11 @@ COMBAT_MESSAGE,
rVal = InventoryMessage.parseclientRequestAddNaturalMessage(byteBuffer);
}
break;
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTUPDATETOOLBAR:
if(InventoryMessage.canParseMessage(byteBuffer,secondByte)){
rVal = InventoryMessage.parseclientUpdateToolbarMessage(byteBuffer);
}
break;
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTPERFORMITEMACTION:
if(InventoryMessage.canParseMessage(byteBuffer,secondByte)){
rVal = InventoryMessage.parseclientRequestPerformItemActionMessage(byteBuffer);

View File

@ -138,13 +138,15 @@ Message categories
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTUNEQUIPITEM = 6;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTADDTOOLBAR = 7;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTADDNATURAL = 8;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTPERFORMITEMACTION = 9;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTUPDATETOOLBAR = 9;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTPERFORMITEMACTION = 10;
/*
Inventory packet sizes
*/
public static final byte INVENTORY_MESSAGE_TYPE_REMOVEITEMFROMINVENTORY_SIZE = 6;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTADDTOOLBAR_SIZE = 10;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTADDNATURAL_SIZE = 6;
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTUPDATETOOLBAR_SIZE = 6;
/*
Synchronization subcategories
*/

View File

@ -74,6 +74,12 @@ public class InventoryProtocol implements ServerProtocolTemplate<InventoryMessag
InventoryUtils.serverGetInventoryState(target).addNetworkMessage(message);
}
} break;
case CLIENTUPDATETOOLBAR: {
target = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId());
if(target != null && InventoryUtils.hasToolbarInventory(target)){
InventoryUtils.serverGetInventoryState(target).addNetworkMessage(message);
}
} break;
case SERVERCOMMANDUNEQUIPITEM:
case SERVERCOMMANDMOVEITEMCONTAINER:
case SERVERCOMMANDEQUIPITEM: