FRONTEND: added PlayerAction class to trigger the tool
parent
15e938e864
commit
5ed2f7a3cb
|
@ -6,6 +6,7 @@ a +move_left
|
|||
s +move_backward
|
||||
d +move_right
|
||||
space +jump
|
||||
x +triggeraction
|
||||
ctrl+q quit
|
||||
wheelup "+zoom_in"
|
||||
wheeldown "+zoom_out"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
set(SRCS
|
||||
ClientEntity.h ClientEntity.cpp
|
||||
ClientEntityId.h
|
||||
PlayerAction.h PlayerAction.cpp
|
||||
PlayerMovement.h PlayerMovement.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include "PlayerAction.h"
|
||||
#include "core/command/Command.h"
|
||||
#include "frontend/ClientEntity.h"
|
||||
|
||||
namespace frontend {
|
||||
|
||||
network::Animation PlayerAction::animation() const {
|
||||
if (_triggerAction.pressed()) {
|
||||
return network::Animation::TOOL;
|
||||
}
|
||||
return network::Animation::IDLE;
|
||||
}
|
||||
|
||||
bool PlayerAction::init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlayerAction::update(const ClientEntityPtr& entity) {
|
||||
entity->setAnimation(animation());
|
||||
}
|
||||
|
||||
void PlayerAction::construct() {
|
||||
core::Command::registerActionButton("triggeraction", _triggerAction);
|
||||
}
|
||||
|
||||
void PlayerAction::shutdown() {
|
||||
core::Command::unregisterActionButton("triggeraction");
|
||||
_triggerAction.handleUp(core::ACTION_BUTTON_ALL_KEYS, 0ul);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/command/ActionButton.h"
|
||||
#include "core/IComponent.h"
|
||||
#include "Shared_generated.h"
|
||||
|
||||
namespace frontend {
|
||||
|
||||
class ClientEntity;
|
||||
typedef std::shared_ptr<ClientEntity> ClientEntityPtr;
|
||||
|
||||
/**
|
||||
* @brief Trigger action component that does the input listening
|
||||
*
|
||||
* @see core::ActionButton
|
||||
*/
|
||||
class PlayerAction : public core::IComponent {
|
||||
private:
|
||||
core::ActionButton _triggerAction;
|
||||
|
||||
network::Animation animation() const;
|
||||
|
||||
public:
|
||||
bool init() override;
|
||||
void update(const ClientEntityPtr& entity);
|
||||
void construct() override;
|
||||
void shutdown() override;
|
||||
};
|
||||
|
||||
}
|
|
@ -47,6 +47,7 @@ core::AppState MapView::onConstruct() {
|
|||
_rotationSpeed = core::Var::getSafe(cfg::ClientMouseRotationSpeed);
|
||||
|
||||
_movement.construct();
|
||||
_action.construct();
|
||||
_camera.construct();
|
||||
|
||||
core::Command::registerCommand("bird", [&] (const core::CmdArgs& args) {
|
||||
|
@ -93,6 +94,11 @@ core::AppState MapView::onInit() {
|
|||
return core::AppState::InitFailure;
|
||||
}
|
||||
|
||||
if (!_action.init()) {
|
||||
Log::error("Failed to init action component");
|
||||
return core::AppState::InitFailure;
|
||||
}
|
||||
|
||||
if (!_stockDataProvider->init(filesystem()->load("stock.lua"))) {
|
||||
Log::error("Failed to init stock data provider: %s", _stockDataProvider->error().c_str());
|
||||
return core::AppState::InitFailure;
|
||||
|
@ -184,6 +190,7 @@ void MapView::beforeUI() {
|
|||
_movement.update(_deltaFrameSeconds, camera.horizontalYaw(), _entity, [&] (const glm::vec3& pos, float maxWalkHeight) {
|
||||
return _worldMgr->findWalkableFloor(pos, maxWalkHeight);
|
||||
});
|
||||
_action.update(_entity);
|
||||
_camera.update(_entity->position(), _deltaFrameMillis, _now);
|
||||
|
||||
if (_updateWorld) {
|
||||
|
@ -315,6 +322,7 @@ core::AppState MapView::onCleanup() {
|
|||
_worldRenderer.shutdown();
|
||||
_axis.shutdown();
|
||||
_movement.shutdown();
|
||||
_action.shutdown();
|
||||
_camera.shutdown();
|
||||
_entity = frontend::ClientEntityPtr();
|
||||
const core::AppState state = Super::onCleanup();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "RenderShaders.h"
|
||||
#include "voxelrender/WorldRenderer.h"
|
||||
#include "frontend/ClientEntity.h"
|
||||
#include "frontend/PlayerAction.h"
|
||||
#include "render/Axis.h"
|
||||
#include "frontend/PlayerMovement.h"
|
||||
#include "voxelrender/PlayerCamera.h"
|
||||
|
@ -35,6 +36,7 @@ protected:
|
|||
core::VarPtr _rotationSpeed;
|
||||
frontend::ClientEntityPtr _entity;
|
||||
frontend::PlayerMovement _movement;
|
||||
frontend::PlayerAction _action;
|
||||
stock::StockDataProviderPtr _stockDataProvider;
|
||||
voxelformat::VolumeCachePtr _volumeCache;
|
||||
voxelrender::PlayerCamera _camera;
|
||||
|
|
Loading…
Reference in New Issue