some buttons are invoked via key press

This commit is contained in:
devZoGok
2021-11-02 09:17:45 +02:00
parent 87664309ea
commit fd03442393
5 changed files with 34 additions and 36 deletions
+5 -4
View File
@@ -4,6 +4,7 @@
#include "key.h"
#include <vector>
#include <util.h>
namespace battleship{
enum class AppStateTypes {GUI_STATE,IN_GAME_STATE,ACTIVE_STATE};
@@ -22,10 +23,10 @@ namespace battleship{
virtual void update(){}
virtual void onAction(Mapping::Bind, bool){}
virtual void onAnalog(Mapping::Bind, double){}
/*
virtual void onRawKeyPress(irr::SEvent::SKeyInput){}
virtual void onRawMousePress(irr::SEvent::SMouseInput){}
*/
virtual void onRawKeyPress(vb01::u8){}
virtual void onRawMousePress(vb01::u8){}
virtual void onRawJoystickAxis(vb01::u8, float){}
virtual void onRawJoystickKeyPress(vb01::u8){}
private:
bool attached = false;
std::vector<Mapping*> attachedKeys;
+10 -14
View File
@@ -97,28 +97,24 @@ namespace battleship{
}
}
/*
for(int i=0;i<350;i++){
if(glfwGetKey(window,i))
a->onRawKeyButton(i);
else if(glfwGetMouseButton(window,i))
a->onRawMouseButton(i);
for(int i = 0; i < 350; i++){
if(glfwGetKey(window, i))
a->onRawKeyPress(i);
else if(glfwGetMouseButton(window, i))
a->onRawMousePress(i);
}
*/
glfwSetCursorPosCallback(window,foo);
/*
if(glfwJoystickPresent(GLFW_JOYSTICK_1)){
for(int i=0;i<numAxis;i++)
if(abs(axis[i])==1)
a->onRawJoystickAxis(i,axis[i]);
for(int i = 0; i < numAxis; i++)
if(abs(axis[i]) == 1)
a->onRawJoystickAxis(i, axis[i]);
for(int i=0;i<numButtons;i++)
for(int i = 0; i < numButtons; i++)
if(buttons[i])
a->onRawJoystickButton(i);
a->onRawJoystickKeyPress(i);
}
*/
}
}
}
+12 -10
View File
@@ -205,20 +205,22 @@ namespace battleship{
}
}
/*
void GuiAppState::onRawKeyPress(SEvent::SKeyInput event){
updateControlsListbox(event.Key);
void GuiAppState::onRawKeyPress(u8 trigger){
Button *button = nullptr;
for(Button *b : buttons)
if(b->getTrigger() == trigger){
button = b;
break;
}
if(button)
button->onClick();
}
void GuiAppState::onRawMousePress(SEvent::SMouseInput event){
int trigger=0;
if(event.isMiddlePressed())
trigger=1;
else if(event.isRightPressed())
trigger=2;
void GuiAppState::onRawMousePress(u8 trigger){
updateControlsListbox(trigger);
}
*/
Textbox* GuiAppState::getOpenTextbox() {
Textbox* t = nullptr;
+2 -4
View File
@@ -45,10 +45,8 @@ namespace battleship{
private:
virtual void onAction(Mapping::Bind, bool);
virtual void onAnalog(Mapping::Bind, double);
/*
virtual void onRawKeyPress(irr::SEvent::SKeyInput);
virtual void onRawMousePress(irr::SEvent::SMouseInput);
*/
virtual void onRawKeyPress(vb01::u8);
virtual void onRawMousePress(vb01::u8);
vb01Gui::Textbox* getOpenTextbox();
vb01Gui::Listbox* getOpenListbox();
void attachBindKeys();
+5 -4
View File
@@ -18,7 +18,7 @@ namespace battleship{
class SpButton : public Button {
public:
SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) {
SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_S, separate) {
this->state = state;
}
@@ -35,7 +35,7 @@ namespace battleship{
class PlayButton : public Button {
public:
PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) {
PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_P, separate) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
this->lengths[0]=lengths[0];
this->lengths[1]=lengths[1];
@@ -74,7 +74,7 @@ namespace battleship{
class ReturnButton : public Button {
public:
ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) {
ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_B, separate) {
this->state = state;
}
@@ -93,7 +93,6 @@ namespace battleship{
};
GameManager *gm = GameManager::getSingleton();
//IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
Vector2 pos(gm->getWidth() / 8, gm->getHeight() / 8);
difficulties.push_back("Easy");
difficulties.push_back("Medium");
@@ -112,9 +111,11 @@ namespace battleship{
Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font);
Listbox **difficultyListboxes=new Listbox*[1];
Listbox **factionListboxes=new Listbox*[2];
difficultyListboxes[0]=cpuDifficulty;
factionListboxes[0]=playerFaction;
factionListboxes[1]=cpuFaction;
int lengths[]{1,2};
PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true);
ReturnButton *returnButton = new ReturnButton(state, Vector2(200, gm->getHeight() - 150), Vector2(140, 50), "Back", true);