Background ~ Someone mentioned this in the QQ group, and I needed another one. So I wrote this article.
-- Main. Lua Require " Main_box " -- It is best to write a backpack lattice as a class -- -------------------------- -- Main_box.lua Box = {} -- Initialize a grid of 6*4 data records For N = 1 , 6 Do For I = 1 , 4 Do Box [N] [m] = {ID = 0 -- Item ID Boxline = 70 , -- I use a square lattice with a side length of 70 XP. Light = False -- Highlighted border End End -- Boxin is a put function. Function Boxin (ID) Local Full = True For N = 1 , 6 Do For I = 1 , 4 Do If (Box [N] [M]. ID = 0 ) Then Box [N] [M]. ID = Id full = False End End End If (Full) Then -- Given in fullCode End End -- Add item Boxin ( 1 ) Boxin ( 2 )
Then the question is someone in the QQ Group asked: "How can I exchange items? "
First, write the "joystick" of an item. What do you mean?
It is the one that records the selected item data when the cursor (or mouse) selects an item.
UB = {}--The "joystick" usebox of the itemIf(First, check whether the cursor is in the package area after the cursor is clicked)And(The cursor position is detected here, or the cursor position in the package area is determined)ThenLocalX, Y =Here we return the position after the cursor is rounded up or the location after the mouse is rounded up ub. Out.= Box [X], box [X], box [x] [Y]. ID--The computer knows what you choose.Box [x] [Y]. Light =True--Highlight the selected item--[[For a mouse operation, you can add a cache to show the moving items at the mouse position and hide the picture of the moved items.]
Next, place or exchange items.
When the cursor is determined at the new position or the left button is released at the new position
That is, you can call the function to determine the location
* Be sure to add the same judgment as the original location.
-- The moment when the cursor is determined, or the moment when the left mouse is released, the item is exchanged or placed. If (......) Then -- Newx and newy indicate the new location UB. ID = newx, newy, box [newx] [newy]. ID -- Get item ID Box [newx] [newy]. ID = ub. ID -- Alternate old and new Box [ub. x] [ub. Y]. ID = ub. ID -- If the new one is empty, it is equivalent to moving the location. UB. X, UB. Y, UB. ID = newx, newy, UB. ID-- The selected grid changes. -- There are also some changes to the cursor position. -- I will not write anything about the highlighted border. ......... End
That's it.
I feel like I'm talking so much nonsense, but it's okay because I'm not tired of typing ~
It is hard to understand or have some simple-single-or-whimsical ideas that won't write code and then @ me.