mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
mouse cursor
This commit is contained in:
@@ -3,6 +3,9 @@ Size = {x = 70, y = 70}
|
||||
sz = 210
|
||||
s = 90
|
||||
resIconBasePath = 'Icons/Resources/'
|
||||
pointerTex = 'pointer.jpg'
|
||||
attackTex = 'attack.jpg'
|
||||
garrisonTex = 'garrison.jpg'
|
||||
|
||||
gui = {
|
||||
{
|
||||
|
||||
+60
-7
@@ -2,6 +2,7 @@
|
||||
#include <quaternion.h>
|
||||
#include <model.h>
|
||||
#include <material.h>
|
||||
#include <texture.h>
|
||||
#include <quad.h>
|
||||
#include <text.h>
|
||||
#include <rayCaster.h>
|
||||
@@ -34,17 +35,14 @@ namespace battleship{
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
ActiveGameState::ActiveGameState(GuiAppState *guiState, int playerId) : AbstractAppState(
|
||||
ActiveGameState::ActiveGameState(GuiAppState *gs, int plId) : AbstractAppState(
|
||||
AppStateType::ACTIVE_STATE,
|
||||
configData::calcSumBinds(AppStateType::ACTIVE_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::ACTIVE_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]){
|
||||
this->guiState = guiState;
|
||||
this->playerId = playerId;
|
||||
mainPlayer = Game::getSingleton()->getPlayer(playerId);
|
||||
depth = 1;
|
||||
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]), guiState(gs), playerId(plId), depth(1){
|
||||
initDragbox();
|
||||
|
||||
mainPlayer = Game::getSingleton()->getPlayer(playerId);
|
||||
}
|
||||
|
||||
ActiveGameState::~ActiveGameState() {
|
||||
@@ -67,6 +65,28 @@ namespace battleship{
|
||||
root->getGuiNode()->attachChild(dragboxNode);
|
||||
}
|
||||
|
||||
void ActiveGameState::initCursor(){
|
||||
string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Cursors/";
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
|
||||
string p1[]{basePath + (string)SOL_LUA_VIEW["pointerTex"]}, p2[]{basePath + (string)SOL_LUA_VIEW["attackTex"]}, p3[]{basePath + (string)SOL_LUA_VIEW["garrisonTex"]};
|
||||
pointerTex = new Texture(p1, 1, false);
|
||||
attackTex = new Texture(p2, 1, false);
|
||||
garrisonTex = new Texture(p3, 1, false);
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
Material *mat = new Material(root->getLibPath() + "gui");
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
mat->addTexUniform("diffuseMap", pointerTex, false);
|
||||
|
||||
Quad *quad = new Quad(Vector3(20, 20, 0), false);
|
||||
quad->setMaterial(mat);
|
||||
|
||||
cursorNode = new Node();
|
||||
cursorNode->attachMesh(quad);
|
||||
root->getGuiNode()->attachChild(cursorNode);
|
||||
}
|
||||
|
||||
void ActiveGameState::removeDragbox(){
|
||||
Root::getSingleton()->getRootNode()->dettachChild(dragboxNode);
|
||||
delete dragboxNode;
|
||||
@@ -75,12 +95,43 @@ namespace battleship{
|
||||
void ActiveGameState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
|
||||
|
||||
if(!cursorNode) initCursor();
|
||||
}
|
||||
|
||||
void ActiveGameState::onDettached() {
|
||||
AbstractAppState::onDettached();
|
||||
}
|
||||
|
||||
void ActiveGameState::updateCursor(){
|
||||
Vector2 cursorPos = getCursorPos();
|
||||
cursorNode->setPosition(Vector3(cursorPos.x, cursorPos.y, .8));
|
||||
|
||||
bool canSelect = canSelectHoveredOnGameObj();
|
||||
bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam());
|
||||
|
||||
if(controlPressed || (gameObjHoveredOn && !ownGameObj && gameObjHoveredOn->getType() == GameObject::Type::UNIT))
|
||||
cursorState = CursorState::ATTACK;
|
||||
else
|
||||
cursorState = CursorState::NORMAL;
|
||||
|
||||
Texture *tex = nullptr;
|
||||
|
||||
switch(cursorState){
|
||||
case CursorState::ATTACK:
|
||||
tex = attackTex;
|
||||
break;
|
||||
case CursorState::GARRISON:
|
||||
tex = garrisonTex;
|
||||
break;
|
||||
default:
|
||||
tex = pointerTex;
|
||||
break;
|
||||
}
|
||||
|
||||
cursorNode->getMesh(0)->getMaterial()->setTexUniform("diffuseMap", tex, false);
|
||||
}
|
||||
|
||||
void ActiveGameState::update() {
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
guiManager->getText("depth")->setText(L"Depth: " + to_wstring(depth));
|
||||
@@ -88,6 +139,8 @@ namespace battleship{
|
||||
guiManager->getText("wealth")->setText(to_wstring(mainPlayer->getResource(ResourceType::WEALTH)));
|
||||
guiManager->getText("research")->setText(to_wstring(mainPlayer->getResource(ResourceType::RESEARCH)));
|
||||
|
||||
updateCursor();
|
||||
|
||||
if(!isSelectionBox && leftMouseClicked && getTime() - lastLeftMouseClicked > 10)
|
||||
isSelectionBox = true;
|
||||
else if (isSelectionBox)
|
||||
|
||||
+14
-1
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace vb01Gui{
|
||||
@@ -31,8 +32,17 @@ namespace battleship{
|
||||
inline Player* getPlayer(){return mainPlayer;}
|
||||
inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];}
|
||||
private:
|
||||
enum CursorState{
|
||||
NORMAL,
|
||||
ATTACK,
|
||||
GARRISON,
|
||||
SUPPLY
|
||||
};
|
||||
|
||||
bool selectedUnitsAmongst(std::vector<Unit*>);
|
||||
void updateGameObjHoveredOn();
|
||||
void initCursor();
|
||||
void updateCursor();
|
||||
void initDragbox();
|
||||
void removeDragbox();
|
||||
void deselectUnits();
|
||||
@@ -45,8 +55,9 @@ namespace battleship{
|
||||
void enableUnitState(Unit::State);
|
||||
inline bool canSelectHoveredOnGameObj(){return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer;}
|
||||
|
||||
GuiAppState *guiState;
|
||||
CursorState cursorState = CursorState::NORMAL;
|
||||
Player *mainPlayer;
|
||||
GuiAppState *guiState;
|
||||
std::string unitGuiScreen = "";
|
||||
GameObject *gameObjHoveredOn = nullptr;
|
||||
vb01::Node *dragboxNode = nullptr;
|
||||
@@ -59,6 +70,8 @@ namespace battleship{
|
||||
const int NUM_MAX_ZOOMS = 10;
|
||||
float depth = 1;
|
||||
vb01::s64 lastLeftMouseClicked = 0;
|
||||
vb01::Node *cursorNode = nullptr;
|
||||
vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user