Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/editor/project.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class Project {

public:
Project(const std::string &path);
static std::string create(const std::string &dirPath, const std::string &title);
static void openProject(const tgui::String &filePath, bool forceSwitch = false);
static std::string create(const std::string &dirPath,
const std::string &title);
static void openProject(const tgui::String &filePath,
bool forceSwitch = false);
json toJson();
std::string &getTitle();
std::string &getBasePath();
Expand Down
9 changes: 5 additions & 4 deletions include/editor/services/recentProjectService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

class RecentProjectService {
private:
int limit = 10;
std::deque<std::string> recentProjects;
std::filesystem::path path;
void save();
int limit = 10;
std::deque<std::string> recentProjects;
std::filesystem::path path;
void save();

public:
RecentProjectService();
void enqueue(const std::string &projectPath);
Expand Down
1 change: 0 additions & 1 deletion src/editor/fileViews/roomFileView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ void RoomFileView::setRoomTool(ToolboxItem<RoomTool> tool) {
layerVisitor.group->removeAllWidgets();
mj::visit(layerVisitor,
static_cast<RoomLayer>(layerChoose->getSelectedItemIndex()));
cout << "Selected tool: " << tool.text << endl;
}
RoomFileView::~RoomFileView() {
HotkeyService &hks = Editor::instance->getHotkeyService();
Expand Down
15 changes: 8 additions & 7 deletions src/editor/screens/welcomeScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void screens::WelcomeScreen::initItems(tgui::Group::Ptr layout) {
actionsLabel->setTextSize(24);
left->add(actionsLabel);
bindTranslation<tgui::Label>(actionsLabel, "screen.starting.actions",
&tgui::Label::setText);
&tgui::Label::setText);

const auto newProjButton = tgui::Button::create();
bindTranslation<tgui::Button>(newProjButton, "menu.file.new_project",
Expand Down Expand Up @@ -103,22 +103,23 @@ void screens::WelcomeScreen::initItems(tgui::Group::Ptr layout) {
right->setAutoLayout(tgui::AutoLayout::Fill);

const auto recentProjectLabel = tgui::Label::create("");
bindTranslation<tgui::Label>(recentProjectLabel, "screen.starting.recent_projects",
&tgui::Label::setText);
bindTranslation<tgui::Label>(recentProjectLabel,
"screen.starting.recent_projects",
&tgui::Label::setText);
recentProjectLabel->setTextSize(24);
recentProjectLabel->setAutoLayout(tgui::AutoLayout::Top);
right->add(recentProjectLabel);

const auto recentProject = tgui::ListBox::create();
recentProject->setAutoLayout(tgui::AutoLayout::Fill);

for (auto i : Editor::instance->getRecentProjectService().getRecentProjects()) {
for (auto i :
Editor::instance->getRecentProjectService().getRecentProjects()) {
recentProject->addItem(i);
}

recentProject->onItemSelect([this](const tgui::String& path) {
Project::openProject(path);
});
recentProject->onItemSelect(
[this](const tgui::String &path) { Project::openProject(path); });

right->add(recentProject);

Expand Down
1 change: 0 additions & 1 deletion src/editor/services/childWindowSubService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ void ChildWindowSubService::openWindow(const std::string &windowName) {

void ChildWindowSubService::resetAndOpen(const std::string windowName) {
this->createWindows();
std::cout << windowName << std::endl;
this->openWindow(windowName);
}
4 changes: 0 additions & 4 deletions src/editor/services/editorGuiService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ void EditorGuiService::init() {
auto &hks = Editor::instance->getHotkeyService();

hks.deserialize(cfgs.getField("hotkeys"));
auto serialized = hks.serialize();
for (auto &[keyId, keyStr] : serialized) {
std::cout << keyId << ": " << keyStr << std::endl;
}

this->resetUi();
hks.registerHotkeyCallback("toggle_debug",
Expand Down
5 changes: 2 additions & 3 deletions src/editor/services/fileSystemService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ void FileSystemService::promptOpenProject() {
auto files = tgui::FileDialog::create();
files->setFileTypeFilters({{"RPG++ Project", {"*.rpgpp"}}});

files->onFileSelect([](const tgui::String &filePath) {
Project::openProject(filePath);
});
files->onFileSelect(
[](const tgui::String &filePath) { Project::openProject(filePath); });

Editor::instance->getGui().gui->add(files);
}
Expand Down
3 changes: 2 additions & 1 deletion src/editor/services/recentProjectService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void RecentProjectService::save() {

std::ofstream file(path);
if (!file.is_open()) {
std::cerr << "Failed to open recent project file for saving" << std::endl;
std::cerr << "Failed to open recent project file for saving"
<< std::endl;
return;
}

Expand Down
1 change: 0 additions & 1 deletion src/editor/services/translationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void TranslationService::purgeDeadListeners() {
}
}
for (auto id : toBePurged) {
// std::cout << "Purging listener " << id << "\n";
removeListener(id);
}
}
Expand Down
56 changes: 32 additions & 24 deletions src/editor/views/worldView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ WorldView::WorldView(const char *typeName, bool initRenderer)

tgui::Vector2f size = getSize();
widgetSize = size;
texture =
LoadRenderTexture(static_cast<int>(size.x), static_cast<int>(size.y));

camera = {};
camera.offset = Vector2{0, 0};
Expand All @@ -35,9 +33,6 @@ WorldView::WorldView(const char *typeName, bool initRenderer)
}

WorldView::~WorldView() {
if (IsRenderTextureValid(texture)) {
UnloadRenderTexture(texture);
}
}

WorldView::Ptr WorldView::create() { return std::make_shared<WorldView>(); }
Expand All @@ -55,7 +50,38 @@ tgui::Widget::Ptr WorldView::clone() const {
}

void WorldView::setSize(const tgui::Layout2d &size) {
tgui::CanvasRaylib::setSize(size);
CanvasBase::setSize(size);
const tgui::Vector2f newSize = getSize();

if ((newSize.x > 0) && (newSize.y > 0))
{
const tgui::Vector2u newTextureSize{newSize};
// if ((m_textureSize.x < newTextureSize.x) || (m_textureSize.y < newTextureSize.y))
{
if (m_textureTarget.id > 0)
{
// The m_backendTexture is using the exact same texture as our render target (due to the call to replaceInternalTexture).
// To prevent the texture from being freed twice, we shouldn't let UnloadRenderTexture delete the texture.
m_textureTarget.texture.id = 0;
UnloadRenderTexture(m_textureTarget);
}
TGUI_ASSERT(tgui::isBackendSet() && tgui::getBackend()->hasRenderer()
&& std::dynamic_pointer_cast<tgui::BackendRendererRaylib>(tgui::getBackend()->getRenderer()),
"CanvasRaylib can only be used when using the Raylib backend renderer");

m_textureTarget = LoadRenderTexture(static_cast<int>(newTextureSize.x), static_cast<int>(newTextureSize.y));

// Move the ownership of the texture to our backend texture
m_backendTexture->replaceInternalTexture(m_textureTarget.texture);

if (m_textureTarget.id)
m_textureSize = newTextureSize;
else
m_textureSize = {};
}

m_usedTextureSize = newTextureSize;
}
}

bool WorldView::isMouseOnWidget(tgui::Vector2f pos) const {
Expand Down Expand Up @@ -125,27 +151,9 @@ void WorldView::keyPressed(const tgui::Event::KeyEvent &event) {

bool WorldView::canGainFocus() const { return true; }

void WorldView::resetRender() {
tgui::Vector2f newSize = getSize();
m_textureTarget = LoadRenderTexture(static_cast<int>(newSize.x),
static_cast<int>(newSize.y));
m_backendTexture->replaceInternalTexture(m_textureTarget.texture);
if (m_textureTarget.id) {
m_textureSize = tgui::Vector2u{newSize};
} else {
m_textureSize = {};
}
m_usedTextureSize = tgui::Vector2u{newSize};
}

void WorldView::update() {
mouseMiddleButton = IsMouseButtonDown(MOUSE_MIDDLE_BUTTON);

if (widgetSize != getSize()) {
widgetSize = getSize();
resetRender();
}

BeginTextureMode(m_textureTarget);

BeginMode2D(camera);
Expand Down
Loading