2024-03-06 15:50:19 +00:00
|
|
|
#include "PyScene.h"
|
|
|
|
#include "ActionCode.h"
|
|
|
|
#include "Resources.h"
|
|
|
|
|
|
|
|
PyScene::PyScene(GameEngine* g) : Scene(g)
|
|
|
|
{
|
2024-03-07 02:12:26 +00:00
|
|
|
// mouse events
|
|
|
|
registerAction(ActionCode::MOUSEBUTTON + sf::Mouse::Left, "left");
|
|
|
|
registerAction(ActionCode::MOUSEBUTTON + sf::Mouse::Right, "right");
|
|
|
|
registerAction(ActionCode::MOUSEWHEEL + ActionCode::WHEEL_DEL, "wheel_up");
|
|
|
|
registerAction(ActionCode::MOUSEWHEEL + ActionCode::WHEEL_NEG + ActionCode::WHEEL_DEL, "wheel_down");
|
|
|
|
|
2024-03-09 03:25:48 +00:00
|
|
|
registerAction(ActionCode::KEY + sf::Keyboard::Grave, "debug_menu");
|
2024-03-06 15:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PyScene::update()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-03-07 02:12:26 +00:00
|
|
|
void PyScene::do_mouse_input(std::string button, std::string type)
|
|
|
|
{
|
2024-03-08 21:55:58 +00:00
|
|
|
auto unscaledmousepos = sf::Mouse::getPosition(game->getWindow());
|
|
|
|
auto mousepos = game->getWindow().mapPixelToCoords(unscaledmousepos);
|
2024-03-07 02:12:26 +00:00
|
|
|
UIDrawable* target;
|
|
|
|
for (auto d: *ui_elements)
|
|
|
|
{
|
|
|
|
target = d->click_at(sf::Vector2f(mousepos));
|
|
|
|
if (target)
|
|
|
|
{
|
2024-03-08 21:55:58 +00:00
|
|
|
PyObject* args = Py_BuildValue("(iiss)", (int)mousepos.x, (int)mousepos.y, button.c_str(), type.c_str());
|
2024-03-08 17:09:09 +00:00
|
|
|
PyObject* retval = PyObject_Call(target->click_callable, args, NULL);
|
|
|
|
if (!retval)
|
|
|
|
{
|
|
|
|
std::cout << "click_callable has raised an exception. It's going to STDERR and being dropped:" << std::endl;
|
|
|
|
PyErr_Print();
|
|
|
|
PyErr_Clear();
|
|
|
|
} else if (retval != Py_None)
|
|
|
|
{
|
|
|
|
std::cout << "click_callable returned a non-None value. It's not an error, it's just not being saved or used." << std::endl;
|
|
|
|
}
|
2024-03-07 02:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 15:50:19 +00:00
|
|
|
void PyScene::doAction(std::string name, std::string type)
|
|
|
|
{
|
2024-03-07 02:12:26 +00:00
|
|
|
if (ACTIONPY) {
|
|
|
|
McRFPy_API::doAction(name.substr(0, name.size() - 3));
|
|
|
|
}
|
|
|
|
else if (name.compare("left") == 0 || name.compare("rclick") == 0 || name.compare("wheel_up") == 0 || name.compare("wheel_down") == 0) {
|
|
|
|
do_mouse_input(name, type);
|
|
|
|
}
|
|
|
|
else if ACTIONONCE("debug_menu") {
|
|
|
|
McRFPy_API::REPL();
|
|
|
|
}
|
2024-03-06 15:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PyScene::sRender()
|
|
|
|
{
|
|
|
|
game->getWindow().clear();
|
|
|
|
|
|
|
|
auto vec = *ui_elements;
|
|
|
|
for (auto e: vec)
|
|
|
|
{
|
|
|
|
if (e)
|
|
|
|
e->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
game->getWindow().display();
|
|
|
|
}
|