Add onBlockHoverChanged and onBlockHoverCleared

This commit is contained in:
GriffinR 2021-12-17 20:47:12 -05:00 committed by huderlem
parent 9dc44b3373
commit 5f79f15554
5 changed files with 37 additions and 1 deletions

View file

@ -15,7 +15,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Events, current metatile selections, and map images can now be copied and pasted, including between windows. - Events, current metatile selections, and map images can now be copied and pasted, including between windows.
- The grid and map border visibility are now saved as config options. - The grid and map border visibility are now saved as config options.
- Add ~60 new API functions, including new features like reading/writing metatile data, layering, moving, and hiding items in the overlay, creating modified images and tile/metatile images, reading tileset sizes, logging warnings and errors, and more. - Add ~60 new API functions, including new features like reading/writing metatile data, layering, moving, and hiding items in the overlay, creating modified images and tile/metatile images, reading tileset sizes, logging warnings and errors, and more.
- Add 5 new scripting callbacks. - Add 7 new scripting callbacks.
### Changed ### Changed
- New events will be placed in the center of the current view of the map. - New events will be placed in the center of the current view of the map.

View file

@ -118,6 +118,17 @@ Callbacks
:param object prevBlock: the block's state before it was modified. The object's shape is ``{metatileId, collision, elevation, rawValue}`` :param object prevBlock: the block's state before it was modified. The object's shape is ``{metatileId, collision, elevation, rawValue}``
:param object newBlock: the block's new state after it was modified. The object's shape is ``{metatileId, collision, elevation, rawValue}`` :param object newBlock: the block's new state after it was modified. The object's shape is ``{metatileId, collision, elevation, rawValue}``
.. js:function:: onBlockHoverChanged(x, y)
Called when the mouse enters a new map block.
:param number x: x coordinate of the block
:param number y: y coordinate of the block
.. js:function:: onBlockHoverCleared()
Called when the mouse exits the map.
.. js:function:: onMapResized(oldWidth, oldHeight, newWidth, newHeight) .. js:function:: onMapResized(oldWidth, oldHeight, newWidth, newHeight)
Called when the dimensions of the map are changed. Called when the dimensions of the map are changed.

View file

@ -12,6 +12,8 @@ enum CallbackType {
OnProjectOpened, OnProjectOpened,
OnProjectClosed, OnProjectClosed,
OnBlockChanged, OnBlockChanged,
OnBlockHoverChanged,
OnBlockHoverCleared,
OnMapOpened, OnMapOpened,
OnMapResized, OnMapResized,
OnMapShifted, OnMapShifted,
@ -38,6 +40,8 @@ public:
static void cb_ProjectOpened(QString projectPath); static void cb_ProjectOpened(QString projectPath);
static void cb_ProjectClosed(QString projectPath); static void cb_ProjectClosed(QString projectPath);
static void cb_MetatileChanged(int x, int y, Block prevBlock, Block newBlock); static void cb_MetatileChanged(int x, int y, Block prevBlock, Block newBlock);
static void cb_BlockHoverChanged(int x, int y);
static void cb_BlockHoverCleared();
static void cb_MapOpened(QString mapName); static void cb_MapOpened(QString mapName);
static void cb_MapResized(int oldWidth, int oldHeight, int newWidth, int newHeight); static void cb_MapResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
static void cb_MapShifted(int xDelta, int yDelta); static void cb_MapShifted(int xDelta, int yDelta);

View file

@ -10,6 +10,7 @@
#include "montabwidget.h" #include "montabwidget.h"
#include "editcommands.h" #include "editcommands.h"
#include "config.h" #include "config.h"
#include "scripting.h"
#include <QCheckBox> #include <QCheckBox>
#include <QPainter> #include <QPainter>
#include <QMouseEvent> #include <QMouseEvent>
@ -992,6 +993,7 @@ void Editor::updateCursorRectPos(int x, int y) {
this->cursorMapTileRect->updateLocation(x, y); this->cursorMapTileRect->updateLocation(x, y);
if (ui->graphicsView_Map->scene()) if (ui->graphicsView_Map->scene())
ui->graphicsView_Map->scene()->update(); ui->graphicsView_Map->scene()->update();
Scripting::cb_BlockHoverChanged(x, y);
} }
void Editor::setCursorRectVisible(bool visible) { void Editor::setCursorRectVisible(bool visible) {
@ -1029,6 +1031,7 @@ void Editor::onHoveredMapMetatileCleared() {
|| map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects) { || map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
this->ui->statusBar->clearMessage(); this->ui->statusBar->clearMessage();
} }
Scripting::cb_BlockHoverCleared();
} }
void Editor::onHoveredMapMovementPermissionChanged(int x, int y) { void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
@ -1051,6 +1054,7 @@ void Editor::onHoveredMapMovementPermissionCleared() {
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) { if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
this->ui->statusBar->clearMessage(); this->ui->statusBar->clearMessage();
} }
Scripting::cb_BlockHoverCleared();
} }
QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation) { QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation) {

View file

@ -5,6 +5,8 @@ QMap<CallbackType, QString> callbackFunctions = {
{OnProjectOpened, "onProjectOpened"}, {OnProjectOpened, "onProjectOpened"},
{OnProjectClosed, "onProjectClosed"}, {OnProjectClosed, "onProjectClosed"},
{OnBlockChanged, "onBlockChanged"}, {OnBlockChanged, "onBlockChanged"},
{OnBlockHoverChanged, "onBlockHoverChanged"},
{OnBlockHoverCleared, "onBlockHoverCleared"},
{OnMapOpened, "onMapOpened"}, {OnMapOpened, "onMapOpened"},
{OnMapResized, "onMapResized"}, {OnMapResized, "onMapResized"},
{OnMapShifted, "onMapShifted"}, {OnMapShifted, "onMapShifted"},
@ -136,6 +138,21 @@ void Scripting::cb_MetatileChanged(int x, int y, Block prevBlock, Block newBlock
instance->invokeCallback(OnBlockChanged, args); instance->invokeCallback(OnBlockChanged, args);
} }
void Scripting::cb_BlockHoverChanged(int x, int y) {
if (!instance) return;
QJSValueList args {
x,
y,
};
instance->invokeCallback(OnBlockHoverChanged, args);
}
void Scripting::cb_BlockHoverCleared() {
if (!instance) return;
instance->invokeCallback(OnBlockHoverCleared, QJSValueList());
}
void Scripting::cb_MapOpened(QString mapName) { void Scripting::cb_MapOpened(QString mapName) {
if (!instance) return; if (!instance) return;