mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
* build: replace FetchContent with direct includes for glm * build(deps): replace SOIL2 with stb for image and vorbis decoding * build: replace FetchContent with direct includes for toml++ * refactor(texture): bump block texture size to 512 and disable items tab * feat: add hotbar system with ItemStack and RowLayout * fix(ui): restrict Ctrl key handling to typing mode * feat(ui): add widget border support and highlight selected hotbar slot * fix(ui): update borders on scale change and correct Image width - Added update_border() calls in set_scale() for Button, ChatBox, Image, Label, and TextField. - Fixed Image::width() to multiply by width instead of height. - Added early return in Widget::update_border() if border is not supported. * feat(ui): add border visual feedback on slider drag * feat(ui): add ItemSlot widget and refactor hotbar to use it * feat(world_scene): add inventory UI and pause type enum * feat(ui): add item slot tooltip and make window size static * fix(ui label): account for background offset in width/height * refactor(ui): centralize item info label in inventory and add update * feat(ui): add hotbar interaction in inventory UI * fix(inventory-ui): correct row creation logic for first item The loop starting at index 0 created a new row on the first iteration (i % 10 == 0). Shift the loop to start at 1 and adjust modulus condition to create rows correctly every 10 items. * feat(block): add name_key for localized block names Add `name_key` field to all block TOML definitions, enabling per-block localization. Update `BlockData` struct and `BlockManager` with `local_name()` method that returns a localized string via the translation system. Add corresponding entries to `en_US.json` and `zh_CN.json`. Modify inventory UI to use the localized name when displaying block info, and fix a bug where emptying a hotbar slot did not clear the item locally. * fix(ui): change inventory item slot color from white to gray * fix(ui): add missing include for std::array
454 lines
12 KiB
C++
454 lines
12 KiB
C++
/// @ref gtx_io
|
|
/// @author Jan P Springer (regnirpsj@gmail.com)
|
|
|
|
#include <iomanip> // std::fixed, std::setfill<>, std::setprecision, std::right, std::setw
|
|
#include <ostream> // std::basic_ostream<>
|
|
#include "../gtc/matrix_access.hpp" // glm::col, glm::row
|
|
#include "../gtx/type_trait.hpp" // glm::type<>
|
|
|
|
#if GLM_COMPILER & GLM_COMPILER_CLANG
|
|
# pragma clang diagnostic push
|
|
# pragma clang diagnostic ignored "-Wpadded"
|
|
# pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
|
# pragma clang diagnostic ignored "-Wglobal-constructors"
|
|
#endif
|
|
|
|
namespace glm{
|
|
namespace io
|
|
{
|
|
template<typename CTy>
|
|
GLM_FUNC_QUALIFIER format_punct<CTy>::format_punct(size_t a)
|
|
: std::locale::facet(a)
|
|
, formatted(true)
|
|
, precision(3)
|
|
, width(1 + 4 + 1 + precision)
|
|
, separator(',')
|
|
, delim_left('[')
|
|
, delim_right(']')
|
|
, space(' ')
|
|
, newline('\n')
|
|
, order(column_major)
|
|
{}
|
|
|
|
template<typename CTy>
|
|
GLM_FUNC_QUALIFIER format_punct<CTy>::format_punct(format_punct const& a)
|
|
: std::locale::facet(0)
|
|
, formatted(a.formatted)
|
|
, precision(a.precision)
|
|
, width(a.width)
|
|
, separator(a.separator)
|
|
, delim_left(a.delim_left)
|
|
, delim_right(a.delim_right)
|
|
, space(a.space)
|
|
, newline(a.newline)
|
|
, order(a.order)
|
|
{}
|
|
|
|
template<typename CTy> std::locale::id format_punct<CTy>::id;
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::basic_state_saver(std::basic_ios<CTy, CTr>& a)
|
|
: state_(a)
|
|
, flags_(a.flags())
|
|
, precision_(a.precision())
|
|
, width_(a.width())
|
|
, fill_(a.fill())
|
|
, locale_(a.getloc())
|
|
{}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::~basic_state_saver()
|
|
{
|
|
state_.imbue(locale_);
|
|
state_.fill(fill_);
|
|
state_.width(width_);
|
|
state_.precision(precision_);
|
|
state_.flags(flags_);
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER basic_format_saver<CTy, CTr>::basic_format_saver(std::basic_ios<CTy, CTr>& a)
|
|
: bss_(a)
|
|
{
|
|
a.imbue(std::locale(a.getloc(), new format_punct<CTy>(get_facet<format_punct<CTy> >(a))));
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER
|
|
basic_format_saver<CTy, CTr>::~basic_format_saver()
|
|
{}
|
|
|
|
GLM_FUNC_QUALIFIER precision::precision(unsigned a)
|
|
: value(a)
|
|
{}
|
|
|
|
GLM_FUNC_QUALIFIER width::width(unsigned a)
|
|
: value(a)
|
|
{}
|
|
|
|
template<typename CTy>
|
|
GLM_FUNC_QUALIFIER delimeter<CTy>::delimeter(CTy a, CTy b, CTy c)
|
|
: value()
|
|
{
|
|
value[0] = a;
|
|
value[1] = b;
|
|
value[2] = c;
|
|
}
|
|
|
|
GLM_FUNC_QUALIFIER order::order(order_type a)
|
|
: value(a)
|
|
{}
|
|
|
|
template<typename FTy, typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy, CTr>& ios)
|
|
{
|
|
if(!std::has_facet<FTy>(ios.getloc()))
|
|
ios.imbue(std::locale(ios.getloc(), new FTy));
|
|
|
|
return std::use_facet<FTy>(ios.getloc());
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& formatted(std::basic_ios<CTy, CTr>& ios)
|
|
{
|
|
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true;
|
|
return ios;
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& unformatted(std::basic_ios<CTy, CTr>& ios)
|
|
{
|
|
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false;
|
|
return ios;
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
|
|
{
|
|
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value;
|
|
return os;
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a)
|
|
{
|
|
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value;
|
|
return os;
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, delimeter<CTy> const& a)
|
|
{
|
|
format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)));
|
|
|
|
fmt.delim_left = a.value[0];
|
|
fmt.delim_right = a.value[1];
|
|
fmt.separator = a.value[2];
|
|
|
|
return os;
|
|
}
|
|
|
|
template<typename CTy, typename CTr>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, order const& a)
|
|
{
|
|
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
|
|
return os;
|
|
}
|
|
} // namespace io
|
|
|
|
namespace detail
|
|
{
|
|
template<typename CTy, typename CTr, typename V>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
|
|
print_vector_on(std::basic_ostream<CTy, CTr>& os, V const& a)
|
|
{
|
|
typename std::basic_ostream<CTy, CTr>::sentry const cerberus(os);
|
|
|
|
if(cerberus)
|
|
{
|
|
io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
|
|
|
|
length_t const& components(type<V>::components);
|
|
|
|
if(fmt.formatted)
|
|
{
|
|
io::basic_state_saver<CTy> const bss(os);
|
|
|
|
os << std::fixed << std::right << std::setprecision(static_cast<std::streamsize>(fmt.precision)) << std::setfill(fmt.space) << fmt.delim_left;
|
|
|
|
for(length_t i(0); i < components; ++i)
|
|
{
|
|
os << std::setw(static_cast<int>(fmt.width)) << a[i];
|
|
if(components-1 != i)
|
|
os << fmt.separator;
|
|
}
|
|
|
|
os << fmt.delim_right;
|
|
}
|
|
else
|
|
{
|
|
for(length_t i(0); i < components; ++i)
|
|
{
|
|
os << a[i];
|
|
|
|
if(components-1 != i)
|
|
os << fmt.space;
|
|
}
|
|
}
|
|
}
|
|
|
|
return os;
|
|
}
|
|
}//namespace detail
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, qua<T, Q> const& a)
|
|
{
|
|
return detail::print_vector_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<1, T, Q> const& a)
|
|
{
|
|
return detail::print_vector_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<2, T, Q> const& a)
|
|
{
|
|
return detail::print_vector_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<3, T, Q> const& a)
|
|
{
|
|
return detail::print_vector_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<4, T, Q> const& a)
|
|
{
|
|
return detail::print_vector_on(os, a);
|
|
}
|
|
|
|
namespace detail
|
|
{
|
|
template<typename CTy, typename CTr, template<length_t, length_t, typename, qualifier> class M, length_t C, length_t R, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& print_matrix_on(std::basic_ostream<CTy, CTr>& os, M<C, R, T, Q> const& a)
|
|
{
|
|
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
|
|
|
|
if(cerberus)
|
|
{
|
|
io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
|
|
|
|
length_t const& cols(type<M<C, R, T, Q> >::cols);
|
|
length_t const& rows(type<M<C, R, T, Q> >::rows);
|
|
|
|
if(fmt.formatted)
|
|
{
|
|
os << fmt.newline << fmt.delim_left;
|
|
|
|
switch(fmt.order)
|
|
{
|
|
case io::column_major:
|
|
{
|
|
for(length_t i(0); i < rows; ++i)
|
|
{
|
|
if (0 != i)
|
|
os << fmt.space;
|
|
|
|
os << row(a, i);
|
|
|
|
if(rows-1 != i)
|
|
os << fmt.newline;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case io::row_major:
|
|
{
|
|
for(length_t i(0); i < cols; ++i)
|
|
{
|
|
if(0 != i)
|
|
os << fmt.space;
|
|
|
|
os << column(a, i);
|
|
|
|
if(cols-1 != i)
|
|
os << fmt.newline;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
os << fmt.delim_right;
|
|
}
|
|
else
|
|
{
|
|
switch (fmt.order)
|
|
{
|
|
case io::column_major:
|
|
{
|
|
for(length_t i(0); i < cols; ++i)
|
|
{
|
|
os << column(a, i);
|
|
|
|
if(cols - 1 != i)
|
|
os << fmt.space;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case io::row_major:
|
|
{
|
|
for (length_t i(0); i < rows; ++i)
|
|
{
|
|
os << row(a, i);
|
|
|
|
if (rows-1 != i)
|
|
os << fmt.space;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return os;
|
|
}
|
|
}//namespace detail
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<2, 2, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<2, 3, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<2, 4, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<3, 2, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<3, 3, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<3, 4, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<4, 2, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<4, 3, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<4, 4, T, Q> const& a)
|
|
{
|
|
return detail::print_matrix_on(os, a);
|
|
}
|
|
|
|
namespace detail
|
|
{
|
|
template<typename CTy, typename CTr, template<length_t, length_t, typename, qualifier> class M, length_t C, length_t R, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& print_matrix_pair_on(std::basic_ostream<CTy, CTr>& os, std::pair<M<C, R, T, Q> const, M<C, R, T, Q> const> const& a)
|
|
{
|
|
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
|
|
|
|
if(cerberus)
|
|
{
|
|
io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
|
|
M<C, R, T, Q> const& ml(a.first);
|
|
M<C, R, T, Q> const& mr(a.second);
|
|
length_t const& cols(type<M<C, R, T, Q> >::cols);
|
|
length_t const& rows(type<M<C, R, T, Q> >::rows);
|
|
|
|
if(fmt.formatted)
|
|
{
|
|
os << fmt.newline << fmt.delim_left;
|
|
|
|
switch(fmt.order)
|
|
{
|
|
default:
|
|
case io::column_major:
|
|
{
|
|
for(length_t i(0); i < rows; ++i)
|
|
{
|
|
if(0 != i)
|
|
os << fmt.space;
|
|
|
|
os << row(ml, i) << ((rows-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << row(mr, i);
|
|
|
|
if(rows-1 != i)
|
|
os << fmt.newline;
|
|
}
|
|
}
|
|
break;
|
|
case io::row_major:
|
|
{
|
|
for(length_t i(0); i < cols; ++i)
|
|
{
|
|
if(0 != i)
|
|
os << fmt.space;
|
|
|
|
os << column(ml, i) << ((cols-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << column(mr, i);
|
|
|
|
if(cols-1 != i)
|
|
os << fmt.newline;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
os << fmt.delim_right;
|
|
}
|
|
else
|
|
{
|
|
os << ml << fmt.space << mr;
|
|
}
|
|
}
|
|
|
|
return os;
|
|
}
|
|
}//namespace detail
|
|
|
|
template<typename CTy, typename CTr, typename T, qualifier Q>
|
|
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(
|
|
std::basic_ostream<CTy, CTr> & os,
|
|
std::pair<mat<4, 4, T, Q> const,
|
|
mat<4, 4, T, Q> const> const& a)
|
|
{
|
|
return detail::print_matrix_pair_on(os, a);
|
|
}
|
|
}//namespace glm
|
|
|
|
#if GLM_COMPILER & GLM_COMPILER_CLANG
|
|
# pragma clang diagnostic pop
|
|
#endif
|
|
|