[jasper/world/studio] Fix positioning for tile placement
All checks were successful
Build / build (push) Successful in 3m9s
All checks were successful
Build / build (push) Successful in 3m9s
This commit is contained in:
parent
4c7fc5f9b4
commit
b26601fad9
@ -49,33 +49,16 @@ static WorldDoc makeValid(WorldDoc doc) noexcept {
|
||||
[[nodiscard]]
|
||||
constexpr ox::Point fbPtToTileAddr(
|
||||
ox::Vec2 const&fbPt,
|
||||
ox::Size const&fbSz,
|
||||
ox::Size const&mapSz) noexcept {
|
||||
// fbw - framebuffer width
|
||||
// fbh - framebuffer height
|
||||
// fbx - framebuffer pt x
|
||||
// fby - framebuffer pt y
|
||||
// sw - scaled width
|
||||
// sh - scaled height
|
||||
// mw - map width
|
||||
// mw - map height
|
||||
// mx - map loc x
|
||||
// my - map loc y
|
||||
// sw = fbw / mw
|
||||
// sh = fbh / mh
|
||||
// tile addr x = sw * fbx
|
||||
// tile addr y = sh * fby
|
||||
auto const fbw = static_cast<float>(fbSz.width);
|
||||
auto const fbh = static_cast<float>(fbSz.height);
|
||||
auto const mw = static_cast<float>(mapSz.width);
|
||||
auto const mh = static_cast<float>(mapSz.height);
|
||||
auto const sw = fbw / mw;
|
||||
auto const sh = fbh / mh;
|
||||
auto const fbx = fbPt.x / fbw;
|
||||
auto const fby = fbPt.y / fbh;
|
||||
ox::Vec2 const&mapSz) noexcept {
|
||||
constexpr auto ColumnsOnScrn = 15;
|
||||
constexpr auto RowsOnScrn = 10;
|
||||
auto const fbX = static_cast<float>(fbPt.x);
|
||||
auto const fbY = static_cast<float>(fbPt.y);
|
||||
auto const tw = static_cast<float>(mapSz.x / ColumnsOnScrn);
|
||||
auto const th = static_cast<float>(mapSz.y / RowsOnScrn);
|
||||
return {
|
||||
static_cast<int>(sw * fbx),
|
||||
static_cast<int>(sh * fby),
|
||||
static_cast<int>(fbX / tw),
|
||||
static_cast<int>(fbY / th),
|
||||
};
|
||||
}
|
||||
|
||||
@ -190,15 +173,18 @@ void WorldEditorImGui::drawWorldView() noexcept {
|
||||
auto const srcH = fbHeight / fbWidth;
|
||||
auto const dstH = paneSize.y / paneSize.x;
|
||||
float xScale{}, yScale{};
|
||||
float fbPaneScale{};
|
||||
if (dstH > srcH) {
|
||||
// crop off width
|
||||
xScale = srcH / dstH;
|
||||
yScale = 1;
|
||||
fbPaneScale = paneSize.y / fbHeight;
|
||||
} else {
|
||||
auto const srcW = fbWidth / fbHeight;
|
||||
auto const dstW = (paneSize.x / paneSize.y);
|
||||
xScale = 1;
|
||||
yScale = srcW / dstW;
|
||||
fbPaneScale = paneSize.x / fbWidth;
|
||||
}
|
||||
ImGui::Image(
|
||||
ig::toImTextureID(fb.color.id),
|
||||
@ -208,10 +194,14 @@ void WorldEditorImGui::drawWorldView() noexcept {
|
||||
std::ignore = ig::dragDropTarget([&, this] {
|
||||
oxRequire(objId, ig::getDragDropPayload<WorldTileDragDrop>("WorldTile"));
|
||||
auto const&io = ImGui::GetIO();
|
||||
auto const dropPos = world::dropPos(ox::Vec2(io.MousePos));
|
||||
auto const mw = m_doc.columns * ncore::TileWidth * 2;
|
||||
auto const mh = m_doc.rows * ncore::TileHeight * 2;
|
||||
auto const tileAddr = fbPtToTileAddr(dropPos, fb.size(), {mw, mh});
|
||||
auto const dropPos = world::dropPos(ox::Vec2{io.MousePos});
|
||||
auto const viewSz = m_view.drawSize();
|
||||
auto const tileAddr = fbPtToTileAddr(
|
||||
dropPos,
|
||||
ox::Vec2{
|
||||
static_cast<float>(viewSz.width) * fbPaneScale,
|
||||
static_cast<float>(viewSz.height) * fbPaneScale});
|
||||
if (tileAddr.x < m_doc.columns && tileAddr.y < m_doc.rows) {
|
||||
pushCommand<ModifyTilesCommand>(
|
||||
m_doc,
|
||||
m_worldStatic,
|
||||
@ -224,6 +214,7 @@ void WorldEditorImGui::drawWorldView() noexcept {
|
||||
.setId = objId.setId,
|
||||
},
|
||||
});
|
||||
}
|
||||
oxReturnError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic));
|
||||
return ox::Error{};
|
||||
});
|
||||
|
@ -29,6 +29,11 @@ class WorldEditorImGui: public studio::Editor {
|
||||
ox::String name;
|
||||
uint64_t id{};
|
||||
keel::AssetRef<WorldObjectSet> set;
|
||||
ObjSetRef(ox::String pName, uint64_t pId, keel::AssetRef<WorldObjectSet> pSet):
|
||||
name(std::move(pName)),
|
||||
id(pId),
|
||||
set(std::move(pSet)) {}
|
||||
constexpr ObjSetRef() = default;
|
||||
};
|
||||
ox::Vector<ObjSetRef> m_objSets;
|
||||
WorldStatic m_worldStatic;
|
||||
|
Loading…
x
Reference in New Issue
Block a user