First step of SDL2 migration.

This commit is contained in:
Quentin Bazin 2020-07-07 19:33:01 +02:00
parent 89f913bb90
commit c9b7990c3c
67 changed files with 244 additions and 247 deletions

3
.gitmodules vendored
View File

@ -16,3 +16,6 @@
[submodule "external/lua"]
path = external/lua
url = https://github.com/Unarelith/lua
[submodule "external/SFML"]
path = external/SFML
url = https://github.com/SFML/SFML

View File

@ -84,6 +84,18 @@ set(BUILD_SHARED_LIBS OFF)
add_subdirectory(external/entt)
include_directories(external/entt/src)
#------------------------------------------------------------------------------
# - SFML
#------------------------------------------------------------------------------
set(SFML_STATIC TRUE)
set(SFML_BUILD_AUDIO FALSE CACHE BOOL "")
set(SFML_BUILD_GRAPHICS FALSE CACHE BOOL "")
set(SFML_BUILD_NETWORK TRUE CACHE BOOL "")
set(SFML_BUILD_WINDOW FALSE CACHE BOOL "")
add_subdirectory(external/SFML)
#------------------------------------------------------------------------------
# - gamekit
#------------------------------------------------------------------------------

1
external/SFML vendored Submodule

@ -0,0 +1 @@
Subproject commit 2f11710abc5aa478503a7ff3f9e654bd2078ebab

2
external/gamekit vendored

@ -1 +1 @@
Subproject commit 1e8b6c860bff1da20880a93c852754a879eed56c
Subproject commit 80e222ce687eef7ce0473b489ded9aceb8a7ac95

View File

@ -106,14 +106,7 @@ void ClientApplication::init() {
m_keyboardHandler.loadKeysFromFile("config/keys.lua");
gk::GamePad::init(m_keyboardHandler);
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 0;
settings.majorVersion = 2;
settings.minorVersion = 1;
createWindow(sf::VideoMode{Config::screenWidth, Config::screenHeight}, APP_NAME, sf::Style::Titlebar | sf::Style::Close, settings);
createWindow(Config::screenWidth, Config::screenHeight, APP_NAME);
m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled);
m_window.setOpenGLFlagsSetupFunc(&ClientApplication::initOpenGL);
m_window.disableView();
@ -132,30 +125,23 @@ void ClientApplication::init() {
void ClientApplication::handleEvents() {
gk::CoreApplication::handleEvents();
if ((Config::isFullscreenModeEnabled && !m_window.isFullscreenModeEnabled())
|| (!Config::isFullscreenModeEnabled && m_window.isFullscreenModeEnabled())) {
m_window.setFullscreenMode(Config::isFullscreenModeEnabled);
// FIXME: Required for Windows
sf::Event event;
event.type = sf::Event::Resized;
event.size.width = m_window.window().getSize().x;
event.size.height = m_window.window().getSize().y;
onEvent(event);
if ((Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Fullscreen)
|| (!Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Windowed)) {
m_window.setWindowMode(Config::isFullscreenModeEnabled ? gk::Window::Mode::Fullscreen : gk::Window::Mode::Windowed);
}
if (Config::screenWidth != m_window.getSize().x || Config::screenHeight != m_window.getSize().y) {
m_window.setSize({Config::screenWidth, Config::screenHeight});
m_window.resize(Config::screenWidth, Config::screenHeight);
}
if (Config::isVerticalSyncEnabled != m_window.isVerticalSyncEnabled())
m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled);
}
void ClientApplication::onEvent(const sf::Event &event) {
void ClientApplication::onEvent(const SDL_Event &event) {
gk::CoreApplication::onEvent(event);
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F11)
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F11)
Config::isFullscreenModeEnabled ^= 1;
}

View File

@ -40,7 +40,7 @@ class ClientApplication : public gk::CoreApplication {
private:
void handleEvents() override;
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void onExit() override;
static void initOpenGL();

View File

@ -35,20 +35,20 @@
#include "KeyboardHandler.hpp"
KeyboardHandler::KeyboardHandler() {
addKey(GameKey::Left, "Left", sf::Keyboard::A);
addKey(GameKey::Right, "Right", sf::Keyboard::D);
addKey(GameKey::Up, "Up", sf::Keyboard::W);
addKey(GameKey::Down, "Down", sf::Keyboard::S);
addKey(GameKey::Left, "Left", SDLK_a);
addKey(GameKey::Right, "Right", SDLK_d);
addKey(GameKey::Up, "Up", SDLK_w);
addKey(GameKey::Down, "Down", SDLK_s);
addKey(GameKey::Jump, "Jump", sf::Keyboard::Space);
addKey(GameKey::Fly, "Fly", sf::Keyboard::X);
addKey(GameKey::Sneak, "Sneak", sf::Keyboard::LShift);
addKey(GameKey::Sprint, "Sprint", sf::Keyboard::LControl);
addKey(GameKey::Jump, "Jump", SDLK_SPACE);
addKey(GameKey::Fly, "Fly", SDLK_x);
addKey(GameKey::Sneak, "Sneak", SDLK_LSHIFT);
addKey(GameKey::Sprint, "Sprint", SDLK_LCTRL);
addKey(GameKey::Chat, "Chat", sf::Keyboard::T);
addKey(GameKey::Command, "Command", sf::Keyboard::Divide);
addKey(GameKey::Chat, "Chat", SDLK_t);
addKey(GameKey::Command, "Command", SDLK_KP_DIVIDE);
addKey(GameKey::Shift, "Shift", sf::Keyboard::LShift);
addKey(GameKey::Shift, "Shift", SDLK_LSHIFT);
}
void KeyboardHandler::loadKeysFromFile(const std::string &filename) {
@ -65,13 +65,13 @@ void KeyboardHandler::loadKeysFromFile(const std::string &filename) {
const std::string &keyName = it.second.as<sol::table>()["name"].get<std::string>();
const std::string &keyValue = it.second.as<sol::table>()["value"].get<std::string>();
sf::Keyboard::Key keycode = gk::KeyboardUtils::getKeyFromName(keyValue);
SDL_Keycode keycode = SDL_GetKeyFromName(keyValue.c_str());
auto keyit = m_keysID.find(keyID);
if (keyit != m_keysID.end()) {
gk::GameKey key = keyit->second;
m_keys[key].setKeycode(keycode);
if (m_keys[key].keycode() == sf::Keyboard::Unknown) {
if (m_keys[key].keycode() == SDLK_UNKNOWN) {
gkWarning() << "Key name '" + keyValue + "' not recognized";
}
}
@ -102,10 +102,15 @@ void KeyboardHandler::saveKeysToFile(const std::string &filename) {
}
bool KeyboardHandler::isKeyPressed(gk::GameKey key) {
return sf::Keyboard::isKeyPressed(m_keys[key].keycode());
const u8 *keyboardState = SDL_GetKeyboardState(nullptr);
SDL_Keycode keyScancode = m_keys[key].keycode();
m_keysPressed[key] = keyboardState[SDL_GetScancodeFromKey(keyScancode)];
return m_keysPressed[key];
}
void KeyboardHandler::addKey(gk::GameKey id, const std::string &name, sf::Keyboard::Key defaultKey, const std::string &stringID, Key *key) {
void KeyboardHandler::addKey(gk::GameKey id, const std::string &name, SDL_Keycode defaultKey, const std::string &stringID, Key *key) {
auto keyit = m_keysID.find(stringID);
if (keyit == m_keysID.end()) {
auto it = m_keys.emplace(id, Key((u16)id, (stringID.empty() ? "_" + name : stringID), name));

View File

@ -31,7 +31,6 @@
#include <string>
#include <gk/core/input/InputHandler.hpp>
#include <gk/core/input/KeyboardUtils.hpp>
#include "Key.hpp"
@ -44,11 +43,11 @@ class KeyboardHandler : public gk::InputHandler {
bool isKeyPressed(gk::GameKey key) override;
sf::Keyboard::Key getKeycode(gk::GameKey key) { return m_keys[key].keycode(); }
std::string getKeyName(gk::GameKey key) { return gk::KeyboardUtils::getNameFromKey(m_keys[key].keycode()); }
void setKeycode(gk::GameKey key, sf::Keyboard::Key keycode) { m_keys[key].setKeycode(keycode); }
SDL_Keycode getKeycode(gk::GameKey key) { return m_keys[key].keycode(); }
std::string getKeyName(gk::GameKey key) { return SDL_GetKeyName(m_keys[key].keycode()); }
void setKeycode(gk::GameKey key, SDL_Keycode keycode) { m_keys[key].setKeycode(keycode); }
void addKey(gk::GameKey id, const std::string &name, sf::Keyboard::Key defaultKey, const std::string &stringID = "", Key *key = nullptr);
void addKey(gk::GameKey id, const std::string &name, SDL_Keycode defaultKey, const std::string &stringID = "", Key *key = nullptr);
u32 keyCount() { return m_keys.size(); }
const std::map<gk::GameKey, Key> &keys() const { return m_keys; }

View File

@ -248,7 +248,7 @@ static constexpr float modelCoords[NUM_QUADS * NUM_VERTICES_PER_QUAD][NUM_VERTEX
PlayerBox::PlayerBox(const gk::Camera &camera)
: m_camera(camera),
m_texture(gk::ResourceHandler::getInstance().get<sf::Texture>("texture-player"))
m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>("texture-player"))
{
updateVertexBuffer();
}

View File

@ -27,12 +27,11 @@
#ifndef PLAYERBOX_HPP_
#define PLAYERBOX_HPP_
#include <SFML/Graphics/Texture.hpp>
#include <gk/gl/Camera.hpp>
#include <gk/gl/Drawable.hpp>
#include <gk/gl/VertexBuffer.hpp>
#include <gk/gl/Texture.hpp>
#include <gk/gl/Transformable.hpp>
#include <gk/gl/VertexBuffer.hpp>
#include "Player.hpp"
@ -53,7 +52,7 @@ class PlayerBox : public gk::Drawable, public gk::Transformable, public Player {
const gk::Camera &m_camera;
sf::Texture &m_texture;
gk::Texture &m_texture;
};
#endif // PLAYERBOX_HPP_

View File

@ -82,7 +82,7 @@ void TextureAtlas::packTextures() {
m_texture.loadFromImage(atlas);
sf::Texture::bind(&m_texture);
gk::Texture::bind(&m_texture);
glGenerateMipmap(GL_TEXTURE_2D);
@ -92,7 +92,7 @@ void TextureAtlas::packTextures() {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
sf::Texture::bind(nullptr);
gk::Texture::bind(nullptr);
}
void TextureAtlas::loadFromRegistry(const std::string &texturePack) {

View File

@ -32,10 +32,11 @@
#include <unordered_map>
#include <vector>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Image.hpp> // FIXME: Make a similar implementation in GameKit
#include <gk/core/IntTypes.hpp>
#include <gk/core/Rect.hpp>
#include <gk/gl/Texture.hpp>
class TextureAtlas {
public:
@ -49,7 +50,7 @@ class TextureAtlas {
u16 getTextureID(const std::string &filename) const;
gk::FloatRect getTexCoords(const std::string &filename, bool normalized = true) const;
const sf::Texture &texture() const { return m_texture; }
const gk::Texture &texture() const { return m_texture; }
bool isReady() const { return m_isReady; }
@ -62,7 +63,7 @@ class TextureAtlas {
std::vector<sf::Image> m_images;
// Packed texture
sf::Texture m_texture;
gk::Texture m_texture;
// Is the texture atlas ready to use?
bool m_isReady = false;

View File

@ -43,7 +43,7 @@ void CraftingWidget::init(unsigned int offset, unsigned int size) {
m_craftingResultInventoryWidget.setShiftDestination(m_shiftDestination);
}
void CraftingWidget::onEvent(const sf::Event &event) {
void CraftingWidget::onEvent(const SDL_Event &event) {
m_craftingInventoryWidget.onEvent(event);
m_craftingResultInventoryWidget.onEvent(event);

View File

@ -37,7 +37,7 @@ class CraftingWidget : public AbstractInventoryWidget {
void init(unsigned int offset = 0, unsigned int size = 3);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -26,14 +26,13 @@
*/
#include <fstream>
#include <SFML/Graphics/Texture.hpp>
#include <gk/gl/Texture.hpp>
#include <gk/resource/ResourceHandler.hpp>
#include "Font.hpp"
Font::Font(const std::string &textureName, const std::string &configPath)
: m_texture(gk::ResourceHandler::getInstance().get<sf::Texture>(textureName))
: m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>(textureName))
{
std::memset(m_charWidth, 0, sizeof(u8) * 256);

View File

@ -31,7 +31,7 @@
#include <gk/core/Vector2.hpp>
namespace sf {
namespace gk {
class Texture;
}
@ -44,12 +44,12 @@ class Font {
u8 getCharWidth(u8 c) const { return m_charWidth[c]; }
gk::Vector2i getTileSize() const { return {m_width, m_height}; }
const sf::Texture &texture() const { return m_texture; }
const gk::Texture &texture() const { return m_texture; }
private:
void parseConfig(const std::string &configPath);
sf::Texture &m_texture;
gk::Texture &m_texture;
u8 m_charWidth[256];
u8 m_width = 8; // FIXME: Hardcoded value

View File

@ -52,11 +52,11 @@ void InventoryWidget::scroll(float scrolling) {
loadItemWidgets(offset, size);
}
void InventoryWidget::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseMoved) {
void InventoryWidget::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEMOTION) {
m_currentItemWidget = nullptr;
for (std::size_t i = 0 ; i < m_itemWidgets.size() ; ++i) {
if (m_itemWidgets[i].isPointInWidget(event.mouseMove.x, event.mouseMove.y)) {
if (m_itemWidgets[i].isPointInWidget(event.motion.x, event.motion.y)) {
m_currentItemWidget = &m_itemWidgets[i];
m_selectedItemBackground.setPosition(1 + (i % m_inventoryWidth) * 18, 1 + (i / m_inventoryWidth) * 18, 0);

View File

@ -43,7 +43,7 @@ class InventoryWidget : public AbstractInventoryWidget {
void scroll(float scrolling);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -43,11 +43,11 @@ void MenuWidget::reset(u16 width, u16 height) {
Widget::m_height = 0;
}
void MenuWidget::onEvent(const sf::Event &event) {
void MenuWidget::onEvent(const SDL_Event &event) {
for (std::size_t i = 0 ; i < m_buttons.size() ; ++i) {
m_buttons.at(i).onEvent(event);
if (event.type == sf::Event::Resized) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
int x = i % m_width;
int y = i / m_width;

View File

@ -38,7 +38,7 @@ class MenuWidget : public Widget {
void reset(u16 width, u16 height);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void onGuiScaleChanged(const GuiScaleChangedEvent &event);

View File

@ -37,35 +37,35 @@ MouseItemWidget::MouseItemWidget(Widget *parent) : ItemWidget(m_inventory, 0, 0,
m_tooltipInfoText.setColor({180, 180, 180});
}
void MouseItemWidget::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseMoved) {
updatePosition(event.mouseMove.x, event.mouseMove.y);
void MouseItemWidget::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEMOTION) {
updatePosition(event.motion.x, event.motion.y);
}
else if (event.type == sf::Event::MouseButtonPressed) {
updatePosition(event.mouseButton.x, event.mouseButton.y);
else if (event.type == SDL_MOUSEBUTTONDOWN) {
updatePosition(event.button.x, event.button.y);
if (getStack().amount() == 0) {
if (event.mouseButton.button == sf::Mouse::Left) {
if (event.button.button == SDL_BUTTON_LEFT) {
leftClickBehaviour();
}
else if (event.mouseButton.button == sf::Mouse::Right) {
else if (event.button.button == SDL_BUTTON_RIGHT) {
rightClickBehaviour();
}
m_isDragging = false;
}
else if (event.mouseButton.button == sf::Mouse::Left || event.mouseButton.button == sf::Mouse::Right) {
startDragging(event.mouseButton.button == sf::Mouse::Left);
else if (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT) {
startDragging(event.button.button == SDL_BUTTON_LEFT);
}
}
else if (event.type == sf::Event::MouseButtonReleased) {
updatePosition(event.mouseButton.x, event.mouseButton.y);
else if (event.type == SDL_MOUSEBUTTONUP) {
updatePosition(event.button.x, event.button.y);
if (m_isDragging && m_draggedSlots.size() <= 1) {
if (event.mouseButton.button == sf::Mouse::Left) {
if (event.button.button == SDL_BUTTON_LEFT) {
leftClickBehaviour();
}
else if (event.mouseButton.button == sf::Mouse::Right) {
else if (event.button.button == SDL_BUTTON_RIGHT) {
rightClickBehaviour();
}
}

View File

@ -38,7 +38,7 @@ class MouseItemWidget : public ItemWidget {
public:
MouseItemWidget(Widget *parent);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void leftClickBehaviour();
void rightClickBehaviour();

View File

@ -26,7 +26,7 @@
*/
#include "ProgressBarWidget.hpp"
ProgressBarWidget::ProgressBarWidget(const sf::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent)
ProgressBarWidget::ProgressBarWidget(const gk::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent)
: Widget(parent), m_blockData(blockData), m_image(texture)
{
m_type = type;

View File

@ -40,7 +40,7 @@ enum class ProgressBarType : u8 {
class ProgressBarWidget : public Widget {
public:
ProgressBarWidget(const sf::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent = nullptr);
ProgressBarWidget(const gk::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent = nullptr);
void init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, unsigned int maxMetaValue);
void init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, const std::string &maxMeta);

View File

@ -29,7 +29,7 @@
#include "Config.hpp"
#include "ScrollBarWidget.hpp"
void ScrollBarWidget::init(const sf::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget) {
void ScrollBarWidget::init(const gk::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget) {
m_clipRect = clipRect;
m_minY = minY;
@ -44,19 +44,19 @@ void ScrollBarWidget::init(const sf::Texture &texture, const gk::FloatRect &clip
m_image.setClipRect(m_clipRect.x, m_clipRect.y, m_clipRect.sizeX, m_clipRect.sizeY);
}
void ScrollBarWidget::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) {
if (isPointInWidget(event.mouseButton.x, event.mouseButton.y)) {
void ScrollBarWidget::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
if (isPointInWidget(event.button.x, event.button.y)) {
m_isDragging = true;
updateScrolling(event.mouseButton.y);
updateScrolling(event.button.y);
}
}
else if (event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left) {
else if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT) {
m_isDragging = false;
}
else if (event.type == sf::Event::MouseMoved && m_isDragging) {
updateScrolling(event.mouseMove.y);
else if (event.type == SDL_MOUSEMOTION && m_isDragging) {
updateScrolling(event.motion.y);
}
}

View File

@ -35,12 +35,12 @@ class ScrollBarWidget : public Widget {
public:
ScrollBarWidget(Widget *parent = nullptr) : Widget(12, 15, parent) {}
void init(const sf::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget);
void init(const gk::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget);
void onEvent(const sf::Event &event);
void onEvent(const SDL_Event &event) override;
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const;
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
void updateScrolling(u16 y);

View File

@ -71,10 +71,10 @@ ScrollableList::ScrollableList() : Widget(ScrollableListElement::widgetWidth, 0)
m_cursor.setSize(m_width, m_height);
}
void ScrollableList::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseButtonPressed) {
void ScrollableList::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEBUTTONDOWN) {
for (auto &it : m_elements) {
if (it.isPointInWidget(event.mouseButton.x, event.mouseButton.y)) {
if (it.isPointInWidget(event.button.x, event.button.y)) {
m_cursor.setSize(it.width() + 2, it.height() + 2);
m_cursor.setPosition(-1, it.getPosition().y - 1);

View File

@ -54,7 +54,7 @@ class ScrollableList : public Widget {
public:
ScrollableList();
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void addElement(const std::string &line1, const std::string &line2, const std::string &line3);

View File

@ -50,17 +50,17 @@ TextButton::TextButton(const CppCallback &callback, Widget *parent) : TextButton
m_cppCallback = callback;
}
void TextButton::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseMoved) {
m_isHovered = isPointInWidget(event.mouseMove.x, event.mouseMove.y);
void TextButton::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEMOTION) {
m_isHovered = isPointInWidget(event.motion.x, event.motion.y);
if (m_isEnabled && m_isHovered)
m_text.setColor(m_hoverColor);
else if (m_isEnabled && !m_isHovered)
m_text.setColor(m_defaultColor);
}
else if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left && m_isHovered && m_isEnabled) {
m_isHovered = isPointInWidget(event.mouseButton.x, event.mouseButton.y);
else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT && m_isHovered && m_isEnabled) {
m_isHovered = isPointInWidget(event.button.x, event.button.y);
if (m_isEnabled && m_isHovered)
m_text.setColor(m_hoverColor);

View File

@ -45,7 +45,7 @@ class TextButton : public Widget {
TextButton(u16 width, Widget *parent = nullptr);
TextButton(const CppCallback &callback, Widget *parent = nullptr);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
const std::string &text() const { return m_text.string(); }
void setText(const std::string &text);

View File

@ -34,8 +34,8 @@ TextInput::TextInput() {
m_placeholder.setColor(gk::Color(150, 150, 150));
}
void TextInput::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseButtonPressed) {
void TextInput::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEBUTTONDOWN) {
gk::FloatRect rect{
getPosition().x,
getPosition().y,
@ -43,10 +43,10 @@ void TextInput::onEvent(const sf::Event &event) {
getBackgroundSize().y * getScale().y
};
m_hasFocus = rect.contains(event.mouseButton.x, event.mouseButton.y);
m_hasFocus = rect.contains(event.button.x, event.button.y);
}
else if (m_hasFocus) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Backspace && !m_content.empty()) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_BACKSPACE && !m_content.empty()) {
m_content.erase(m_content.begin() + m_content.length() - 1);
m_text.setString(m_content);
@ -54,15 +54,17 @@ void TextInput::onEvent(const sf::Event &event) {
m_cursor.setPosition(m_text.getSize().x, 0);
}
if (event.type == sf::Event::TextEntered) {
u32 c = event.text.unicode;
if (isprint(c) && (!m_characterLimit || m_content.size() < m_characterLimit)) {
m_content += c;
}
if (event.type == SDL_TEXTINPUT) {
std::string text = event.text.text;
for (char c : text) {
if (isprint(c) && (!m_characterLimit || m_content.size() < m_characterLimit)) {
m_content += c;
}
m_text.setString(m_content);
m_text.updateVertexBuffer();
m_cursor.setPosition(m_text.getSize().x, 0);
m_text.setString(m_content);
m_text.updateVertexBuffer();
m_cursor.setPosition(m_text.getSize().x, 0);
}
}
}
}

View File

@ -27,7 +27,7 @@
#ifndef TEXTINPUT_HPP_
#define TEXTINPUT_HPP_
#include <SFML/Window/Event.hpp>
#include <gk/core/SDLHeaders.hpp>
#include "Text.hpp"
@ -35,7 +35,7 @@ class TextInput : public gk::Drawable, public gk::Transformable {
public:
TextInput();
void onEvent(const sf::Event &event);
void onEvent(const SDL_Event &event);
const std::string &string() const { return m_content; }
void setString(const std::string &string);

View File

@ -27,9 +27,8 @@
#ifndef WIDGET_HPP_
#define WIDGET_HPP_
#include <SFML/Window/Event.hpp>
#include <gk/core/Rect.hpp>
#include <gk/core/SDLHeaders.hpp>
#include <gk/gl/Drawable.hpp>
#include <gk/gl/Transformable.hpp>
@ -39,7 +38,7 @@ class Widget : public gk::Drawable, public gk::Transformable {
Widget(unsigned int width, unsigned int height, Widget *parent = nullptr)
: m_parent(parent), m_width(width), m_height(height) {}
virtual void onEvent(const sf::Event &) {}
virtual void onEvent(const SDL_Event &) {}
virtual void update() {}
bool isPointInWidget(float x, float y);

View File

@ -44,16 +44,16 @@
BlockCursor::BlockCursor(ClientPlayer &player, ClientWorld &world, ClientCommandHandler &client)
: m_player(player), m_world(world), m_client(client)
{
m_blockDestroyTexture = &gk::ResourceHandler::getInstance().get<sf::Texture>("texture-block_destroy");
m_blockDestroyTexture = &gk::ResourceHandler::getInstance().get<gk::Texture>("texture-block_destroy");
}
void BlockCursor::onEvent(const sf::Event &event, const Hotbar &hotbar) {
if (event.type == sf::Event::MouseButtonPressed && m_selectedBlock.w != -1) {
if (event.mouseButton.button == sf::Mouse::Left) {
void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
if (event.type == SDL_MOUSEBUTTONDOWN && m_selectedBlock.w != -1) {
if (event.button.button == SDL_BUTTON_LEFT) {
m_animationStart = gk::GameClock::getInstance().getTicks();
m_currentTool = &m_player.inventory().getStack(hotbar.cursorPos(), 0);
}
else if (event.mouseButton.button == sf::Mouse::Right) {
else if (event.button.button == SDL_BUTTON_RIGHT) {
if (m_animationStart != 0)
m_animationStart = 0;
@ -124,10 +124,8 @@ void BlockCursor::onEvent(const sf::Event &event, const Hotbar &hotbar) {
}
}
}
else if (event.type == sf::Event::MouseButtonReleased) {
if (event.mouseButton.button == sf::Mouse::Left) {
m_animationStart = 0;
}
else if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT) {
m_animationStart = 0;
}
}

View File

@ -27,7 +27,7 @@
#ifndef BLOCKCURSOR_HPP_
#define BLOCKCURSOR_HPP_
#include <SFML/Window/Event.hpp>
#include <gk/core/SDLHeaders.hpp>
#include "ClientWorld.hpp"
#include "Inventory.hpp"
@ -41,7 +41,7 @@ class BlockCursor : public gk::Drawable {
public:
BlockCursor(ClientPlayer &player, ClientWorld &world, ClientCommandHandler &client);
void onEvent(const sf::Event &event, const Hotbar &hotbar);
void onEvent(const SDL_Event &event, const Hotbar &hotbar);
void update(const Hotbar &hotbar);
@ -69,7 +69,7 @@ class BlockCursor : public gk::Drawable {
const Block *m_currentBlock = nullptr;
const ItemStack *m_currentTool = nullptr;
sf::Texture *m_blockDestroyTexture = nullptr;
gk::Texture *m_blockDestroyTexture = nullptr;
};
#endif // BLOCKCURSOR_HPP_

View File

@ -64,8 +64,8 @@ void HUD::setup() {
m_chat.setPosition(2, Config::screenHeight / Config::guiScale - 50);
}
void HUD::onEvent(const sf::Event &event) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F3)
void HUD::onEvent(const SDL_Event &event) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F3)
m_isDebugOverlayVisible ^= 1;
if (Config::isHotbarVisible)

View File

@ -44,7 +44,7 @@ class HUD : public gk::Transformable, public gk::Drawable {
void setup();
void onEvent(const sf::Event &event);
void onEvent(const SDL_Event &event);
void onGuiScaleChanged(const GuiScaleChangedEvent &event);
void update();

View File

@ -40,13 +40,13 @@ Hotbar::Hotbar(Inventory &inventory, ClientCommandHandler &client, Widget *paren
m_cursor.setPosition(-1, -1, 0);
}
void Hotbar::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseWheelScrolled) {
if (event.mouseWheelScroll.delta < 0) {
void Hotbar::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEWHEEL) {
if (event.wheel.y < 0) {
m_cursorPos = (m_cursorPos + 1) % 9;
m_client.sendPlayerHeldItemChanged(m_cursorPos, currentItem().id());
}
else if (event.mouseWheelScroll.delta > 0) {
else if (event.wheel.y > 0) {
m_cursorPos = (m_cursorPos == 0) ? 8 : m_cursorPos - 1;
m_client.sendPlayerHeldItemChanged(m_cursorPos, currentItem().id());
}

View File

@ -38,7 +38,7 @@ class Hotbar : public Widget {
public:
Hotbar(Inventory &inventory, ClientCommandHandler &client, Widget *parent = nullptr);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -53,12 +53,12 @@ ChatState::ChatState(ClientCommandHandler &clientCommandHandler, Chat &chat, boo
m_chat.setMessageVisibility(true);
}
void ChatState::onEvent(const sf::Event &event) {
void ChatState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
m_textInput.onEvent(event);
if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Escape) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
gk::Mouse::resetToWindowCenter();
@ -69,7 +69,7 @@ void ChatState::onEvent(const sf::Event &event) {
m_stateStack->pop();
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) {
if (!m_textInput.string().empty()) {
m_clientCommandHandler.sendChatMessage(m_textInput.string());
m_chat.addHistoryEntry(m_textInput.string());
@ -85,13 +85,13 @@ void ChatState::onEvent(const sf::Event &event) {
m_stateStack->pop();
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Up && m_currentHistoryEntry < (int)m_chat.historySize() - 1) {
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_UP && m_currentHistoryEntry < (int)m_chat.historySize() - 1) {
if (m_currentHistoryEntry == -1)
m_oldEntry = m_textInput.string();
m_textInput.setString(m_chat.getHistoryEntry(++m_currentHistoryEntry));
}
else if (event.key.code == sf::Keyboard::Down && m_currentHistoryEntry >= 0) {
else if (event.key.keysym.sym == SDLK_DOWN && m_currentHistoryEntry >= 0) {
--m_currentHistoryEntry;
if (m_currentHistoryEntry == -1)
m_textInput.setString(m_oldEntry);

View File

@ -37,7 +37,7 @@ class ChatState : public InterfaceState {
public:
ChatState(ClientCommandHandler &clientCommandHandler, Chat &chat, bool addSlash, gk::ApplicationState *parent = nullptr);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
private:
void updateWidgetPosition() override;

View File

@ -72,7 +72,7 @@ ConnectionErrorState::ConnectionErrorState(const std::string &error, const std::
updateWidgetPosition();
}
void ConnectionErrorState::onEvent(const sf::Event &event) {
void ConnectionErrorState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (!m_stateStack->empty() && &m_stateStack->top() == this) {

View File

@ -34,7 +34,7 @@ class ConnectionErrorState : public InterfaceState {
public:
ConnectionErrorState(const std::string &error, const std::string &host, u16 port, gk::ApplicationState *parent = nullptr);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
private:
void updateWidgetPosition() override;

View File

@ -77,8 +77,8 @@ void GameState::connect(const std::string &host, int port, const std::string &us
gk::Mouse::setCursorGrabbed(true);
}
void GameState::onEvent(const sf::Event &event) {
if (event.type == sf::Event::Closed) {
void GameState::onEvent(const SDL_Event &event) {
if (event.type == SDL_QUIT) {
m_client.disconnect();
m_stateStack->clear();
@ -87,44 +87,38 @@ void GameState::onEvent(const sf::Event &event) {
if (!m_stateStack->empty() && &m_stateStack->top() == this) {
KeyboardHandler *keyboardHandler = (KeyboardHandler *)gk::GamePad::getInputHandler();
#ifdef __APPLE__
if (event.type == sf::Event::MouseMoved) {
gk::Mouse::update(event);
if (event.type == SDL_MOUSEMOTION) {
if(Config::screenWidth / 2.0f != event.motion.x || Config::screenHeight / 2.0f != event.motion.y) {
m_player.turnH(event.motion.xrel * -0.01 * Config::mouseSensitivity);
m_player.turnViewV(event.motion.yrel * -0.01 * Config::mouseSensitivity);
const auto &delta = gk::Mouse::getDelta();
m_player.turnH(delta.x * -0.02 * Config::mouseSensitivity);
m_player.turnViewV(delta.y * -0.02 * Config::mouseSensitivity);
gk::Mouse::resetToWindowCenter();
}
}
#else
if (event.type == sf::Event::MouseMovedRaw) {
m_player.turnH(event.mouseMoveRaw.deltaX * -0.01 * Config::mouseSensitivity);
m_player.turnViewV(event.mouseMoveRaw.deltaY * -0.01 * Config::mouseSensitivity);
gk::Mouse::resetToWindowCenter();
}
#endif
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
m_stateStack->push<PauseMenuState>(m_client, this);
}
else if (event.type == sf::Event::KeyPressed
&& (event.key.code == keyboardHandler->getKeycode(GameKey::Chat)
|| event.key.code == keyboardHandler->getKeycode(GameKey::Command)))
else if (event.type == SDL_KEYDOWN
&& (event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Chat)
|| event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Command)))
{
m_stateStack->push<ChatState>(m_clientCommandHandler, m_hud.chat(), event.key.code == keyboardHandler->getKeycode(GameKey::Command), this);
m_stateStack->push<ChatState>(m_clientCommandHandler, m_hud.chat(), event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Command), this);
}
else if (event.type == sf::Event::LostFocus) {
m_stateStack->push<PauseMenuState>(m_client, this);
else if (event.type == SDL_WINDOWEVENT) {
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
m_stateStack->push<PauseMenuState>(m_client, this);
gk::Mouse::setCursorGrabbed(false);
gk::Mouse::setCursorVisible(true);
gk::Mouse::setCursorGrabbed(false);
gk::Mouse::setCursorVisible(true);
}
else if (event.type == SDL_WINDOWEVENT_FOCUS_GAINED) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
}
}
else if (event.type == sf::Event::GainedFocus) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
}
else if (event.type == sf::Event::KeyPressed) {
else if (event.type == SDL_KEYDOWN) {
for (auto &key : Registry::getInstance().keys()) {
if (event.key.code == key.keycode()) {
if (event.key.keysym.sym == key.keycode()) {
m_clientCommandHandler.sendKeyPressed(key.id());
}
}
@ -133,9 +127,9 @@ void GameState::onEvent(const sf::Event &event) {
m_hud.onEvent(event);
}
if (event.type == sf::Event::Resized) {
Config::screenWidth = event.size.width;
Config::screenHeight = event.size.height;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
Config::screenWidth = event.window.data1;
Config::screenHeight = event.window.data2;
m_camera.setAspectRatio((float)Config::screenWidth / Config::screenHeight);
m_hud.setup();

View File

@ -54,7 +54,7 @@ class GameState : public gk::ApplicationState {
void connect(const std::string &host, int port, const std::string &username);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -52,18 +52,18 @@ void InterfaceState::setup() {
// m_view.setCenter(Config::screenWidth / 2.0f, Config::screenHeight / 2.0f);
}
void InterfaceState::onEvent(const sf::Event &event) {
void InterfaceState::onEvent(const SDL_Event &event) {
if (m_parent) {
m_parent->onEvent(event);
}
else if (event.type == sf::Event::Closed) {
else if (event.type == SDL_QUIT) {
m_stateStack->clear();
}
if (event.type == sf::Event::Resized) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (!m_parent) {
Config::screenWidth = event.size.width;
Config::screenHeight = event.size.height;
Config::screenWidth = event.window.data1;
Config::screenHeight = event.window.data2;
}
setup();

View File

@ -37,7 +37,7 @@ class InterfaceState : public gk::ApplicationState {
protected:
void setup();
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -64,13 +64,13 @@ LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, Cli
loadGUI(packet);
}
void LuaGUIState::onEvent(const sf::Event &event) {
void LuaGUIState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (event.type == sf::Event::Resized && m_isCentered)
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED && m_isCentered)
centerMainWidget();
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
gk::Mouse::resetToWindowCenter();
@ -81,7 +81,7 @@ void LuaGUIState::onEvent(const sf::Event &event) {
for (auto &it : m_widgets)
it->onEvent(event);
if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT
&& m_currentInventoryWidget && !m_currentInventoryWidget->shiftDestination().empty()
&& m_mouseItemWidget.currentItemWidget() && gk::GamePad::isKeyPressed(GameKey::Shift)) {
for (const std::string &shiftDestination : m_currentInventoryWidget->shiftDestination()) {
@ -202,7 +202,7 @@ void LuaGUIState::loadImage(const std::string &, s32 x, s32 y, sf::Packet &packe
gk::FloatRect clipRect;
packet >> textureFilename >> clipRect.x >> clipRect.y >> clipRect.sizeX >> clipRect.sizeY;
sf::Texture &texture = loadTexture(textureFilename);
gk::Texture &texture = loadTexture(textureFilename);
auto *image = new gk::Image(texture);
image->setPosition(x, y);
@ -335,7 +335,7 @@ void LuaGUIState::loadProgressBarWidget(const std::string &, s32 x, s32 y, sf::P
return;
}
sf::Texture &texture = loadTexture(textureFilename);
gk::Texture &texture = loadTexture(textureFilename);
ProgressBarWidget *widget = new ProgressBarWidget(texture, *data, ProgressBarType(type));
if (!maxMeta.empty())
@ -353,7 +353,7 @@ void LuaGUIState::loadScrollBarWidget(const std::string &, s32 x, s32 y, sf::Pac
std::string widget;
packet >> textureFilename >> clipRect >> minY >> maxY >> widget;
sf::Texture &texture = loadTexture(textureFilename);
gk::Texture &texture = loadTexture(textureFilename);
ScrollBarWidget *scrollBarWidget = new ScrollBarWidget(&m_mainWidget);
scrollBarWidget->setPosition(x, y);
@ -368,10 +368,10 @@ void LuaGUIState::loadInventory(const std::string &name, sf::Packet &packet) {
packet >> m_inventories.at(name);
}
sf::Texture &LuaGUIState::loadTexture(const std::string &textureFilename) {
gk::Texture &LuaGUIState::loadTexture(const std::string &textureFilename) {
auto it = m_textures.find(textureFilename);
if (it == m_textures.end()) {
m_textures.emplace(textureFilename, sf::Texture{}).first->second.loadFromFile(textureFilename);
m_textures.emplace(textureFilename, gk::Texture{}).first->second.loadFromFile(textureFilename);
return m_textures.at(textureFilename);
}
else {

View File

@ -44,7 +44,7 @@ class LuaGUIState : public InterfaceState {
public:
LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, ClientWorld &world, sf::Packet &packet, gk::ApplicationState *parent = nullptr);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;
@ -60,7 +60,7 @@ class LuaGUIState : public InterfaceState {
void loadScrollBarWidget(const std::string &name, s32 x, s32 y, sf::Packet &packet);
void loadInventory(const std::string &name, sf::Packet &packet);
sf::Texture &loadTexture(const std::string &textureFilename);
gk::Texture &loadTexture(const std::string &textureFilename);
void centerMainWidget();
@ -76,7 +76,7 @@ class LuaGUIState : public InterfaceState {
std::vector<std::unique_ptr<Widget>> m_widgets;
std::vector<std::unique_ptr<gk::Drawable>> m_drawables;
std::unordered_map<std::string, Inventory> m_inventories;
std::unordered_map<std::string, sf::Texture> m_textures;
std::unordered_map<std::string, gk::Texture> m_textures;
ClientPlayer &m_player;
ClientWorld &m_world;

View File

@ -87,17 +87,18 @@ void PauseMenuState::init() {
m_eventHandler->addListener<GuiScaleChangedEvent>(&PauseMenuState::onGuiScaleChanged, this);
}
void PauseMenuState::onEvent(const sf::Event &event) {
void PauseMenuState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (event.type == sf::Event::Resized && !m_stateStack->empty() && &m_stateStack->top() != this) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED
&& !m_stateStack->empty() && &m_stateStack->top() != this) {
m_menuWidget.onEvent(event);
}
if (!m_stateStack->empty() && &m_stateStack->top() == this) {
m_menuWidget.onEvent(event);
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
gk::Mouse::resetToWindowCenter();

View File

@ -41,7 +41,7 @@ class PauseMenuState : public InterfaceState {
void init() override;
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
private:
void onGuiScaleChanged(const GuiScaleChangedEvent &event);

View File

@ -104,7 +104,7 @@ ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : Interface
updateWidgetPosition();
}
void ServerConnectState::onEvent(const sf::Event &event) {
void ServerConnectState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (!m_stateStack->empty() && &m_stateStack->top() == this) {

View File

@ -35,7 +35,7 @@ class ServerConnectState : public InterfaceState {
public:
ServerConnectState(gk::ApplicationState *parent = nullptr);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -69,10 +69,10 @@ void SettingsMenuState::init() {
m_eventHandler->addListener<GuiScaleChangedEvent>(&SettingsMenuState::onGuiScaleChanged, this);
}
void SettingsMenuState::onEvent(const sf::Event &event) {
void SettingsMenuState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (event.type == sf::Event::Resized && &m_stateStack->top() != this) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED && &m_stateStack->top() != this) {
m_menuWidget.onEvent(event);
}
@ -80,14 +80,14 @@ void SettingsMenuState::onEvent(const sf::Event &event) {
m_menuWidget.onEvent(event);
m_doneButton.onEvent(event);
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
doneButtonAction();
}
else if (m_currentKeyButton && event.type == sf::Event::KeyPressed) {
else if (m_currentKeyButton && event.type == SDL_KEYDOWN) {
KeyboardHandler *keyboardHandler = dynamic_cast<KeyboardHandler *>(gk::GamePad::getInputHandler());
keyboardHandler->setKeycode(m_currentKey, event.key.code);
keyboardHandler->setKeycode(m_currentKey, event.key.keysym.sym);
m_key->setKeycode(event.key.code);
m_key->setKeycode(event.key.keysym.sym);
m_key = nullptr;
m_currentKeyButton->setText(m_currentKeyButton->text() + keyboardHandler->getKeyName(m_currentKey));

View File

@ -42,7 +42,7 @@ class SettingsMenuState : public InterfaceState {
void init() override;
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
private:
void onGuiScaleChanged(const GuiScaleChangedEvent &event);

View File

@ -94,10 +94,10 @@ void TitleScreenState::init() {
m_eventHandler->addListener<GuiScaleChangedEvent>(&TitleScreenState::onGuiScaleChanged, this);
}
void TitleScreenState::onEvent(const sf::Event &event) {
void TitleScreenState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (event.type == sf::Event::Resized) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (!m_stateStack->empty() && &m_stateStack->top() != this)
m_menuWidget.onEvent(event);
}

View File

@ -42,7 +42,7 @@ class TitleScreenState : public InterfaceState {
void init() override;
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -98,7 +98,7 @@ WorldCreationState::WorldCreationState(TitleScreenState *titleScreen, const std:
updateWidgetPosition();
}
void WorldCreationState::onEvent(const sf::Event &event) {
void WorldCreationState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (!m_stateStack->empty() && &m_stateStack->top() == this) {

View File

@ -37,7 +37,7 @@ class WorldCreationState : public InterfaceState {
public:
WorldCreationState(TitleScreenState *titleScreen, const std::string &originalName = "");
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -67,7 +67,7 @@ WorldDeletionState::WorldDeletionState(const std::string &worldName, TitleScreen
updateWidgetPosition();
}
void WorldDeletionState::onEvent(const sf::Event &event) {
void WorldDeletionState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (&m_stateStack->top() == this) {
@ -75,9 +75,6 @@ void WorldDeletionState::onEvent(const sf::Event &event) {
}
}
void WorldDeletionState::update() {
}
void WorldDeletionState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);

View File

@ -36,9 +36,7 @@ class WorldDeletionState : public InterfaceState {
public:
WorldDeletionState(const std::string &worldName, TitleScreenState *titleScreen);
void onEvent(const sf::Event &event) override;
void update() override;
void onEvent(const SDL_Event &event) override;
private:
void updateWidgetPosition() override;

View File

@ -87,10 +87,11 @@ WorldSelectionState::WorldSelectionState(TitleScreenState *titleScreen)
loadSaveList();
}
void WorldSelectionState::onEvent(const sf::Event &event) {
void WorldSelectionState::onEvent(const SDL_Event &event) {
InterfaceState::onEvent(event);
if (event.type == sf::Event::Resized && !m_stateStack->empty() && &m_stateStack->top() != this) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED
&& !m_stateStack->empty() && &m_stateStack->top() != this) {
m_worldList.onEvent(event);
}

View File

@ -37,7 +37,7 @@ class WorldSelectionState : public InterfaceState {
public:
WorldSelectionState(TitleScreenState *titleScreen);
void onEvent(const sf::Event &event) override;
void onEvent(const SDL_Event &event) override;
void update() override;

View File

@ -61,9 +61,9 @@ void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u
else
glCheck(glEnable(GL_CULL_FACE));
sf::Texture::bind(states.texture);
gk::Texture::bind(states.texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, (layer == ChunkBuilder::Layer::NoMipMap || layer == ChunkBuilder::Layer::Flora) ? 0 : Config::mipmapLevels);
sf::Texture::bind(nullptr);
gk::Texture::bind(nullptr);
glCheck(glEnable(GL_DEPTH_TEST));

View File

@ -20,6 +20,8 @@ endforeach(HEADER_FILE)
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
add_dependencies(${PROJECT_NAME}
sfml-network
sfml-system
zlib
EnTT
gamekit
@ -47,6 +49,8 @@ if (UNIX)
endif ()
target_link_libraries(${PROJECT_NAME} PUBLIC
sfml-network
sfml-system
sol2
liblua
gamekit

View File

@ -24,10 +24,9 @@
*
* =====================================================================================
*/
#include <SFML/Graphics/Texture.hpp>
#include <gk/core/XMLFile.hpp>
#include <gk/gl/OpenGL.hpp>
#include <gk/gl/Texture.hpp>
#include <gk/resource/ResourceHandler.hpp>
#include "TextureLoader.hpp"
@ -40,14 +39,14 @@ void TextureLoader::load(const char *xmlFilename, gk::ResourceHandler &handler)
std::string name = textureElement->Attribute("name");
std::string path = textureElement->Attribute("path");
auto &texture = handler.add<sf::Texture>("texture-" + name);
auto &texture = handler.add<gk::Texture>("texture-" + name);
texture.loadFromFile(path);
if (textureElement->Attribute("repeat", "true")) {
sf::Texture::bind(&texture);
gk::Texture::bind(&texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
sf::Texture::bind(nullptr);
gk::Texture::bind(nullptr);
}
textureElement = textureElement->NextSiblingElement("texture");

View File

@ -30,12 +30,11 @@
#include <string>
#include <gk/core/IntTypes.hpp>
#include <gk/core/input/KeyboardUtils.hpp>
#include <gk/core/ISerializable.hpp>
#include <gk/core/SDLHeaders.hpp>
#include <sol/sol.hpp>
#include <gk/core/ISerializable.hpp>
#include "NetworkUtils.hpp"
class Key : public gk::ISerializable {
@ -53,15 +52,15 @@ class Key : public gk::ISerializable {
const std::string &name() const { return m_name; }
void setName(const std::string &name) { m_name = name; }
sf::Keyboard::Key keycode() const { return m_keycode; }
void setKeycode(sf::Keyboard::Key keycode) { m_keycode = keycode; if (m_parent) m_parent->m_keycode = keycode; }
SDL_Keycode keycode() const { return m_keycode; }
void setKeycode(SDL_Keycode keycode) { m_keycode = keycode; if (m_parent) m_parent->m_keycode = keycode; }
const std::string &defaultKey() const { return m_defaultKey; }
void setDefaultKey(const std::string &defaultKey) {
m_defaultKey = defaultKey;
if (m_keycode == sf::Keyboard::Unknown)
m_keycode = gk::KeyboardUtils::getKeyFromName(m_defaultKey);
if (m_keycode == SDLK_UNKNOWN)
m_keycode = SDL_GetKeyFromName(m_defaultKey.c_str());
}
const sol::unsafe_function &callback() const { return m_callback; }
@ -76,7 +75,7 @@ class Key : public gk::ISerializable {
std::string m_name;
std::string m_defaultKey;
sf::Keyboard::Key m_keycode = sf::Keyboard::Unknown;
SDL_Keycode m_keycode = SDLK_UNKNOWN;
sol::unsafe_function m_callback;