added custom caption to items. fixed glyph render.
This commit is contained in:
@@ -57,6 +57,14 @@ static inline void draw_glyph(
|
|||||||
const FontStyle& style
|
const FontStyle& style
|
||||||
) {
|
) {
|
||||||
for (int i = 0; i <= style.bold; i++) {
|
for (int i = 0; i <= style.bold; i++) {
|
||||||
|
glm::vec4 color;
|
||||||
|
|
||||||
|
if (style.color == glm::vec4(1, 1, 1, 1)) {
|
||||||
|
color = batch.getColor();
|
||||||
|
} else {
|
||||||
|
color = style.color;
|
||||||
|
}
|
||||||
|
|
||||||
batch.sprite(
|
batch.sprite(
|
||||||
pos.x + (offset.x + i / (right.x/glyphInterval/2.0f)) * right.x,
|
pos.x + (offset.x + i / (right.x/glyphInterval/2.0f)) * right.x,
|
||||||
pos.y + offset.y * right.y,
|
pos.y + offset.y * right.y,
|
||||||
@@ -65,7 +73,7 @@ static inline void draw_glyph(
|
|||||||
-0.15f * style.italic,
|
-0.15f * style.italic,
|
||||||
16,
|
16,
|
||||||
c,
|
c,
|
||||||
batch.getColor() * style.color
|
color
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +89,15 @@ static inline void draw_glyph(
|
|||||||
const FontStyle& style
|
const FontStyle& style
|
||||||
) {
|
) {
|
||||||
for (int i = 0; i <= style.bold; i++) {
|
for (int i = 0; i <= style.bold; i++) {
|
||||||
|
glm::vec4 color;
|
||||||
|
|
||||||
|
if (style.color == glm::vec4(1, 1, 1, 1)) {
|
||||||
|
color = batch.getColor();
|
||||||
|
} else {
|
||||||
|
color = style.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
batch.sprite(
|
batch.sprite(
|
||||||
pos + right * (offset.x + i) + up * offset.y,
|
pos + right * (offset.x + i) + up * offset.y,
|
||||||
up, right / glyphInterval,
|
up, right / glyphInterval,
|
||||||
@@ -88,7 +105,7 @@ static inline void draw_glyph(
|
|||||||
0.5f,
|
0.5f,
|
||||||
16,
|
16,
|
||||||
c,
|
c,
|
||||||
batch.getColor() * style.color
|
color
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ GUI::GUI(Engine& engine)
|
|||||||
tooltip = guiutil::create(
|
tooltip = guiutil::create(
|
||||||
*this,
|
*this,
|
||||||
"<container color='#000000A0' interactive='false' z-index='999'>"
|
"<container color='#000000A0' interactive='false' z-index='999'>"
|
||||||
"<label id='tooltip.label' pos='2' autoresize='true' multiline='true' text-wrap='false'></label>"
|
"<label id='tooltip.label' markup='md' pos='2' autoresize='true' multiline='true' text-wrap='false'></label>"
|
||||||
"</container>"
|
"</container>"
|
||||||
);
|
);
|
||||||
store("tooltip", tooltip);
|
store("tooltip", tooltip);
|
||||||
|
|||||||
@@ -1,10 +1,21 @@
|
|||||||
#include "InventoryView.hpp"
|
#include "InventoryView.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
#include "assets/assets_util.hpp"
|
#include "assets/assets_util.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "frontend/LevelFrontend.hpp"
|
#include "frontend/LevelFrontend.hpp"
|
||||||
#include "frontend/locale.hpp"
|
#include "frontend/locale.hpp"
|
||||||
|
#include "graphics/core/Atlas.hpp"
|
||||||
|
#include "graphics/core/Batch2D.hpp"
|
||||||
|
#include "graphics/core/DrawContext.hpp"
|
||||||
|
#include "graphics/core/Font.hpp"
|
||||||
|
#include "graphics/core/Shader.hpp"
|
||||||
|
#include "graphics/core/Texture.hpp"
|
||||||
|
#include "graphics/render/BlocksPreview.hpp"
|
||||||
|
#include "graphics/ui/GUI.hpp"
|
||||||
#include "items/Inventories.hpp"
|
#include "items/Inventories.hpp"
|
||||||
#include "items/Inventory.hpp"
|
#include "items/Inventory.hpp"
|
||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
@@ -15,17 +26,6 @@
|
|||||||
#include "voxels/Block.hpp"
|
#include "voxels/Block.hpp"
|
||||||
#include "window/input.hpp"
|
#include "window/input.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "graphics/core/Atlas.hpp"
|
|
||||||
#include "graphics/core/Batch2D.hpp"
|
|
||||||
#include "graphics/core/Font.hpp"
|
|
||||||
#include "graphics/core/DrawContext.hpp"
|
|
||||||
#include "graphics/core/Shader.hpp"
|
|
||||||
#include "graphics/core/Texture.hpp"
|
|
||||||
#include "graphics/render/BlocksPreview.hpp"
|
|
||||||
#include "graphics/ui/GUI.hpp"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
@@ -37,21 +37,24 @@ SlotLayout::SlotLayout(
|
|||||||
slotcallback updateFunc,
|
slotcallback updateFunc,
|
||||||
slotcallback shareFunc,
|
slotcallback shareFunc,
|
||||||
slotcallback rightClick
|
slotcallback rightClick
|
||||||
) : index(index),
|
)
|
||||||
position(position),
|
: index(index),
|
||||||
background(background),
|
position(position),
|
||||||
itemSource(itemSource),
|
background(background),
|
||||||
updateFunc(std::move(updateFunc)),
|
itemSource(itemSource),
|
||||||
shareFunc(std::move(shareFunc)),
|
updateFunc(std::move(updateFunc)),
|
||||||
rightClick(std::move(rightClick)) {}
|
shareFunc(std::move(shareFunc)),
|
||||||
|
rightClick(std::move(rightClick)) {
|
||||||
|
}
|
||||||
|
|
||||||
InventoryBuilder::InventoryBuilder(GUI& gui) : gui(gui) {
|
InventoryBuilder::InventoryBuilder(GUI& gui) : gui(gui) {
|
||||||
view = std::make_shared<InventoryView>(gui);
|
view = std::make_shared<InventoryView>(gui);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryBuilder::addGrid(
|
void InventoryBuilder::addGrid(
|
||||||
int cols, int count,
|
int cols,
|
||||||
glm::vec2 pos,
|
int count,
|
||||||
|
glm::vec2 pos,
|
||||||
glm::vec4 padding,
|
glm::vec4 padding,
|
||||||
bool addpanel,
|
bool addpanel,
|
||||||
const SlotLayout& slotLayout
|
const SlotLayout& slotLayout
|
||||||
@@ -61,9 +64,11 @@ void InventoryBuilder::addGrid(
|
|||||||
|
|
||||||
int rows = ceildiv(count, cols);
|
int rows = ceildiv(count, cols);
|
||||||
|
|
||||||
uint width = cols * (slotSize + interval) - interval + padding.x + padding.z;
|
uint width =
|
||||||
uint height = rows * (slotSize + interval) - interval + padding.y + padding.w;
|
cols * (slotSize + interval) - interval + padding.x + padding.z;
|
||||||
|
uint height =
|
||||||
|
rows * (slotSize + interval) - interval + padding.y + padding.w;
|
||||||
|
|
||||||
glm::vec2 vsize = view->getSize();
|
glm::vec2 vsize = view->getSize();
|
||||||
if (pos.x + width > vsize.x) {
|
if (pos.x + width > vsize.x) {
|
||||||
vsize.x = pos.x + width;
|
vsize.x = pos.x + width;
|
||||||
@@ -85,7 +90,7 @@ void InventoryBuilder::addGrid(
|
|||||||
if (row * cols + col >= count) {
|
if (row * cols + col >= count) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
glm::vec2 position (
|
glm::vec2 position(
|
||||||
col * (slotSize + interval) + padding.x,
|
col * (slotSize + interval) + padding.x,
|
||||||
row * (slotSize + interval) + padding.y
|
row * (slotSize + interval) + padding.y
|
||||||
);
|
);
|
||||||
@@ -105,11 +110,9 @@ std::shared_ptr<InventoryView> InventoryBuilder::build() {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlotView::SlotView(
|
SlotView::SlotView(GUI& gui, SlotLayout layout)
|
||||||
GUI& gui, SlotLayout layout
|
: UINode(gui, glm::vec2(InventoryView::SLOT_SIZE)),
|
||||||
) : UINode(gui, glm::vec2(InventoryView::SLOT_SIZE)),
|
layout(std::move(layout)) {
|
||||||
layout(std::move(layout))
|
|
||||||
{
|
|
||||||
setColor(glm::vec4(0, 0, 0, 0.2f));
|
setColor(glm::vec4(0, 0, 0, 0.2f));
|
||||||
setTooltipDelay(0.0f);
|
setTooltipDelay(0.0f);
|
||||||
}
|
}
|
||||||
@@ -120,9 +123,16 @@ void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (itemid) {
|
if (itemid) {
|
||||||
tooltip = util::pascal_case(
|
dv::value* caption = stack.getField("caption");
|
||||||
langs::get(util::str2wstr_utf8(item.caption))
|
if (caption != nullptr) {
|
||||||
);
|
tooltip = util::pascal_case(
|
||||||
|
langs::get(util::str2wstr_utf8(caption->asString()))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
tooltip = util::pascal_case(
|
||||||
|
langs::get(util::str2wstr_utf8(item.caption))
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tooltip.clear();
|
tooltip.clear();
|
||||||
}
|
}
|
||||||
@@ -148,19 +158,37 @@ void SlotView::drawItemIcon(
|
|||||||
|
|
||||||
UVRegion region = previews.get(block.name);
|
UVRegion region = previews.get(block.name);
|
||||||
batch.rect(
|
batch.rect(
|
||||||
pos.x, pos.y, SLOT_SIZE, SLOT_SIZE,
|
pos.x,
|
||||||
0, 0, 0, region, false, true, tint
|
pos.y,
|
||||||
|
SLOT_SIZE,
|
||||||
|
SLOT_SIZE,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
region,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
tint
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemIconType::SPRITE: {
|
case ItemIconType::SPRITE: {
|
||||||
auto textureRegion =
|
auto textureRegion =
|
||||||
util::get_texture_region(assets, item.icon, "blocks:notfound");
|
util::get_texture_region(assets, item.icon, "blocks:notfound");
|
||||||
|
|
||||||
batch.texture(textureRegion.texture);
|
batch.texture(textureRegion.texture);
|
||||||
batch.rect(
|
batch.rect(
|
||||||
pos.x, pos.y, SLOT_SIZE, SLOT_SIZE,
|
pos.x,
|
||||||
0, 0, 0, textureRegion.region, false, true, tint
|
pos.y,
|
||||||
|
SLOT_SIZE,
|
||||||
|
SLOT_SIZE,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
textureRegion.region,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
tint
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -184,7 +212,7 @@ void SlotView::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
glm::vec4 tint(1, 1, 1, isEnabled() ? 1 : 0.5f);
|
glm::vec4 tint(1, 1, 1, isEnabled() ? 1 : 0.5f);
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec4 color = getColor();
|
glm::vec4 color = getColor();
|
||||||
|
|
||||||
if (hover || highlighted) {
|
if (hover || highlighted) {
|
||||||
tint *= 1.333f;
|
tint *= 1.333f;
|
||||||
color = glm::vec4(1, 1, 1, 0.2f);
|
color = glm::vec4(1, 1, 1, 0.2f);
|
||||||
@@ -262,7 +290,7 @@ void SlotView::drawItemInfo(
|
|||||||
batch.setColor({0, 0, 0, 0.75f});
|
batch.setColor({0, 0, 0, 0.75f});
|
||||||
batch.rect(pos.x - 2, pos.y - 2, 6, SLOT_SIZE + 4);
|
batch.rect(pos.x - 2, pos.y - 2, 6, SLOT_SIZE + 4);
|
||||||
float t = static_cast<float>(uses) / item.uses;
|
float t = static_cast<float>(uses) / item.uses;
|
||||||
|
|
||||||
int height = SLOT_SIZE * t;
|
int height = SLOT_SIZE * t;
|
||||||
batch.setColor({(1.0f - t * 0.8f), 0.4f, t * 0.8f + 0.2f, 1.0f});
|
batch.setColor({(1.0f - t * 0.8f), 0.4f, t * 0.8f + 0.2f, 1.0f});
|
||||||
batch.rect(pos.x, pos.y + SLOT_SIZE - height, 2, height);
|
batch.rect(pos.x, pos.y + SLOT_SIZE - height, 2, height);
|
||||||
@@ -317,8 +345,7 @@ void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (layout.itemSource)
|
if (layout.itemSource) return;
|
||||||
return;
|
|
||||||
if (grabbed.isEmpty()) {
|
if (grabbed.isEmpty()) {
|
||||||
if (!stack.isEmpty() && layout.taking) {
|
if (!stack.isEmpty() && layout.taking) {
|
||||||
grabbed.set(std::move(stack));
|
grabbed.set(std::move(stack));
|
||||||
@@ -342,15 +369,15 @@ void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
|||||||
} else {
|
} else {
|
||||||
grabbed = ItemStack(stack.getItemId(), count - 1);
|
grabbed = ItemStack(stack.getItemId(), count - 1);
|
||||||
}
|
}
|
||||||
} else if (stack.accepts(grabbed) && stack.getCount() < stackDef.stackSize) {
|
} else if (stack.accepts(grabbed) &&
|
||||||
|
stack.getCount() < stackDef.stackSize) {
|
||||||
stack.setCount(stack.getCount() + 1);
|
stack.setCount(stack.getCount() + 1);
|
||||||
grabbed.setCount(grabbed.getCount() - 1);
|
grabbed.setCount(grabbed.getCount() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlotView::clicked(Mousecode button) {
|
void SlotView::clicked(Mousecode button) {
|
||||||
if (bound == nullptr)
|
if (bound == nullptr) return;
|
||||||
return;
|
|
||||||
auto exchangeSlot =
|
auto exchangeSlot =
|
||||||
std::dynamic_pointer_cast<SlotView>(gui.get(EXCHANGE_SLOT_NAME));
|
std::dynamic_pointer_cast<SlotView>(gui.get(EXCHANGE_SLOT_NAME));
|
||||||
if (exchangeSlot == nullptr) {
|
if (exchangeSlot == nullptr) {
|
||||||
@@ -358,7 +385,7 @@ void SlotView::clicked(Mousecode button) {
|
|||||||
}
|
}
|
||||||
ItemStack& grabbed = exchangeSlot->getStack();
|
ItemStack& grabbed = exchangeSlot->getStack();
|
||||||
ItemStack& stack = *bound;
|
ItemStack& stack = *bound;
|
||||||
|
|
||||||
if (button == Mousecode::BUTTON_1) {
|
if (button == Mousecode::BUTTON_1) {
|
||||||
performLeftClick(stack, grabbed);
|
performLeftClick(stack, grabbed);
|
||||||
} else if (button == Mousecode::BUTTON_2) {
|
} else if (button == Mousecode::BUTTON_2) {
|
||||||
@@ -382,9 +409,7 @@ const std::wstring& SlotView::getTooltip() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SlotView::bind(
|
void SlotView::bind(
|
||||||
int64_t inventoryid,
|
int64_t inventoryid, ItemStack& stack, const Content* content
|
||||||
ItemStack& stack,
|
|
||||||
const Content* content
|
|
||||||
) {
|
) {
|
||||||
this->inventoryid = inventoryid;
|
this->inventoryid = inventoryid;
|
||||||
bound = &stack;
|
bound = &stack;
|
||||||
@@ -403,11 +428,11 @@ InventoryView::InventoryView(GUI& gui) : Container(gui, glm::vec2()) {
|
|||||||
setColor(glm::vec4(0, 0, 0, 0.0f));
|
setColor(glm::vec4(0, 0, 0, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryView::~InventoryView() {}
|
InventoryView::~InventoryView() {
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<SlotView> InventoryView::addSlot(const SlotLayout& layout) {
|
std::shared_ptr<SlotView> InventoryView::addSlot(const SlotLayout& layout) {
|
||||||
uint width = InventoryView::SLOT_SIZE + layout.padding;
|
uint width = InventoryView::SLOT_SIZE + layout.padding;
|
||||||
uint height = InventoryView::SLOT_SIZE + layout.padding;
|
uint height = InventoryView::SLOT_SIZE + layout.padding;
|
||||||
|
|
||||||
auto pos = layout.position;
|
auto pos = layout.position;
|
||||||
@@ -432,14 +457,12 @@ std::shared_ptr<Inventory> InventoryView::getInventory() const {
|
|||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t InventoryView::getSlotsCount() const {
|
size_t InventoryView::getSlotsCount() const {
|
||||||
return slots.size();
|
return slots.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryView::bind(
|
void InventoryView::bind(
|
||||||
const std::shared_ptr<Inventory>& inventory,
|
const std::shared_ptr<Inventory>& inventory, const Content* content
|
||||||
const Content* content
|
|
||||||
) {
|
) {
|
||||||
this->inventory = inventory;
|
this->inventory = inventory;
|
||||||
this->content = content;
|
this->content = content;
|
||||||
|
|||||||
Reference in New Issue
Block a user