Skip to content

Commit

Permalink
Merge pull request #1630 from mouzedrift/editor-fixes
Browse files Browse the repository at this point in the history
fix editor context menu sometimes not appearing, fix moving multiple collisions
  • Loading branch information
mouzedrift authored Sep 9, 2024
2 parents 6fcf595 + 376e11a commit 0cc71bd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 72 deletions.
107 changes: 53 additions & 54 deletions Source/AliveLibAE/FlyingSlig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void FlyingSlig::CreateFromSaveState(SerializedObjectData& pBuffer)
pFlyingSlig->field_18C = pSaveState->field_5C;
pFlyingSlig->field_190 = pSaveState->field_60;
pFlyingSlig->field_194 = pSaveState->field_64;
pFlyingSlig->field_198_line_length = pSaveState->field_68_line_length;
pFlyingSlig->mCurrentLineLength = pSaveState->field_68_line_length;
pFlyingSlig->field_1C4 = pSaveState->field_6C;
pFlyingSlig->field_1C8_lever_pull_range_xpos = pSaveState->field_70_lever_pull_range_xpos;
pFlyingSlig->field_1CC_lever_pull_range_ypos = pSaveState->field_74_lever_pull_range_ypos;
Expand Down Expand Up @@ -417,7 +417,7 @@ void FlyingSlig::VGetSaveState(SerializedObjectData& pSaveBuffer)
data.field_5C = field_18C;
data.field_60 = field_190;
data.field_64 = field_194;
data.field_68_line_length = field_198_line_length;
data.field_68_line_length = mCurrentLineLength;
data.field_6C = field_1C4;
data.field_70_lever_pull_range_xpos = field_1C8_lever_pull_range_xpos;
data.field_74_lever_pull_range_ypos = field_1CC_lever_pull_range_ypos;
Expand Down Expand Up @@ -560,9 +560,9 @@ void FlyingSlig::sub_4348A0()
field_294_nextXPos = mXPos;
field_18C = FP_FromInteger(0);
field_190 = FP_FromInteger(0);
sub_437C70(BaseAliveGameObjectCollisionLine);
const s16 v5 = FP_GetExponent(mYPos - field_1A4_rect.y);
const s16 v6 = FP_GetExponent(mXPos - field_1A4_rect.x);
SetActiveLine(BaseAliveGameObjectCollisionLine);
const s16 v5 = FP_GetExponent(mYPos - mCurrentLineRect.y);
const s16 v6 = FP_GetExponent(mXPos - mCurrentLineRect.x);
field_194 = FP_FromInteger(Math_SquareRoot_Int(v5 * v5 + v6 * v6));
mUnknown2 = field_118_data.mFacing == relive::reliveXDirection::eLeft;
}
Expand Down Expand Up @@ -930,7 +930,7 @@ void FlyingSlig::Brain_1_Death()

void FlyingSlig::Brain_2_Moving()
{
if (!sub_436730() && sub_4374A0(1) == 1)
if (!ReactingToSomething() && sub_4374A0(1) == 1)
{
mUnknown2 = !mUnknown2;
PatrolDelay();
Expand All @@ -945,7 +945,7 @@ void FlyingSlig::Brain_3_GetAlerted()
}
else if (VIsFacingMe(sControlledCharacter))
{
if (!sub_436730() && static_cast<s32>(sGnFrame) >= field_14C_timer)
if (!ReactingToSomething() && static_cast<s32>(sGnFrame) >= field_14C_timer)
{
ToMoving();
}
Expand Down Expand Up @@ -996,7 +996,7 @@ void FlyingSlig::Brain_4_ChasingEnemy()
}
}
}
else if (!sub_436B20())
else if (!GotoNextOrPrevLine())
{
sub_4373B0();
}
Expand All @@ -1006,7 +1006,7 @@ void FlyingSlig::Brain_4_ChasingEnemy()

void FlyingSlig::Brain_5_Idle()
{
if (!sub_436730() && static_cast<s32>(sGnFrame) >= field_14C_timer)
if (!ReactingToSomething() && static_cast<s32>(sGnFrame) >= field_14C_timer)
{
ToMoving();
}
Expand Down Expand Up @@ -1955,13 +1955,13 @@ s16 FlyingSlig::sub_4374A0(s16 a2)
FP right = {};
if (directedXMaxSpeedUp <= FP_FromInteger(0))
{
left = field_1A4_rect.x;
right = field_1A4_rect.w;
left = mCurrentLineRect.x;
right = mCurrentLineRect.w;
}
else
{
left = field_1A4_rect.w;
right = field_1A4_rect.x;
left = mCurrentLineRect.w;
right = mCurrentLineRect.x;
}

const FP width = left - right;
Expand All @@ -1984,7 +1984,7 @@ s16 FlyingSlig::sub_4374A0(s16 a2)
mLastLine = true;

const FP v65 = FP_Abs((((field_18C * field_18C) / field_2B4_max_slow_down) * FP_FromDouble(0.5)));
const FP v27 = field_198_line_length - field_194;
const FP v27 = mCurrentLineLength - field_194;
if (v27 < field_2A8_max_x_speed && field_18C == FP_FromInteger(0))
{
return 1;
Expand Down Expand Up @@ -2027,13 +2027,13 @@ s16 FlyingSlig::sub_4374A0(s16 a2)
FP right = {};
if (directedXMaxSpeed <= FP_FromInteger(0))
{
left = field_1A4_rect.x;
right = field_1A4_rect.w;
left = mCurrentLineRect.x;
right = mCurrentLineRect.w;
}
else
{
left = field_1A4_rect.w;
right = field_1A4_rect.x;
left = mCurrentLineRect.w;
right = mCurrentLineRect.x;
}

const FP width = left - right;
Expand Down Expand Up @@ -2071,13 +2071,13 @@ s16 FlyingSlig::sub_4374A0(s16 a2)

if (field_190 > FP_FromInteger(0))
{
field_184_xSpeed = field_1A4_rect.w - field_1A4_rect.x;
field_188_ySpeed = field_1A4_rect.h - field_1A4_rect.y;
field_184_xSpeed = mCurrentLineRect.w - mCurrentLineRect.x;
field_188_ySpeed = mCurrentLineRect.h - mCurrentLineRect.y;
}
else if (field_190 < FP_FromInteger(0))
{
field_184_xSpeed = field_1A4_rect.x - field_1A4_rect.w;
field_188_ySpeed = field_1A4_rect.y - field_1A4_rect.h;
field_184_xSpeed = mCurrentLineRect.x - mCurrentLineRect.w;
field_188_ySpeed = mCurrentLineRect.y - mCurrentLineRect.h;
}

return 0;
Expand Down Expand Up @@ -2179,7 +2179,7 @@ void FlyingSlig::BlowUp()
field_14C_timer = MakeTimer(40);
}

s16 FlyingSlig::sub_436730()
s16 FlyingSlig::ReactingToSomething()
{
if (CanChase(sControlledCharacter))
{
Expand Down Expand Up @@ -2450,31 +2450,30 @@ void FlyingSlig::HandlePlayerControls()
}
}

s16 FlyingSlig::sub_437C70(PathLine* pLine)
s16 FlyingSlig::SetActiveLine(PathLine* pLine)
{
BaseAliveGameObjectCollisionLine = pLine;
if (!BaseAliveGameObjectCollisionLine)
{
return 0;
}

field_1A4_rect.x = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.x);
field_1A4_rect.y = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.y);
field_1A4_rect.w = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.w);
field_1A4_rect.h = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.h);
mCurrentLineRect.x = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.x);
mCurrentLineRect.y = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.y);
mCurrentLineRect.w = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.w);
mCurrentLineRect.h = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.h);

mNextLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mNext);
mPrevLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mPrevious);

field_1EC_pNextLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mNext);
field_1F0_pPrevLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mPrevious);
mCurrentLineLength = FP_FromInteger(BaseAliveGameObjectCollisionLine->mLineLength);

field_198_line_length = FP_FromInteger(BaseAliveGameObjectCollisionLine->mLineLength);
mNoPrevLine = mPrevLine == nullptr;
mNoNextLine = mNextLine == nullptr;

mNoPrevLine = field_1F0_pPrevLine == nullptr;
mNoNextLine = field_1EC_pNextLine == nullptr;

field_182_bound1 = FindLeftOrRightBound(field_1A4_rect.w, field_1A4_rect.h);
field_180_bound2 = FindLeftOrRightBound(field_1A4_rect.x, field_1A4_rect.y);
field_1BC = Math_Tan(field_1A4_rect.y - field_1A4_rect.h, field_1A4_rect.w - field_1A4_rect.x);
field_182_bound1 = FindLeftOrRightBound(mCurrentLineRect.w, mCurrentLineRect.h);
field_180_bound2 = FindLeftOrRightBound(mCurrentLineRect.x, mCurrentLineRect.y);
field_1BC = Math_Tan(mCurrentLineRect.y - mCurrentLineRect.h, mCurrentLineRect.w - mCurrentLineRect.x);

field_1C0 = field_1BC + FP_FromInteger(128);

Expand Down Expand Up @@ -2589,8 +2588,8 @@ s16 FlyingSlig::sub_436C60(PSX_RECT* pRect, s16 arg_4)
return 1;
}

const FP v2 = (field_1A4_rect.h - field_1A4_rect.y) / (field_1A4_rect.w - field_1A4_rect.x);
const FP v3 = field_1A4_rect.y - (v2 * field_1A4_rect.x);
const FP v2 = (mCurrentLineRect.h - mCurrentLineRect.y) / (mCurrentLineRect.w - mCurrentLineRect.x);
const FP v3 = mCurrentLineRect.y - (v2 * mCurrentLineRect.x);

FP yOff1 = {};
if (bRightInRect)
Expand Down Expand Up @@ -2652,13 +2651,13 @@ s16 FlyingSlig::sub_436C60(PSX_RECT* pRect, s16 arg_4)
if (bRightInRect)
{
sqrt1 = FP_FromInteger(Math_SquareRoot_Int(
FP_GetExponent(yOff1 - field_1A4_rect.y) * (FP_GetExponent(yOff1 - field_1A4_rect.y)) + FP_GetExponent(rRight - field_1A4_rect.x) * (FP_GetExponent(rRight - field_1A4_rect.x))));
FP_GetExponent(yOff1 - mCurrentLineRect.y) * (FP_GetExponent(yOff1 - mCurrentLineRect.y)) + FP_GetExponent(rRight - mCurrentLineRect.x) * (FP_GetExponent(rRight - mCurrentLineRect.x))));
}

if (bLeftInRect)
{
const s32 sqrt2_int = Math_SquareRoot_Int(
FP_GetExponent(yOff2 - field_1A4_rect.y) * (FP_GetExponent(yOff2 - field_1A4_rect.y)) + FP_GetExponent(rLeft - field_1A4_rect.x) * (FP_GetExponent(rLeft - field_1A4_rect.x)));
FP_GetExponent(yOff2 - mCurrentLineRect.y) * (FP_GetExponent(yOff2 - mCurrentLineRect.y)) + FP_GetExponent(rLeft - mCurrentLineRect.x) * (FP_GetExponent(rLeft - mCurrentLineRect.x)));

sqrt2 = FP_FromInteger(sqrt2_int);
}
Expand Down Expand Up @@ -2732,14 +2731,14 @@ s16 FlyingSlig::sub_436C60(PSX_RECT* pRect, s16 arg_4)

if (arg_4)
{
field_1C4 = FP_Abs(yTop - field_1A4_rect.y);
field_1C4 = FP_Abs(yTop - mCurrentLineRect.y);
}

return 1;
}
}

bool FlyingSlig::sub_436B20()
bool FlyingSlig::GotoNextOrPrevLine()
{
PathLine* pLastNextOrPrevLine = nullptr;

Expand Down Expand Up @@ -3197,38 +3196,38 @@ void FlyingSlig::sub_437AC0(FP arg1, FP_Point* pPoint)

if (arg1 > FP_FromInteger(0))
{
if (field_194 + arg1 > field_198_line_length)
if (field_194 + arg1 > mCurrentLineLength)
{
if (!mLastLine && field_1EC_pNextLine)
if (!mLastLine && mNextLine)
{
unknown = field_194 + arg1 - field_198_line_length;
if (sub_437C70(field_1EC_pNextLine))
unknown = field_194 + arg1 - mCurrentLineLength;
if (SetActiveLine(mNextLine))
{
field_194 = FP_FromInteger(0);
}
else
{
unknown = FP_FromInteger(0);
field_194 = field_198_line_length;
field_194 = mCurrentLineLength;
}
}
else
{
unknown = FP_FromInteger(0);
field_194 = field_198_line_length;
field_194 = mCurrentLineLength;
}
}
}
else
{
if (field_194 + arg1 < FP_FromInteger(0))
{
if (!mLastLine && field_1F0_pPrevLine)
if (!mLastLine && mPrevLine)
{
unknown = field_194 + arg1;
if (sub_437C70(field_1F0_pPrevLine))
if (SetActiveLine(mPrevLine))
{
field_194 = field_198_line_length;
field_194 = mCurrentLineLength;
}
else
{
Expand All @@ -3245,6 +3244,6 @@ void FlyingSlig::sub_437AC0(FP arg1, FP_Point* pPoint)
}

field_194 += unknown;
pPoint->x = (field_194 * ((field_1A4_rect.w - field_1A4_rect.x) / field_198_line_length)) + field_1A4_rect.x;
pPoint->y = (field_194 * ((field_1A4_rect.h - field_1A4_rect.y) / field_198_line_length)) + field_1A4_rect.y;
pPoint->x = (field_194 * ((mCurrentLineRect.w - mCurrentLineRect.x) / mCurrentLineLength)) + mCurrentLineRect.x;
pPoint->y = (field_194 * ((mCurrentLineRect.h - mCurrentLineRect.y) / mCurrentLineLength)) + mCurrentLineRect.y;
}
14 changes: 7 additions & 7 deletions Source/AliveLibAE/FlyingSlig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ class FlyingSlig final : public BaseAliveGameObject

// TODO: names
s16 sub_4374A0(s16 a2);
s16 sub_436730();
s16 sub_437C70(PathLine* pLine);
s16 ReactingToSomething();
s16 SetActiveLine(PathLine* pLine);
s16 sub_436C60(PSX_RECT* pRect, s16 op1);
bool sub_436B20();
bool GotoNextOrPrevLine();
void sub_4373B0();
void sub_437AC0(FP a2, FP_Point* pPoint);

Expand Down Expand Up @@ -298,15 +298,15 @@ class FlyingSlig final : public BaseAliveGameObject
FP field_18C = {};
FP field_190 = {};
FP field_194 = {};
FP field_198_line_length = {};
FP_Rect field_1A4_rect = {};
FP mCurrentLineLength = {};
FP_Rect mCurrentLineRect = {};
FP field_1BC = {};
FP field_1C0 = {};
FP field_1C4 = {};
FP field_1C8_lever_pull_range_xpos = {};
FP field_1CC_lever_pull_range_ypos = {};
PathLine* field_1EC_pNextLine = nullptr;
PathLine* field_1F0_pPrevLine = nullptr;
PathLine* mNextLine = nullptr;
PathLine* mPrevLine = nullptr;
std::shared_ptr<AnimationPal> field_1F4_mPal;
s16 field_27C_r = 0;
s16 field_27E_g = 0;
Expand Down
6 changes: 2 additions & 4 deletions Source/Tools/editor/Source/EditorTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void EditorGraphicsView::contextMenuEvent(QContextMenuEvent* pEvent)
QMenu menu(this);

const QPoint scenePos = mapToScene(pEvent->pos()).toPoint();
QList<QGraphicsItem*> itemsAtMousePos = items(scenePos);
QList<QGraphicsItem*> itemsAtMousePos = scene()->items(scenePos);
qDebug() << "There are " << itemsAtMousePos.count() << " at the context menu";

bool cameraAtMenu = false;
Expand Down Expand Up @@ -303,9 +303,7 @@ void EditorGraphicsView::contextMenuEvent(QContextMenuEvent* pEvent)

if (scene()->selectedItems().count() > 0)
{
// TODO: Copy

// TODO: Cut
// TODO: Cut, Copy, Paste, Delete

// TODO: Check if the selection has collision items
// If nothing is selected its impossible to connect collision items
Expand Down
17 changes: 11 additions & 6 deletions Source/Tools/editor/Source/ResizeableArrowItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,30 @@ void ResizeableArrowItem::Visit(IReflector& f)
f.Visit("Length", mLine->mLine.mLineLength);
}

void ResizeableArrowItem::SyncToCollisionItem()
void ResizeableArrowItem::SyncFromCollisionItem()
{
setLine(mLine->X2(), mLine->Y2(), mLine->X1(), mLine->Y1());

// Full repaint because the line type may have changed which changes the line colour
update();
}

void ResizeableArrowItem::PosOrLineChanged()
void ResizeableArrowItem::SyncToCollisionItem()
{
QLineF curLine = line();

// Sync the model to the graphics item
mLine->SetX1(static_cast<int>(curLine.x2()));
mLine->SetY1(static_cast<int>(curLine.y2()));
mLine->SetX2(static_cast<int>(curLine.x1()));
mLine->SetY2(static_cast<int>(curLine.y1()));
mLine->SetX1(static_cast<int>(curLine.x2() + pos().x()));
mLine->SetY1(static_cast<int>(curLine.y2() + pos().y()));
mLine->SetX2(static_cast<int>(curLine.x1() + pos().x()));
mLine->SetY2(static_cast<int>(curLine.y1() + pos().y()));

mLine->CalculateLength();
}

void ResizeableArrowItem::PosOrLineChanged()
{
SyncToCollisionItem();

// Update the property tree view
mPropSyncer.Sync(this);
Expand Down
3 changes: 2 additions & 1 deletion Source/Tools/editor/Source/ResizeableArrowItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ResizeableArrowItem final : public IGraphicsItem, public QGraphicsLineItem

void SyncInternalObject() override
{
SyncToCollisionItem();
SyncFromCollisionItem();
}

void Visit(IReflector& f) override;
Expand All @@ -43,6 +43,7 @@ class ResizeableArrowItem final : public IGraphicsItem, public QGraphicsLineItem
void Init();
void CalcWhichEndOfLineClicked( QPointF aPos, Qt::KeyboardModifiers aMods );
void SetViewCursor(Qt::CursorShape cursor);
void SyncFromCollisionItem();
void SyncToCollisionItem();
void PosOrLineChanged();
private:
Expand Down

0 comments on commit 0cc71bd

Please sign in to comment.