diff --git a/.gitmodules b/.gitmodules index 8a992a2fa..d22875d64 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,10 +2,6 @@ path = external/entt url = git://github.com/skypjack/entt.git ignore = dirty -[submodule "external/SFML"] - path = external/SFML - url = git://github.com/SFML/SFML.git - ignore = dirty [submodule "external/gamekit"] path = external/gamekit url = git://github.com/Unarelith/GameKit.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c6e4d223..51f73ad93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(openminer) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") if (WIN32) set(WIN_LIBRARIES_PATH "C:/Libraries") @@ -98,47 +98,6 @@ endif(NOT GLM_FOUND) include_directories(${GLM_INCLUDE_DIRS}) -#------------------------------------------------------------------------------ -# - SDL2, SDL2_image, SDL2_mixer -#------------------------------------------------------------------------------ -if (MSVC) - set(SDL2_PATH ${WIN_LIBRARIES_PATH}/SDL2 CACHE BOOL "" FORCE) - set(SDL2_IMAGE_PATH ${WIN_LIBRARIES_PATH}/SDL2_image CACHE BOOL "" FORCE) - set(SDL2_MIXER_PATH ${WIN_LIBRARIES_PATH}/SDL2_mixer CACHE BOOL "" FORCE) - set(SDL2_TTF_PATH ${WIN_LIBRARIES_PATH}/SDL2_ttf CACHE BOOL "" FORCE) -elseif (WIN32) - set(SDL2_PATH ${WIN_LIBRARIES_PATH}/SDL2/i686-w64-mingw32 CACHE BOOL "" FORCE) - set(SDL2_IMAGE_PATH ${WIN_LIBRARIES_PATH}/SDL2_image/i686-w64-mingw32 CACHE BOOL "" FORCE) - set(SDL2_MIXER_PATH ${WIN_LIBRARIES_PATH}/SDL2_mixer/i686-w64-mingw32 CACHE BOOL "" FORCE) - set(SDL2_TTF_PATH ${WIN_LIBRARIES_PATH}/SDL2_ttf/i686-w64-mingw32 CACHE BOOL "" FORCE) -endif () - -find_package(SDL2 REQUIRED) -find_package(SDL2_image REQUIRED) -find_package(SDL2_mixer REQUIRED) -find_package(SDL2_ttf REQUIRED) - -if(NOT SDL2_FOUND) - message(FATAL_ERROR "SDL2 not found!") -endif(NOT SDL2_FOUND) - -if(NOT SDL2_IMAGE_FOUND) - message(FATAL_ERROR "SDL2_image not found!") -endif(NOT SDL2_IMAGE_FOUND) - -if(NOT SDL2_MIXER_FOUND) - message(FATAL_ERROR "SDL2_mixer not found!") -endif(NOT SDL2_MIXER_FOUND) - -if(NOT SDL2_TTF_FOUND) - message(FATAL_ERROR "SDL2_ttf not found!") -endif(NOT SDL2_TTF_FOUND) - -include_directories(${SDL2_INCLUDE_DIRS} - ${SDL2_IMAGE_INCLUDE_DIRS} - ${SDL2_MIXER_INCLUDE_DIRS} - ${SDL2_TTF_INCLUDE_DIRS}) - #------------------------------------------------------------------------------ # - GLEW #------------------------------------------------------------------------------ @@ -189,18 +148,6 @@ include_directories(external/entt/single_include) add_subdirectory(external/gamekit) include_directories(external/gamekit/include) -#------------------------------------------------------------------------------ -# - SFML network -#------------------------------------------------------------------------------ -set(SFML_BUILD_AUDIO FALSE) -set(SFML_BUILD_GRAPHICS FALSE) -set(SFML_BUILD_WINDOW FALSE) -set(SFML_STATIC TRUE) - -set(BUILD_SHARED_LIBS OFF) - -add_subdirectory(external/SFML) - #------------------------------------------------------------------------------ # - zlib #------------------------------------------------------------------------------ diff --git a/external/SFML b/external/SFML deleted file mode 160000 index 50e173e40..000000000 --- a/external/SFML +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 50e173e403ef8912e3d8ac3c7ab3e27e32243339 diff --git a/external/gamekit b/external/gamekit index d39510fa3..4459bb5cb 160000 --- a/external/gamekit +++ b/external/gamekit @@ -1 +1 @@ -Subproject commit d39510fa3920197ddff588aacf5a15175e67887a +Subproject commit 4459bb5cb5b99c5265930fde9276b763b0969fa5 diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index 4f8b7ecf8..4e64b6ae9 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -52,15 +52,14 @@ target_link_libraries(${PROJECT_NAME} ${CMAKE_PROJECT_NAME}_common gamekit ${OPENGL_LIBRARIES} - ${SDL2_LIBRARIES} - ${SDL2_IMAGE_LIBRARIES} - ${SDL2_MIXER_LIBRARIES} - ${SDL2_TTF_LIBRARIES} ${TINYXML2_LIBRARIES} ${GLEW_LIBRARIES} ${LUA_LIBRARIES} sfml-system + sfml-window sfml-network + sfml-graphics + sfml-audio zlib ${UNIX_LIBS}) diff --git a/source/client/core/ClientApplication.cpp b/source/client/core/ClientApplication.cpp index 4c4acb2d3..ceb1587b7 100644 --- a/source/client/core/ClientApplication.cpp +++ b/source/client/core/ClientApplication.cpp @@ -104,21 +104,22 @@ void ClientApplication::init() { void ClientApplication::handleEvents() { gk::CoreApplication::handleEvents(); - 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.resize(Config::screenWidth, Config::screenHeight); - } - - if (Config::isVerticalSyncEnabled != m_window.isVerticalSyncEnabled()) - m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled); + // FIXME: SFML + // 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.resize(Config::screenWidth, Config::screenHeight); + // } + // + // if (Config::isVerticalSyncEnabled != m_window.isVerticalSyncEnabled()) + // m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled); } -void ClientApplication::onEvent(const SDL_Event &event) { - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F11) +void ClientApplication::onEvent(const sf::Event &event) { + if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F11) Config::isFullscreenModeEnabled ^= 1; } diff --git a/source/client/core/ClientApplication.hpp b/source/client/core/ClientApplication.hpp index 05e5ba1c1..f623707a5 100644 --- a/source/client/core/ClientApplication.hpp +++ b/source/client/core/ClientApplication.hpp @@ -41,7 +41,7 @@ class ClientApplication : public gk::CoreApplication { private: void handleEvents() override; - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void initOpenGL(); diff --git a/source/client/graphics/PlayerBox.cpp b/source/client/graphics/PlayerBox.cpp index ec5dc5cbb..b23ac3552 100644 --- a/source/client/graphics/PlayerBox.cpp +++ b/source/client/graphics/PlayerBox.cpp @@ -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("texture-player")) + m_texture(gk::ResourceHandler::getInstance().get("texture-player")) { updateVertexBuffer(); } diff --git a/source/client/graphics/PlayerBox.hpp b/source/client/graphics/PlayerBox.hpp index 735c92ac6..d02769a95 100644 --- a/source/client/graphics/PlayerBox.hpp +++ b/source/client/graphics/PlayerBox.hpp @@ -27,11 +27,12 @@ #ifndef PLAYERBOX_HPP_ #define PLAYERBOX_HPP_ +#include + #include #include #include #include -#include #include "Player.hpp" @@ -52,7 +53,7 @@ class PlayerBox : public gk::Drawable, public gk::Transformable, public Player { const gk::Camera &m_camera; - gk::Texture &m_texture; + sf::Texture &m_texture; }; #endif // PLAYERBOX_HPP_ diff --git a/source/client/graphics/TextureAtlas.cpp b/source/client/graphics/TextureAtlas.cpp index 35dbe99af..060dfd7e3 100644 --- a/source/client/graphics/TextureAtlas.cpp +++ b/source/client/graphics/TextureAtlas.cpp @@ -26,6 +26,7 @@ */ #include #include +#include #include "Registry.hpp" #include "TextureAtlas.hpp" @@ -37,75 +38,78 @@ void TextureAtlas::addFile(const std::string &path, const std::string &filename) if (it != m_textureMap.end()) return; - SurfacePtr surface{IMG_Load((path + filename).c_str()), &SDL_FreeSurface}; - if(!surface) { - gkWarning() << "Failed to load texture:" << path + filename; - return; - } - - if (!m_tileSize) - m_tileSize = surface->w; - - if (m_tileSize != surface->w || m_tileSize != surface->h) - throw EXCEPTION("Texture size unexpected for", path + filename + ". Got", surface->w, surface->h, "instead of", m_tileSize, m_tileSize); - - m_textureMap.emplace(filename, m_textures.size()); - m_textures.emplace_back(std::move(surface)); + // FIXME: SFML + // SurfacePtr surface{IMG_Load((path + filename).c_str()), &SDL_FreeSurface}; + // if(!surface) { + // gkWarning() << "Failed to load texture:" << path + filename; + // return; + // } + // + // if (!m_tileSize) + // m_tileSize = surface->w; + // + // if (m_tileSize != surface->w || m_tileSize != surface->h) + // throw EXCEPTION("Texture size unexpected for", path + filename + ". Got", surface->w, surface->h, "instead of", m_tileSize, m_tileSize); + // + // m_textureMap.emplace(filename, m_textures.size()); + // m_textures.emplace_back(std::move(surface)); } void TextureAtlas::packTextures() { if (!m_tileSize) throw EXCEPTION("Cannot pack zero-sized textures!"); - SurfacePtr atlas{nullptr, &SDL_FreeSurface}; - - // Max amount of textures on one line - const u16 atlasWidth = 16; - - // Max amount of textures on one column - const u16 atlasHeight = std::ceil((float)m_textures.size() / atlasWidth); - - Uint32 rmask, gmask, bmask, amask; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif - - atlas.reset(SDL_CreateRGBSurface(0, atlasWidth * m_tileSize, atlasHeight * m_tileSize, 32, rmask, gmask, bmask, amask)); - if (!atlas) { - throw EXCEPTION("Failed to create surface:", SDL_GetError()); - } - - u16 i = 0; - for (auto &it : m_textures) { - SDL_Rect outRect; - outRect.x = (i % atlasWidth) * m_tileSize; - outRect.y = (i / atlasWidth) * m_tileSize; - outRect.w = m_tileSize; - outRect.h = m_tileSize; - - SDL_BlitSurface(it.get(), nullptr, atlas.get(), &outRect); - - ++i; - } - - m_textures.clear(); + // FIXME: SFML +// SurfacePtr atlas{nullptr, &SDL_FreeSurface}; +// +// // Max amount of textures on one line +// const u16 atlasWidth = 16; +// +// // Max amount of textures on one column +// const u16 atlasHeight = std::ceil((float)m_textures.size() / atlasWidth); +// +// Uint32 rmask, gmask, bmask, amask; +// #if SDL_BYTEORDER == SDL_BIG_ENDIAN +// rmask = 0xff000000; +// gmask = 0x00ff0000; +// bmask = 0x0000ff00; +// amask = 0x000000ff; +// #else +// rmask = 0x000000ff; +// gmask = 0x0000ff00; +// bmask = 0x00ff0000; +// amask = 0xff000000; +// #endif +// +// atlas.reset(SDL_CreateRGBSurface(0, atlasWidth * m_tileSize, atlasHeight * m_tileSize, 32, rmask, gmask, bmask, amask)); +// if (!atlas) { +// throw EXCEPTION("Failed to create surface:", SDL_GetError()); +// } +// +// u16 i = 0; +// for (auto &it : m_textures) { +// SDL_Rect outRect; +// outRect.x = (i % atlasWidth) * m_tileSize; +// outRect.y = (i / atlasWidth) * m_tileSize; +// outRect.w = m_tileSize; +// outRect.h = m_tileSize; +// +// SDL_BlitSurface(it.get(), nullptr, atlas.get(), &outRect); +// +// ++i; +// } +// +// m_textures.clear(); m_isReady = true; - if (IMG_SavePNG(atlas.get(), "test_atlas.png") < 0) - throw EXCEPTION("Failed to save texture to: test_atlas.png. Reason:", IMG_GetError()); - - m_texture.loadFromSurface(atlas.get()); + // FIXME: SFML + // if (IMG_SavePNG(atlas.get(), "test_atlas.png") < 0) + // throw EXCEPTION("Failed to save texture to: test_atlas.png. Reason:", IMG_GetError()); + // + // m_texture.loadFromSurface(atlas.get()); - gk::Texture::bind(&m_texture); + sf::Texture::bind(&m_texture); glGenerateMipmap(GL_TEXTURE_2D); @@ -115,7 +119,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); - gk::Texture::bind(nullptr); + sf::Texture::bind(nullptr); } void TextureAtlas::loadFromRegistry(const std::string &texturePack) { diff --git a/source/client/graphics/TextureAtlas.hpp b/source/client/graphics/TextureAtlas.hpp index ac331a40a..5c0eda836 100644 --- a/source/client/graphics/TextureAtlas.hpp +++ b/source/client/graphics/TextureAtlas.hpp @@ -32,10 +32,10 @@ #include #include +#include + #include -#include #include -#include class TextureAtlas { public: @@ -49,7 +49,7 @@ class TextureAtlas { u16 getTextureID(const std::string &filename) const; gk::FloatRect getTexCoords(const std::string &filename, bool normalized = true) const; - const gk::Texture &texture() const { return m_texture; } + const sf::Texture &texture() const { return m_texture; } bool isReady() const { return m_isReady; } @@ -60,12 +60,8 @@ class TextureAtlas { // Mapping between filename and internal texture ID std::unordered_map m_textureMap; - // Textures to pack together - using SurfacePtr = std::unique_ptr; - std::vector m_textures; - // Packed texture - gk::Texture m_texture; + sf::Texture m_texture; // Is the texture atlas ready to use? bool m_isReady = false; diff --git a/source/client/gui/CraftingWidget.cpp b/source/client/gui/CraftingWidget.cpp index 565e1fb28..b5844fc0f 100644 --- a/source/client/gui/CraftingWidget.cpp +++ b/source/client/gui/CraftingWidget.cpp @@ -43,7 +43,7 @@ void CraftingWidget::init(unsigned int offset, unsigned int size) { m_craftingResultInventoryWidget.setShiftDestination(m_shiftDestination); } -void CraftingWidget::onEvent(const SDL_Event &event) { +void CraftingWidget::onEvent(const sf::Event &event) { m_craftingInventoryWidget.onEvent(event); m_craftingResultInventoryWidget.onEvent(event); diff --git a/source/client/gui/CraftingWidget.hpp b/source/client/gui/CraftingWidget.hpp index fc2d081a0..f81ac0c97 100644 --- a/source/client/gui/CraftingWidget.hpp +++ b/source/client/gui/CraftingWidget.hpp @@ -37,7 +37,7 @@ class CraftingWidget : public AbstractInventoryWidget { void init(unsigned int offset = 0, unsigned int size = 3); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/gui/Font.cpp b/source/client/gui/Font.cpp index 4b29545f0..c2e129be0 100644 --- a/source/client/gui/Font.cpp +++ b/source/client/gui/Font.cpp @@ -26,13 +26,14 @@ */ #include -#include +#include + #include #include "Font.hpp" Font::Font(const std::string &textureName, const std::string &configPath) - : m_texture(gk::ResourceHandler::getInstance().get(textureName)) + : m_texture(gk::ResourceHandler::getInstance().get(textureName)) { std::memset(m_charWidth, 0, sizeof(u8) * 256); diff --git a/source/client/gui/Font.hpp b/source/client/gui/Font.hpp index 7752e5591..5b7ae2a6c 100644 --- a/source/client/gui/Font.hpp +++ b/source/client/gui/Font.hpp @@ -31,7 +31,7 @@ #include -namespace gk { +namespace sf { 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 gk::Texture &texture() const { return m_texture; } + const sf::Texture &texture() const { return m_texture; } private: void parseConfig(const std::string &configPath); - gk::Texture &m_texture; + sf::Texture &m_texture; u8 m_charWidth[256]; u8 m_width = 8; // FIXME: Hardcoded value diff --git a/source/client/gui/InventoryWidget.cpp b/source/client/gui/InventoryWidget.cpp index 4477004db..e1c318f5f 100644 --- a/source/client/gui/InventoryWidget.cpp +++ b/source/client/gui/InventoryWidget.cpp @@ -52,11 +52,11 @@ void InventoryWidget::scroll(float scrolling) { loadItemWidgets(offset, size); } -void InventoryWidget::onEvent(const SDL_Event &event) { - if (event.type == SDL_MOUSEMOTION) { +void InventoryWidget::onEvent(const sf::Event &event) { + if (event.type == sf::Event::MouseMoved) { m_currentItemWidget = nullptr; for (std::size_t i = 0 ; i < m_itemWidgets.size() ; ++i) { - if (m_itemWidgets[i].isPointInWidget(event.motion.x, event.motion.y)) { + if (m_itemWidgets[i].isPointInWidget(event.mouseMove.x, event.mouseMove.y)) { m_currentItemWidget = &m_itemWidgets[i]; m_selectedItemBackground.setPosition(1 + (i % m_inventoryWidth) * 18, 1 + (i / m_inventoryWidth) * 18, 0); diff --git a/source/client/gui/InventoryWidget.hpp b/source/client/gui/InventoryWidget.hpp index 10c1381a6..bc335d72e 100644 --- a/source/client/gui/InventoryWidget.hpp +++ b/source/client/gui/InventoryWidget.hpp @@ -43,7 +43,7 @@ class InventoryWidget : public AbstractInventoryWidget { void scroll(float scrolling); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/gui/MenuWidget.cpp b/source/client/gui/MenuWidget.cpp index e69b5bbf7..1a31b424a 100644 --- a/source/client/gui/MenuWidget.cpp +++ b/source/client/gui/MenuWidget.cpp @@ -40,11 +40,11 @@ void MenuWidget::reset(u16 width, u16 height) { m_buttons.reserve(m_width * m_height); } -void MenuWidget::onEvent(const SDL_Event &event) { +void MenuWidget::onEvent(const sf::Event &event) { for (std::size_t i = 0 ; i < m_buttons.size() ; ++i) { m_buttons.at(i).onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { int x = i % m_width; int y = i / m_width; diff --git a/source/client/gui/MenuWidget.hpp b/source/client/gui/MenuWidget.hpp index 1df8892d6..28964202d 100644 --- a/source/client/gui/MenuWidget.hpp +++ b/source/client/gui/MenuWidget.hpp @@ -38,7 +38,7 @@ class MenuWidget : public Widget { void reset(u16 width, u16 height); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void onGuiScaleChanged(const GuiScaleChangedEvent &event); diff --git a/source/client/gui/MouseItemWidget.cpp b/source/client/gui/MouseItemWidget.cpp index 70e733ff7..b9e0f1391 100644 --- a/source/client/gui/MouseItemWidget.cpp +++ b/source/client/gui/MouseItemWidget.cpp @@ -37,35 +37,35 @@ MouseItemWidget::MouseItemWidget(Widget *parent) : ItemWidget(m_inventory, 0, 0, m_tooltipInfoText.setColor({180, 180, 180}); } -void MouseItemWidget::onEvent(const SDL_Event &event) { - if (event.type == SDL_MOUSEMOTION) { - updatePosition(event.motion.x, event.motion.y); +void MouseItemWidget::onEvent(const sf::Event &event) { + if (event.type == sf::Event::MouseMoved) { + updatePosition(event.mouseMove.x, event.mouseMove.y); } - else if (event.type == SDL_MOUSEBUTTONDOWN) { - updatePosition(event.button.x, event.button.y); + else if (event.type == sf::Event::MouseButtonPressed) { + updatePosition(event.mouseButton.x, event.mouseButton.y); if (getStack().amount() == 0) { - if (event.button.button == SDL_BUTTON_LEFT) { + if (event.mouseButton.button == sf::Mouse::Left) { leftClickBehaviour(); } - else if (event.button.button == SDL_BUTTON_RIGHT) { + else if (event.mouseButton.button == sf::Mouse::Right) { rightClickBehaviour(); } m_isDragging = false; } - else if (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT) { - startDragging(event.button.button == SDL_BUTTON_LEFT); + else if (event.mouseButton.button == sf::Mouse::Left || event.mouseButton.button == sf::Mouse::Right) { + startDragging(event.mouseButton.button == sf::Mouse::Left); } } - else if (event.type == SDL_MOUSEBUTTONUP) { - updatePosition(event.button.x, event.button.y); + else if (event.type == sf::Event::MouseButtonReleased) { + updatePosition(event.mouseButton.x, event.mouseButton.y); if (m_isDragging && m_draggedSlots.size() <= 1) { - if (event.button.button == SDL_BUTTON_LEFT) { + if (event.mouseButton.button == sf::Mouse::Left) { leftClickBehaviour(); } - else if (event.button.button == SDL_BUTTON_RIGHT) { + else if (event.mouseButton.button == sf::Mouse::Right) { rightClickBehaviour(); } } diff --git a/source/client/gui/MouseItemWidget.hpp b/source/client/gui/MouseItemWidget.hpp index 28b95da45..5d1eb79c1 100644 --- a/source/client/gui/MouseItemWidget.hpp +++ b/source/client/gui/MouseItemWidget.hpp @@ -38,7 +38,7 @@ class MouseItemWidget : public ItemWidget { public: MouseItemWidget(Widget *parent); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void leftClickBehaviour(); void rightClickBehaviour(); diff --git a/source/client/gui/ProgressBarWidget.cpp b/source/client/gui/ProgressBarWidget.cpp index 0fbb98abb..52dd08436 100644 --- a/source/client/gui/ProgressBarWidget.cpp +++ b/source/client/gui/ProgressBarWidget.cpp @@ -26,7 +26,7 @@ */ #include "ProgressBarWidget.hpp" -ProgressBarWidget::ProgressBarWidget(const gk::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent) +ProgressBarWidget::ProgressBarWidget(const sf::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent) : Widget(parent), m_blockData(blockData), m_image(texture) { m_type = type; diff --git a/source/client/gui/ProgressBarWidget.hpp b/source/client/gui/ProgressBarWidget.hpp index d9a4ce1b9..55c3dcd03 100644 --- a/source/client/gui/ProgressBarWidget.hpp +++ b/source/client/gui/ProgressBarWidget.hpp @@ -40,7 +40,7 @@ enum class ProgressBarType : u8 { class ProgressBarWidget : public Widget { public: - ProgressBarWidget(const gk::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent = nullptr); + ProgressBarWidget(const sf::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); diff --git a/source/client/gui/ScrollBarWidget.cpp b/source/client/gui/ScrollBarWidget.cpp index d256543db..347e0c87c 100644 --- a/source/client/gui/ScrollBarWidget.cpp +++ b/source/client/gui/ScrollBarWidget.cpp @@ -29,7 +29,7 @@ #include "Config.hpp" #include "ScrollBarWidget.hpp" -void ScrollBarWidget::init(const gk::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget) { +void ScrollBarWidget::init(const sf::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 gk::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 SDL_Event &event) { - if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) { - if (isPointInWidget(event.button.x, event.button.y)) { +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)) { m_isDragging = true; - updateScrolling(event.button.y); + updateScrolling(event.mouseButton.y); } } - else if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT) { + else if (event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left) { m_isDragging = false; } - else if (event.type == SDL_MOUSEMOTION && m_isDragging) { - updateScrolling(event.motion.y); + else if (event.type == sf::Event::MouseMoved && m_isDragging) { + updateScrolling(event.mouseMove.y); } } diff --git a/source/client/gui/ScrollBarWidget.hpp b/source/client/gui/ScrollBarWidget.hpp index 5c07db2ce..015ac6f24 100644 --- a/source/client/gui/ScrollBarWidget.hpp +++ b/source/client/gui/ScrollBarWidget.hpp @@ -35,9 +35,9 @@ class ScrollBarWidget : public Widget { public: ScrollBarWidget(Widget *parent = nullptr) : Widget(12, 15, parent) {} - void init(const gk::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget); + void init(const sf::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget); - void onEvent(const SDL_Event &event); + void onEvent(const sf::Event &event); private: void draw(gk::RenderTarget &target, gk::RenderStates states) const; diff --git a/source/client/gui/Text.cpp b/source/client/gui/Text.cpp index 97921f1b9..3baff7290 100644 --- a/source/client/gui/Text.cpp +++ b/source/client/gui/Text.cpp @@ -24,7 +24,6 @@ * * ===================================================================================== */ -#include #include #include "Color.hpp" diff --git a/source/client/gui/TextButton.cpp b/source/client/gui/TextButton.cpp index bce7a42a9..6b08175eb 100644 --- a/source/client/gui/TextButton.cpp +++ b/source/client/gui/TextButton.cpp @@ -36,16 +36,16 @@ TextButton::TextButton(const CppCallback &callback, Widget *parent) : TextButton m_cppCallback = callback; } -void TextButton::onEvent(const SDL_Event &event) { - if (event.type == SDL_MOUSEMOTION) { - m_isHovered = isPointInWidget(event.motion.x, event.motion.y); +void TextButton::onEvent(const sf::Event &event) { + if (event.type == sf::Event::MouseMoved) { + m_isHovered = isPointInWidget(event.mouseMove.x, event.mouseMove.y); if (m_isEnabled && m_isHovered && m_text.color() == gk::Color::White) m_text.setColor({255, 255, 160}); else if (!m_isHovered && m_text.color() != gk::Color::White) m_text.setColor(gk::Color::White); } - else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT && m_isHovered && m_isEnabled) { + else if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left && m_isHovered && m_isEnabled) { if (m_cppCallback) m_cppCallback(*this); else if (m_luaCallback) diff --git a/source/client/gui/TextButton.hpp b/source/client/gui/TextButton.hpp index cfbed1bc3..a0c89091e 100644 --- a/source/client/gui/TextButton.hpp +++ b/source/client/gui/TextButton.hpp @@ -44,7 +44,7 @@ class TextButton : public Widget { TextButton(Widget *parent = nullptr); TextButton(const CppCallback &callback, Widget *parent = nullptr); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; const std::string &text() const { return m_text.text(); } void setText(const std::string &text); diff --git a/source/client/gui/TextInput.cpp b/source/client/gui/TextInput.cpp index 10f586314..5212aaba0 100644 --- a/source/client/gui/TextInput.cpp +++ b/source/client/gui/TextInput.cpp @@ -32,22 +32,20 @@ TextInput::TextInput() { m_text.setText(std::string{m_cursor}); } -void TextInput::onEvent(const SDL_Event &event) { - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_BACKSPACE && !m_content.empty()) { +void TextInput::onEvent(const sf::Event &event) { + if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Backspace && !m_content.empty()) { m_content.erase(m_content.begin() + m_content.length() - 1); m_text.setText(m_content + m_cursor); } - 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.setText(m_content + m_cursor); + if (event.type == sf::Event::TextEntered) { + u32 c = event.text.unicode; + if (isprint(c) && (!m_characterLimit || m_content.size() < m_characterLimit)) { + m_content += c; } + + m_text.setText(m_content + m_cursor); } } diff --git a/source/client/gui/TextInput.hpp b/source/client/gui/TextInput.hpp index 5c38789eb..71bc78211 100644 --- a/source/client/gui/TextInput.hpp +++ b/source/client/gui/TextInput.hpp @@ -27,7 +27,7 @@ #ifndef TEXTINPUT_HPP_ #define TEXTINPUT_HPP_ -#include +#include #include "Text.hpp" @@ -35,7 +35,7 @@ class TextInput : public gk::Drawable, public gk::Transformable { public: TextInput(); - void onEvent(const SDL_Event &event); + void onEvent(const sf::Event &event); const std::string &text() const { return m_content; } void setText(const std::string &text) { m_content = text; m_text.setText(m_content + m_cursor); } diff --git a/source/client/gui/Widget.hpp b/source/client/gui/Widget.hpp index 6562c97bc..3fcb37d28 100644 --- a/source/client/gui/Widget.hpp +++ b/source/client/gui/Widget.hpp @@ -27,8 +27,9 @@ #ifndef WIDGET_HPP_ #define WIDGET_HPP_ +#include + #include -#include #include #include @@ -38,7 +39,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 SDL_Event &) {} + virtual void onEvent(const sf::Event &) {} virtual void update() {} bool isPointInWidget(float x, float y); diff --git a/source/client/hud/BlockCursor.cpp b/source/client/hud/BlockCursor.cpp index d79552e8c..c0ab41f7b 100644 --- a/source/client/hud/BlockCursor.cpp +++ b/source/client/hud/BlockCursor.cpp @@ -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("texture-block_destroy"); + m_blockDestroyTexture = &gk::ResourceHandler::getInstance().get("texture-block_destroy"); } -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) { +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) { m_animationStart = gk::GameClock::getInstance().getTicks(); m_currentTool = &m_player.inventory().getStack(hotbar.cursorPos(), 0); } - else if (event.button.button == SDL_BUTTON_RIGHT) { + else if (event.mouseButton.button == sf::Mouse::Right) { if (m_animationStart != 0) m_animationStart = 0; @@ -112,8 +112,8 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) { } } } - else if (event.type == SDL_MOUSEBUTTONUP) { - if (event.button.button == SDL_BUTTON_LEFT) { + else if (event.type == sf::Event::MouseButtonReleased) { + if (event.mouseButton.button == sf::Mouse::Left) { m_animationStart = 0; } } diff --git a/source/client/hud/BlockCursor.hpp b/source/client/hud/BlockCursor.hpp index 81a1cb1d5..6abd097cd 100644 --- a/source/client/hud/BlockCursor.hpp +++ b/source/client/hud/BlockCursor.hpp @@ -27,7 +27,7 @@ #ifndef BLOCKCURSOR_HPP_ #define BLOCKCURSOR_HPP_ -#include +#include #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 SDL_Event &event, const Hotbar &hotbar); + void onEvent(const sf::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; - gk::Texture *m_blockDestroyTexture = nullptr; + sf::Texture *m_blockDestroyTexture = nullptr; }; #endif // BLOCKCURSOR_HPP_ diff --git a/source/client/hud/HUD.cpp b/source/client/hud/HUD.cpp index 0638e12b5..5e08fffb9 100644 --- a/source/client/hud/HUD.cpp +++ b/source/client/hud/HUD.cpp @@ -62,8 +62,8 @@ void HUD::setup() { m_crosshair.setup(); } -void HUD::onEvent(const SDL_Event &event) { - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F3) +void HUD::onEvent(const sf::Event &event) { + if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F3) m_isDebugOverlayVisible ^= 1; if (Config::isHotbarVisible) diff --git a/source/client/hud/HUD.hpp b/source/client/hud/HUD.hpp index aa822c489..e39862d65 100644 --- a/source/client/hud/HUD.hpp +++ b/source/client/hud/HUD.hpp @@ -44,7 +44,7 @@ class HUD : public gk::Transformable, public gk::Drawable { void setup(); - void onEvent(const SDL_Event &event); + void onEvent(const sf::Event &event); void onGuiScaleChanged(const GuiScaleChangedEvent &event); void update(); diff --git a/source/client/hud/Hotbar.cpp b/source/client/hud/Hotbar.cpp index 3c11691c7..357906b75 100644 --- a/source/client/hud/Hotbar.cpp +++ b/source/client/hud/Hotbar.cpp @@ -37,11 +37,11 @@ Hotbar::Hotbar(Inventory &inventory, Widget *parent) : Widget(182, 22, parent), m_cursor.setPosition(-1, -1, 0); } -void Hotbar::onEvent(const SDL_Event &event) { - if (event.type == SDL_MOUSEWHEEL) { - if (event.wheel.y < 0) +void Hotbar::onEvent(const sf::Event &event) { + if (event.type == sf::Event::MouseWheelScrolled) { + if (event.mouseWheelScroll.y < 0) m_cursorPos = (m_cursorPos + 1) % 9; - else if (event.wheel.y > 0) + else if (event.mouseWheelScroll.y > 0) m_cursorPos = (m_cursorPos == 0) ? 8 : m_cursorPos - 1; m_cursor.setPosition(-1 + 20 * m_cursorPos, -1, 0); diff --git a/source/client/hud/Hotbar.hpp b/source/client/hud/Hotbar.hpp index f2f835051..a5681e233 100644 --- a/source/client/hud/Hotbar.hpp +++ b/source/client/hud/Hotbar.hpp @@ -36,7 +36,7 @@ class Hotbar : public Widget { public: Hotbar(Inventory &inventory, Widget *parent = nullptr); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/states/ChatState.cpp b/source/client/states/ChatState.cpp index 66f684101..1117527b4 100644 --- a/source/client/states/ChatState.cpp +++ b/source/client/states/ChatState.cpp @@ -58,16 +58,16 @@ void ChatState::updateTextInputGeometry() { m_textInput.setBackgroundSize(Config::screenWidth / Config::guiScale - 4, 10); } -void ChatState::onEvent(const SDL_Event &event) { +void ChatState::onEvent(const sf::Event &event) { InterfaceState::onEvent(event); m_textInput.onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { updateTextInputGeometry(); } - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Escape) { gk::Mouse::setCursorGrabbed(true); gk::Mouse::setCursorVisible(false); gk::Mouse::resetToWindowCenter(); @@ -78,7 +78,7 @@ void ChatState::onEvent(const SDL_Event &event) { m_stateStack->pop(); } - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) { + if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return) { if (!m_textInput.text().empty()) m_clientCommandHandler.sendChatMessage(m_textInput.text()); diff --git a/source/client/states/ChatState.hpp b/source/client/states/ChatState.hpp index 70d616bc2..5eba81885 100644 --- a/source/client/states/ChatState.hpp +++ b/source/client/states/ChatState.hpp @@ -39,7 +39,7 @@ class ChatState : public InterfaceState { void updateTextInputGeometry(); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; private: void draw(gk::RenderTarget &target, gk::RenderStates states) const override; diff --git a/source/client/states/GameState.cpp b/source/client/states/GameState.cpp index 2478b1abe..f09a3bb47 100644 --- a/source/client/states/GameState.cpp +++ b/source/client/states/GameState.cpp @@ -71,8 +71,8 @@ void GameState::connect(const std::string &host, int port) { gk::Mouse::setCursorGrabbed(true); } -void GameState::onEvent(const SDL_Event &event) { - if (event.type == SDL_QUIT) { +void GameState::onEvent(const sf::Event &event) { + if (event.type == sf::Event::Closed) { m_client.disconnect(); m_stateStack->clear(); @@ -81,42 +81,41 @@ void GameState::onEvent(const SDL_Event &event) { if (!m_stateStack->empty() && &m_stateStack->top() == this) { gk::KeyboardHandler *keyboardHandler = (gk::KeyboardHandler *)gk::GamePad::getInputHandler(); - 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); + if (event.type == sf::Event::MouseMoved) { + if(Config::screenWidth / 2.0f != event.mouseMove.x || Config::screenHeight / 2.0f != event.mouseMove.y) { + // FIXME: SFML + // m_player.turnH(event.mouseMove.xrel * -0.01 * Config::mouseSensitivity); + // m_player.turnViewV(event.mouseMove.yrel * -0.01 * Config::mouseSensitivity); gk::Mouse::resetToWindowCenter(); } } - else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { m_stateStack->push(m_client, this); } - else if (event.type == SDL_KEYDOWN - && (event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Chat) - || event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Command))) + else if (event.type == sf::Event::KeyPressed + && (event.key.code == keyboardHandler->getKeycode(GameKey::Chat) + || event.key.code == keyboardHandler->getKeycode(GameKey::Command))) { - m_stateStack->push(m_clientCommandHandler, m_hud.chat(), event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Command), this); + m_stateStack->push(m_clientCommandHandler, m_hud.chat(), event.key.code == keyboardHandler->getKeycode(GameKey::Command), this); } - else if (event.type == SDL_WINDOWEVENT) { - if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { - m_stateStack->push(m_client, this); + else if (event.type == sf::Event::LostFocus) { + m_stateStack->push(m_client, this); - gk::Mouse::setCursorGrabbed(false); - gk::Mouse::setCursorVisible(true); - } - else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { - gk::Mouse::setCursorGrabbed(true); - gk::Mouse::setCursorVisible(false); - } + gk::Mouse::setCursorGrabbed(false); + gk::Mouse::setCursorVisible(true); + } + else if (event.type == sf::Event::GainedFocus) { + gk::Mouse::setCursorGrabbed(true); + gk::Mouse::setCursorVisible(false); } m_hud.onEvent(event); } - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - Config::screenWidth = event.window.data1; - Config::screenHeight = event.window.data2; + if (event.type == sf::Event::Resized) { + Config::screenWidth = event.size.width; + Config::screenHeight = event.size.height; m_camera.setAspectRatio((float)Config::screenWidth / Config::screenHeight); m_hud.setup(); diff --git a/source/client/states/GameState.hpp b/source/client/states/GameState.hpp index 52df5c93c..67624157e 100644 --- a/source/client/states/GameState.hpp +++ b/source/client/states/GameState.hpp @@ -51,7 +51,7 @@ class GameState : public gk::ApplicationState { void connect(const std::string &host, int port); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/states/InterfaceState.cpp b/source/client/states/InterfaceState.cpp index f4eb03660..856d862d9 100644 --- a/source/client/states/InterfaceState.cpp +++ b/source/client/states/InterfaceState.cpp @@ -52,18 +52,18 @@ void InterfaceState::setup() { // m_view.setCenter(Config::screenWidth / 2.0f, Config::screenHeight / 2.0f); } -void InterfaceState::onEvent(const SDL_Event &event) { +void InterfaceState::onEvent(const sf::Event &event) { if (m_parent) { m_parent->onEvent(event); } - else if (event.type == SDL_QUIT) { + else if (event.type == sf::Event::Closed) { m_stateStack->clear(); } - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { if (!m_parent) { - Config::screenWidth = event.window.data1; - Config::screenHeight = event.window.data2; + Config::screenWidth = event.size.width; + Config::screenHeight = event.size.height; } setup(); diff --git a/source/client/states/InterfaceState.hpp b/source/client/states/InterfaceState.hpp index b55e44611..5d9072753 100644 --- a/source/client/states/InterfaceState.hpp +++ b/source/client/states/InterfaceState.hpp @@ -37,7 +37,7 @@ class InterfaceState : public gk::ApplicationState { protected: void setup(); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/states/LuaGUIState.cpp b/source/client/states/LuaGUIState.cpp index 24ad10605..a64a9393f 100644 --- a/source/client/states/LuaGUIState.cpp +++ b/source/client/states/LuaGUIState.cpp @@ -64,13 +64,13 @@ LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, Cli loadGUI(packet); } -void LuaGUIState::onEvent(const SDL_Event &event) { +void LuaGUIState::onEvent(const sf::Event &event) { InterfaceState::onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED && m_isCentered) + if (event.type == sf::Event::Resized && m_isCentered) centerMainWidget(); - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { gk::Mouse::setCursorGrabbed(true); gk::Mouse::setCursorVisible(false); gk::Mouse::resetToWindowCenter(); @@ -81,7 +81,7 @@ void LuaGUIState::onEvent(const SDL_Event &event) { for (auto &it : m_widgets) it->onEvent(event); - if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT + if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::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; - gk::Texture &texture = loadTexture(textureFilename); + sf::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; } - gk::Texture &texture = loadTexture(textureFilename); + sf::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; - gk::Texture &texture = loadTexture(textureFilename); + sf::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); } -gk::Texture &LuaGUIState::loadTexture(const std::string &textureFilename) { +sf::Texture &LuaGUIState::loadTexture(const std::string &textureFilename) { auto it = m_textures.find(textureFilename); if (it == m_textures.end()) { - m_textures.emplace(textureFilename, gk::Texture{textureFilename}); + m_textures.emplace(textureFilename, sf::Texture{}).first->second.loadFromFile(textureFilename); return m_textures.at(textureFilename); } else { diff --git a/source/client/states/LuaGUIState.hpp b/source/client/states/LuaGUIState.hpp index 9b3204b8c..9be652ecd 100644 --- a/source/client/states/LuaGUIState.hpp +++ b/source/client/states/LuaGUIState.hpp @@ -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 SDL_Event &event) override; + void onEvent(const sf::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); - gk::Texture &loadTexture(const std::string &textureFilename); + sf::Texture &loadTexture(const std::string &textureFilename); void centerMainWidget(); @@ -76,7 +76,7 @@ class LuaGUIState : public InterfaceState { std::vector> m_widgets; std::vector> m_drawables; std::unordered_map m_inventories; - std::unordered_map m_textures; + std::unordered_map m_textures; ClientPlayer &m_player; ClientWorld &m_world; diff --git a/source/client/states/PauseMenuState.cpp b/source/client/states/PauseMenuState.cpp index 52174a5e6..ab173e013 100644 --- a/source/client/states/PauseMenuState.cpp +++ b/source/client/states/PauseMenuState.cpp @@ -75,10 +75,10 @@ void PauseMenuState::init() { m_eventHandler->addListener(&PauseMenuState::onGuiScaleChanged, this); } -void PauseMenuState::onEvent(const SDL_Event &event) { +void PauseMenuState::onEvent(const sf::Event &event) { InterfaceState::onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { if (!m_stateStack->empty() && &m_stateStack->top() != this) m_menuWidget.onEvent(event); } @@ -86,7 +86,7 @@ void PauseMenuState::onEvent(const SDL_Event &event) { if (!m_stateStack->empty() && &m_stateStack->top() == this) { m_menuWidget.onEvent(event); - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { gk::Mouse::setCursorGrabbed(true); gk::Mouse::setCursorVisible(false); gk::Mouse::resetToWindowCenter(); diff --git a/source/client/states/PauseMenuState.hpp b/source/client/states/PauseMenuState.hpp index 5476d1593..24137856f 100644 --- a/source/client/states/PauseMenuState.hpp +++ b/source/client/states/PauseMenuState.hpp @@ -41,7 +41,7 @@ class PauseMenuState : public InterfaceState { void init() override; - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; private: void onGuiScaleChanged(const GuiScaleChangedEvent &event); diff --git a/source/client/states/ServerConnectState.cpp b/source/client/states/ServerConnectState.cpp index 6869f678d..f445b928f 100644 --- a/source/client/states/ServerConnectState.cpp +++ b/source/client/states/ServerConnectState.cpp @@ -89,10 +89,10 @@ ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : Interface m_errorText.setScale(Config::guiScale, Config::guiScale); } -void ServerConnectState::onEvent(const SDL_Event &event) { +void ServerConnectState::onEvent(const sf::Event &event) { InterfaceState::onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { m_textInput.setPosition(Config::screenWidth / 2.0f - m_textInput.getBackgroundSize().x * Config::guiScale / 2.0f, Config::screenHeight / 2.0f - m_textInput.getBackgroundSize().y * Config::guiScale / 2.0f); diff --git a/source/client/states/ServerConnectState.hpp b/source/client/states/ServerConnectState.hpp index 88f93a6ad..94ade3686 100644 --- a/source/client/states/ServerConnectState.hpp +++ b/source/client/states/ServerConnectState.hpp @@ -35,7 +35,7 @@ class ServerConnectState : public InterfaceState { public: ServerConnectState(gk::ApplicationState *parent = nullptr); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/states/ServerLoadingState.cpp b/source/client/states/ServerLoadingState.cpp index da95d36a2..1ccb8d84b 100644 --- a/source/client/states/ServerLoadingState.cpp +++ b/source/client/states/ServerLoadingState.cpp @@ -54,10 +54,10 @@ void ServerLoadingState::centerText() { Config::screenHeight / 2 - m_text.getSize().y * Config::guiScale * 2 / 2); } -void ServerLoadingState::onEvent(const SDL_Event &event) { +void ServerLoadingState::onEvent(const sf::Event &event) { InterfaceState::onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { centerText(); } } diff --git a/source/client/states/ServerLoadingState.hpp b/source/client/states/ServerLoadingState.hpp index 02639457c..31de3f8c5 100644 --- a/source/client/states/ServerLoadingState.hpp +++ b/source/client/states/ServerLoadingState.hpp @@ -38,7 +38,7 @@ class ServerLoadingState : public InterfaceState { void centerText(); - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/states/SettingsMenuState.cpp b/source/client/states/SettingsMenuState.cpp index 4b901a5a8..880964d9f 100644 --- a/source/client/states/SettingsMenuState.cpp +++ b/source/client/states/SettingsMenuState.cpp @@ -59,10 +59,10 @@ void SettingsMenuState::init() { m_eventHandler->addListener(&SettingsMenuState::onGuiScaleChanged, this); } -void SettingsMenuState::onEvent(const SDL_Event &event) { +void SettingsMenuState::onEvent(const sf::Event &event) { InterfaceState::onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { updateDoneButtonPosition(); if (&m_stateStack->top() != this) @@ -73,12 +73,12 @@ void SettingsMenuState::onEvent(const SDL_Event &event) { m_menuWidget.onEvent(event); m_doneButton.onEvent(event); - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { doneButtonAction(); } - else if (m_currentKeyButton && event.type == SDL_KEYDOWN) { + else if (m_currentKeyButton && event.type == sf::Event::KeyPressed) { gk::KeyboardHandler *keyboardHandler = (gk::KeyboardHandler *)gk::GamePad::getInputHandler(); - keyboardHandler->setKeycode(m_currentKey, event.key.keysym.sym); + keyboardHandler->setKeycode(m_currentKey, event.key.code); m_currentKeyButton->setText(m_currentKeyButton->text() + keyboardHandler->getKeyName(m_currentKey)); m_currentKeyButton = nullptr; diff --git a/source/client/states/SettingsMenuState.hpp b/source/client/states/SettingsMenuState.hpp index 9c2a3febe..ed6a4c3f1 100644 --- a/source/client/states/SettingsMenuState.hpp +++ b/source/client/states/SettingsMenuState.hpp @@ -41,7 +41,7 @@ class SettingsMenuState : public InterfaceState { void init() override; - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; private: void onGuiScaleChanged(const GuiScaleChangedEvent &event); diff --git a/source/client/states/TitleScreenState.cpp b/source/client/states/TitleScreenState.cpp index db27db511..19195640e 100644 --- a/source/client/states/TitleScreenState.cpp +++ b/source/client/states/TitleScreenState.cpp @@ -74,10 +74,10 @@ void TitleScreenState::init() { m_eventHandler->addListener(&TitleScreenState::onServerOnlineEvent, this); } -void TitleScreenState::onEvent(const SDL_Event &event) { +void TitleScreenState::onEvent(const sf::Event &event) { InterfaceState::onEvent(event); - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (event.type == sf::Event::Resized) { centerBackground(); if (!m_stateStack->empty() && &m_stateStack->top() != this) diff --git a/source/client/states/TitleScreenState.hpp b/source/client/states/TitleScreenState.hpp index 36c1d264b..a3621cffa 100644 --- a/source/client/states/TitleScreenState.hpp +++ b/source/client/states/TitleScreenState.hpp @@ -44,7 +44,7 @@ class TitleScreenState : public InterfaceState { void init() override; - void onEvent(const SDL_Event &event) override; + void onEvent(const sf::Event &event) override; void update() override; diff --git a/source/client/world/ClientChunk.cpp b/source/client/world/ClientChunk.cpp index 317985fbc..7f3c0e5d7 100644 --- a/source/client/world/ClientChunk.cpp +++ b/source/client/world/ClientChunk.cpp @@ -48,9 +48,9 @@ void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u else glCheck(glEnable(GL_CULL_FACE)); - gk::Texture::bind(states.texture); + sf::Texture::bind(states.texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, (layer == ChunkBuilder::Layer::NoMipMap || layer == ChunkBuilder::Layer::Flora) ? 0 : Config::mipmapLevels); - gk::Texture::bind(nullptr); + sf::Texture::bind(nullptr); glCheck(glEnable(GL_DEPTH_TEST)); diff --git a/source/client/world/ClientChunk.hpp b/source/client/world/ClientChunk.hpp index 8d0bf8d7b..b9708a5e2 100644 --- a/source/client/world/ClientChunk.hpp +++ b/source/client/world/ClientChunk.hpp @@ -28,7 +28,6 @@ #define CLIENTCHUNK_HPP_ #include -#include #include "Chunk.hpp" #include "ChunkBuilder.hpp" diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index 0377c903d..aae2afa10 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -18,7 +18,7 @@ endforeach(HEADER_FILE) # Add library #------------------------------------------------------------------------------ add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES}) -add_dependencies(${PROJECT_NAME} zlib EnTT sfml-network gamekit) +add_dependencies(${PROJECT_NAME} zlib EnTT gamekit) #------------------------------------------------------------------------------ # Compiler flags diff --git a/source/common/resource/TextureLoader.cpp b/source/common/resource/TextureLoader.cpp index c69bab59e..b67e358e6 100644 --- a/source/common/resource/TextureLoader.cpp +++ b/source/common/resource/TextureLoader.cpp @@ -24,9 +24,10 @@ * * ===================================================================================== */ +#include + #include #include -#include #include #include "TextureLoader.hpp" @@ -39,14 +40,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("texture-" + name); + auto &texture = handler.add("texture-" + name); texture.loadFromFile(path); - // gk::Texture::bind(&texture); + // sf::Texture::bind(&texture); // glGenerateMipmap(GL_TEXTURE_2D); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); - // gk::Texture::bind(nullptr); + // sf::Texture::bind(nullptr); textureElement = textureElement->NextSiblingElement("texture"); } diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt index 64c3918c4..4497b8a9e 100644 --- a/source/server/CMakeLists.txt +++ b/source/server/CMakeLists.txt @@ -71,10 +71,6 @@ target_link_libraries(${PROJECT_NAME} ${CMAKE_PROJECT_NAME}_common gamekit ${OPENGL_LIBRARIES} - ${SDL2_LIBRARIES} - ${SDL2_IMAGE_LIBRARIES} - ${SDL2_MIXER_LIBRARIES} - ${SDL2_TTF_LIBRARIES} ${TINYXML2_LIBRARIES} ${GLEW_LIBRARIES} ${LUA_LIBRARIES}