[LuaGUIState] Textures are now loaded from a path given by mods.
@ -26,7 +26,7 @@
|
||||
*/
|
||||
#include "ProgressBarWidget.hpp"
|
||||
|
||||
ProgressBarWidget::ProgressBarWidget(const std::string &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;
|
||||
|
@ -40,7 +40,7 @@ enum class ProgressBarType : u8 {
|
||||
|
||||
class ProgressBarWidget : public Widget {
|
||||
public:
|
||||
ProgressBarWidget(const std::string &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);
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "Config.hpp"
|
||||
#include "ScrollBarWidget.hpp"
|
||||
|
||||
void ScrollBarWidget::init(const std::string &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;
|
||||
|
@ -35,7 +35,7 @@ class ScrollBarWidget : public Widget {
|
||||
public:
|
||||
ScrollBarWidget(Widget *parent = nullptr) : Widget(12, 15, parent) {}
|
||||
|
||||
void init(const std::string &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 SDL_Event &event);
|
||||
|
||||
|
@ -198,9 +198,11 @@ void LuaGUIState::loadGUI(sf::Packet &packet) {
|
||||
}
|
||||
|
||||
void LuaGUIState::loadImage(const std::string &, s32 x, s32 y, sf::Packet &packet) {
|
||||
std::string texture;
|
||||
std::string textureFilename;
|
||||
gk::FloatRect clipRect;
|
||||
packet >> texture >> clipRect.x >> clipRect.y >> clipRect.sizeX >> clipRect.sizeY;
|
||||
packet >> textureFilename >> clipRect.x >> clipRect.y >> clipRect.sizeX >> clipRect.sizeY;
|
||||
|
||||
gk::Texture &texture = loadTexture(textureFilename);
|
||||
|
||||
auto *image = new gk::Image(texture);
|
||||
image->setPosition(x, y);
|
||||
@ -310,9 +312,9 @@ void LuaGUIState::loadProgressBarWidget(const std::string &, s32 x, s32 y, sf::P
|
||||
gk::Vector3i block;
|
||||
std::string meta, maxMeta;
|
||||
u32 maxValue;
|
||||
std::string texture;
|
||||
std::string textureFilename;
|
||||
gk::FloatRect clipRect;
|
||||
packet >> type >> block.x >> block.y >> block.z >> meta >> maxMeta >> maxValue >> texture
|
||||
packet >> type >> block.x >> block.y >> block.z >> meta >> maxMeta >> maxValue >> textureFilename
|
||||
>> clipRect.x >> clipRect.y >> clipRect.sizeX >> clipRect.sizeY;
|
||||
|
||||
BlockData *data = m_world.getBlockData(block.x, block.y, block.z);
|
||||
@ -321,6 +323,8 @@ void LuaGUIState::loadProgressBarWidget(const std::string &, s32 x, s32 y, sf::P
|
||||
return;
|
||||
}
|
||||
|
||||
gk::Texture &texture = loadTexture(textureFilename);
|
||||
|
||||
ProgressBarWidget *widget = new ProgressBarWidget(texture, *data, ProgressBarType(type));
|
||||
if (!maxMeta.empty())
|
||||
widget->init(clipRect, gk::Vector2i{x, y}, meta, maxMeta);
|
||||
@ -331,11 +335,13 @@ void LuaGUIState::loadProgressBarWidget(const std::string &, s32 x, s32 y, sf::P
|
||||
}
|
||||
|
||||
void LuaGUIState::loadScrollBarWidget(const std::string &, s32 x, s32 y, sf::Packet &packet) {
|
||||
std::string texture;
|
||||
std::string textureFilename;
|
||||
gk::FloatRect clipRect;
|
||||
u16 minY, maxY;
|
||||
std::string widget;
|
||||
packet >> texture >> clipRect >> minY >> maxY >> widget;
|
||||
packet >> textureFilename >> clipRect >> minY >> maxY >> widget;
|
||||
|
||||
gk::Texture &texture = loadTexture(textureFilename);
|
||||
|
||||
ScrollBarWidget *scrollBarWidget = new ScrollBarWidget(&m_mainWidget);
|
||||
scrollBarWidget->setPosition(x, y);
|
||||
@ -350,6 +356,17 @@ void LuaGUIState::loadInventory(const std::string &name, sf::Packet &packet) {
|
||||
packet >> m_inventories.at(name);
|
||||
}
|
||||
|
||||
gk::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});
|
||||
return m_textures.at(textureFilename);
|
||||
}
|
||||
else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaGUIState::centerMainWidget() {
|
||||
int x = floor(Config::screenWidth / 2.0f - m_width * Config::guiScale / 2.0f + 0.5f);
|
||||
int y = floor(Config::screenHeight / 2.0f - m_height * Config::guiScale / 2.0f + 0.5f);
|
||||
|
@ -60,6 +60,8 @@ 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);
|
||||
|
||||
void centerMainWidget();
|
||||
|
||||
ClientCommandHandler &m_client;
|
||||
@ -74,6 +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, gk::Texture> m_textures;
|
||||
|
||||
ClientPlayer &m_player;
|
||||
ClientWorld &m_world;
|
||||
|
@ -42,7 +42,7 @@ function show_creative_window(client, screen_width, screen_height, gui_scale)
|
||||
name = "img_background",
|
||||
pos = {x = 0, y = 0},
|
||||
|
||||
texture = "texture-creative_window",
|
||||
texture = "mods/default/textures/gui/creative_window.png",
|
||||
clip = {x = 0, y = 0, width = 195, height = 136},
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ function show_creative_window(client, screen_width, screen_height, gui_scale)
|
||||
name = "scroll_bar",
|
||||
pos = {x = 175, y = 18},
|
||||
|
||||
texture = "texture-tabs",
|
||||
texture = "mods/default/textures/gui/tabs.png",
|
||||
clip = {x = 232, y = 0, width = 12, height = 15},
|
||||
clip_selected = {x = 244, y = 0, width = 12, height = 15},
|
||||
|
||||
|
@ -53,7 +53,7 @@ mod:block {
|
||||
meta = "item_progress",
|
||||
max_value = 200,
|
||||
|
||||
texture = "texture-furnace",
|
||||
texture = "mods/default/textures/gui/furnace.png",
|
||||
clip = {x = 176, y = 14, width = 24, height = 17},
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ mod:block {
|
||||
meta = "ticks_remaining",
|
||||
max_meta = "current_burn_time",
|
||||
|
||||
texture = "texture-furnace",
|
||||
texture = "mods/default/textures/gui/furnace.png",
|
||||
clip = {x = 176, y = 0, width = 14, height = 14},
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ mod:block {
|
||||
name = "img_background",
|
||||
pos = {x = 0, y = 0},
|
||||
|
||||
texture = "texture-furnace",
|
||||
texture = "mods/default/textures/gui/furnace.png",
|
||||
clip = {x = 0, y = 0, width = 176, height = 166},
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ function show_inventory(client, screen_width, screen_height, gui_scale)
|
||||
name = "img_background",
|
||||
pos = {x = 0, y = 0},
|
||||
|
||||
texture = "texture-inventory",
|
||||
texture = "mods/default/textures/gui/inventory.png",
|
||||
clip = {x = 0, y = 0, width = 176, height = 166},
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 1005 B After Width: | Height: | Size: 1005 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
BIN
mods/default/textures_mc/gui/creative_window.png
Normal file
After Width: | Height: | Size: 1005 B |
BIN
mods/default/textures_mc/gui/furnace.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
mods/default/textures_mc/gui/inventory.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
mods/default/textures_mc/gui/tabs.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
mods/default/textures_mc/gui/workbench.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
@ -83,7 +83,7 @@ mod:block {
|
||||
name = "img_background",
|
||||
pos = {x = 0, y = 0},
|
||||
|
||||
texture = "texture-workbench",
|
||||
texture = "mods/default/textures/gui/workbench.png",
|
||||
clip = {x = 0, y = 0, width = 176, height = 166},
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
<textures>
|
||||
<texture name="block_destroy" path="resources/textures/block_destroy.png" />
|
||||
<texture name="creative_window" path="resources/textures/creative_window.png" />
|
||||
<texture name="font" path="resources/textures/font.png" />
|
||||
<texture name="furnace" path="resources/textures/furnace.png" />
|
||||
<texture name="inventory" path="resources/textures/inventory.png" />
|
||||
<texture name="tabs" path="resources/textures/tabs.png" />
|
||||
<texture name="toasts" path="resources/textures/toasts.png" />
|
||||
<texture name="title_screen" path="resources/textures/title_screen.png" />
|
||||
<texture name="widgets" path="resources/textures/widgets.png" />
|
||||
<texture name="workbench" path="resources/textures/workbench.png" />
|
||||
<texture name="player" path="resources/textures/player.png" />
|
||||
</textures>
|
||||
|