Skip to content

CUIItemUpgrade implementation (anvil UI)#417

Merged
twostars merged 123 commits intoOpen-KO:masterfrom
Mervandeli:itemupgrade
Feb 16, 2026
Merged

CUIItemUpgrade implementation (anvil UI)#417
twostars merged 123 commits intoOpen-KO:masterfrom
Mervandeli:itemupgrade

Conversation

@Mervandeli
Copy link
Contributor

@Mervandeli Mervandeli commented Aug 13, 2025

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Other (please describe):

What is the current behaviour?

-Item Upgrade not implemented

What is the new behaviour?

-The CUIItemUpgrade class has been implemented, and the UI behaviors work the same as in the original 1298 Client. Items can be upgraded correctly.

Why and how did I change this?

-The items in the ItemUpgrade window are copied from the inventory and backed up. When the window is closed or the Cancel button is pressed, the items are restored from the backup. A backup is used to prevent errors when switching between Inventory and ItemUpgrade. If the upgrade process succeeds or fails, the backup is updated accordingly.

Checklist

  • I have performed a self-review of my own code.
  • Where applicable, I have checked to make sure that this doesn't introduce incompatible behaviour with the official 1.298 server (e.g. unofficial opcodes or behavioural differences).
  • I have checked to make sure that this change does not already exist in the codebase in some fashion (e.g. UI already implemented under a different name).

@Mervandeli
Copy link
Contributor Author

Scroll check and other reviews solved.

This ensures it's correct for the right frame and isn't unintentionally influenced between frames,
e.g. when dragging over the top of another icon.

Also fix bugs caused by implicit copies; we should just explicitly clone these as needed, rather than
this though.
Rather than have iffy logic having to constantly try and figure out if it's a copy (to free) or a reference (to absolutely not free, but restore),
we just always allocate a copy regardless.

Additionally, we refactor packet handling to modify the inventory and then just reload the inventory state.
This is simpler than trying to update 2 states (which it wasn't even doing, so they were easily out of state, especially with stack size changes).

Finally, remove MouseProc() - this logic is redundant. It's handled by UIMSG_ICON_DOWN already.
At this level, MouseProc() can trigger a little more generously, at least
when we indicate work has been done (UI_MOUSEPROC_DONESOMETHING).

This allows things to act a little smoother as it still behaves when dragged outside the UI.
It's unclear what exactly we want to copy here; we might want the icon, we might not.

Implicit copy behaviour by default would copy the pointer rather than allocate a new instance,
and then it wouldn't be clear which parent it should be assigned to.

To be very clear about what we want, we explicitly add Clone() to fully clone the entire thing.

Anything else can be handled manually, but it should be rare.
Don't want to touch tools. Too much of a hassle with clang-tidy for now.
Really need to go over tools with clang-tidy so this is not an issue.
Fix sort order to be consistent with official; this should be descending, not ascending
Officially this will act as a 'move' and only show up in the requirement list.
Since we're just cloning, to simulate this, we just selectively hide/show the icon as appropriate.
Copy link
Collaborator

@twostars twostars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've gone through and tried to clean it up as best I could without changing too much.
That addresses a lot of the concerning leaks and potential use-after-free issues, as well as issues referencing the wrong item because it was shared by tooltip code.

Additionally, we add the requirement item sorting to enforce consistency, and generally try to do away with awkward code trying to be too abstract, causing confusion and bugs in the process (e.g. icon 'drop' handling), though I didn't go as hard on that as I'd have liked.

I made the cloning explicit, so it was very clear what was happening and that we could rely on it for icons (without having to do more work).

I refactored the icon management when handling a packet indicating a burned or upgraded item to effectively - for the most part - update the base inventory, and then copy it. The old implementation was excessively confusing and very much looked like it was entirely desyncing, especially when dealing with stacks. It seemed to be trying to make the changes to both the real inventory and the copied inventory, but also.... not actually doing so, really only modifying one side of it in odd conditions.
It's a lot more straightforward now.

Some other minor changes I made but really the brunt of it involved the icon management. That was the biggest issue here.

I think it looks good now, so I'm happy to merge this once @kenner2 also approves it.

@twostars twostars requested a review from kenner2 February 15, 2026 14:42
@twostars twostars changed the title Anvil CUIItemUpgrade implemented Implemented CUIItemUpgrade (anvil UI) Feb 15, 2026
@twostars twostars changed the title Implemented CUIItemUpgrade (anvil UI) CUIItemUpgrade implementation (anvil UI) Feb 15, 2026
On successful upgrades, on the next assignment, it should reset.
When it burns, we shouldn't bother preserving the slot position as
this item is deleted already, and it just blocks us from adding another.

Also make this consistent across right-clicks and left-clicks.
@twostars twostars merged commit 4481584 into Open-KO:master Feb 16, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants