Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Fixes for #293, #261, #341, #354, and #302.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Jul 3, 2020
1 parent 51e792b commit c21a985
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ function PixelVisionOS:RedrawCanvas(data)
if(data.paintCanvas.invalid == true) then

-- Draw the final canvas to the display on each frame
data.paintCanvas:DrawPixels(data.rect.x, data.rect.y, DrawMode.TilemapCache, data.scale, bgColor, data.emptyColorID)
data.paintCanvas:DrawPixels(data.rect.x, data.rect.y, DrawMode.TilemapCache, data.scale, data.emptyColorID, bgColor)

data.paintCanvas:ResetValidation()

Expand Down
52 changes: 27 additions & 25 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-item-picker-v3.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function PixelVisionOS:CreateItemPicker(rect, itemSize, columns, rows, colorOffset, spriteName, toolTip, enableDragging, draggingLabel)

-- Create the component's base values
local data = self.editorUI:CreateData(rect)
local data = editorUI:CreateData(rect)

data.name = "ItemPicker" .. data.name

Expand Down Expand Up @@ -110,16 +110,17 @@ function PixelVisionOS:CreateItemPicker(rect, itemSize, columns, rows, colorOffs
end

-- Picker component to use for selection
data.picker = self.editorUI:CreatePicker({x = data.visibleRect.x, y = data.visibleRect.y, w = data.visibleRect.w, h = data.visibleRect.h}, itemSize.x, itemSize.y, data.totalItems, spriteName, toolTip)
data.picker = editorUI:CreatePicker({x = data.visibleRect.x, y = data.visibleRect.y, w = data.visibleRect.w, h = data.visibleRect.h}, itemSize.x, itemSize.y, data.totalItems, spriteName, toolTip)

-- Keep the picker from drawing the over graphic
data.picker.drawOver = false

data.picker.onAction = function(value, doubleClick)

if(self.currentButtonDown == data.name) then
print("OnAction")
if(editorUI.inFocusUI.name == data.name) then

self.currentButtonDown = nil
-- editorUI.inFocusUI = nil
data.pressSelection = nil

value = self:CalculateItemPickerPosition(data).index
Expand All @@ -136,7 +137,7 @@ function PixelVisionOS:CreateItemPicker(rect, itemSize, columns, rows, colorOffs

data.picker.onPress = function()

self.currentButtonDown = data.name
-- editorUI.inFocusUI = data

-- Store the current ID being pressed
data.pressSelection = self:CalculateItemPickerPosition(data)
Expand Down Expand Up @@ -194,12 +195,12 @@ function PixelVisionOS:CreateItemPicker(rect, itemSize, columns, rows, colorOffs
data.enableDragging = enableDragging

if(data.enableDragging == true) then
self.editorUI.collisionManager:EnableDragging(data, .2, data.draggingLabel)
editorUI.collisionManager:EnableDragging(data, .2, data.draggingLabel)

-- Make sure we capture the onEndDrag event, clear the selection and pass it back to the collisionManager
data.onEndDrag = function(target)

self.editorUI.collisionManager:EndDrag(target)
editorUI.collisionManager:EndDrag(target)

data.pressSelection = nil
end
Expand Down Expand Up @@ -369,8 +370,9 @@ function PixelVisionOS:UpdateItemPicker(data)

-- Calculate the bg color
local bgColor = data.showBGColor and gameEditor:BackgroundColor() or (self.emptyColorID - data.colorOffset - 1)

gameEditor:CopyCanvasToDisplay(data.canvas, data.visibleRect.x, data.visibleRect.y, data.visibleRect.w, data.visibleRect.h, data.colorOffset, bgColor, data.viewport.x + data.lastStartX, data.viewport.y + data.lastStartY )
--int x = 0, int y = 0, DrawMode drawMode = DrawMode.TilemapCache, int scale = 1, int maskColor = -1, int maskColorID = -1, Rectangle? viewport = null
data.canvas:DrawPixels( data.visibleRect.x, data.visibleRect.y, DrawMode.TilemapCache, 1, -1, bgColor, data.colorOffset, NewRect(data.viewport.x + data.lastStartX, data.viewport.y + data.lastStartY, data.visibleRect.w, data.visibleRect.h))
-- gameEditor:CopyCanvasToDisplay(data.canvas, data.visibleRect.x, data.visibleRect.y, data.visibleRect.w, data.visibleRect.h, data.colorOffset, bgColor, data.viewport.x + data.lastStartX, data.viewport.y + data.lastStartY )

-- Reset the display invalidation
data.invalidateDisplay = false
Expand Down Expand Up @@ -401,14 +403,14 @@ function PixelVisionOS:UpdateItemPicker(data)
-- See if control is down while dragging
data.copyDrag = (Key(Keys.LeftControl) == true or Key(Keys.RightControl) == true) and data.ctrlCopyEnabled == true

if(self.editorUI.collisionManager:MouseInRect(data.visibleRect) and data.overPos.index < data.total) then
if(editorUI.collisionManager:MouseInRect(data.visibleRect) and data.overPos.index < data.total) then

-- data.overPos = self:CalculateItemPickerPosition(data)
data.overPos.x = data.visibleRect.x + (data.overPos.x * data.itemSize.x) - data.lastStartX
data.overPos.y = data.visibleRect.y + (data.overPos.y * data.itemSize.y) - data.lastStartY
else
data.overPos.x = self.editorUI.collisionManager.mousePos.x
data.overPos.y = self.editorUI.collisionManager.mousePos.y
data.overPos.x = editorUI.collisionManager.mousePos.x
data.overPos.y = editorUI.collisionManager.mousePos.y

-- Offset the item so you can see it under the cursor
-- local offset =
Expand All @@ -431,23 +433,23 @@ function PixelVisionOS:UpdateItemPicker(data)
if(data.viewport:Contains(NewPoint(data.emptyDrawArgs[2] - data.visibleRect.x, data.emptyDrawArgs[3] - data.visibleRect.y))) then

-- Draw empty tiles
self.editorUI:NewDraw("DrawSprites", data.emptyDrawArgs)
editorUI:NewDraw("DrawSprites", data.emptyDrawArgs)

end

end

data.scrollOverTime = data.scrollOverTime + self.editorUI.timeDelta
data.scrollOverTime = data.scrollOverTime + editorUI.timeDelta

if(data.scrollOverTime > data.scrollOverDelay) then
-- See if the dragged item is inside of the other UI elements
if(data.vSlider ~= nil and self.editorUI.collisionManager:MouseInRect(data.vSlider.rect) == true) then
if(data.vSlider ~= nil and editorUI.collisionManager:MouseInRect(data.vSlider.rect) == true) then

self.editorUI:UpdateSliderPosition(data.vSlider)
editorUI:UpdateSliderPosition(data.vSlider)

elseif(data.hSlider ~= nil and self.editorUI.collisionManager:MouseInRect(data.hSlider.rect) == true) then
elseif(data.hSlider ~= nil and editorUI.collisionManager:MouseInRect(data.hSlider.rect) == true) then

self.editorUI:UpdateSliderPosition(data.hSlider)
editorUI:UpdateSliderPosition(data.hSlider)

else
-- Reset page over flag
Expand All @@ -465,7 +467,7 @@ function PixelVisionOS:UpdateItemPicker(data)

-- Make sure we are following the mouse if we are not over an item
if(data.overPos.index == -1) then
data.overPos = self.editorUI.collisionManager.mousePos
data.overPos = editorUI.collisionManager.mousePos
end

data.overPos.x = data.rect.x + (data.overPos.x * data.itemSize.x) - data.lastStartX
Expand Down Expand Up @@ -507,13 +509,13 @@ function PixelVisionOS:UpdateItemPicker(data)

if( data.overPos.x > - offscreen and (data.overPos.x + data.tmpItemRect.width) < (data.displaySize.x + offscreen) and data.overPos.y > - offscreen and (data.overPos.y + data.tmpItemRect.height) < (data.displaySize.y + offscreen)) then
-- -- Draw rect behind the over selection
self.editorUI:NewDraw("DrawRect", data.maskSpriteDrawArgs)
editorUI:NewDraw("DrawRect", data.maskSpriteDrawArgs)

-- Draw selected sprites in the background
self.editorUI:NewDraw("DrawPixels", data.overItemDrawArgs)
editorUI:NewDraw("DrawPixels", data.overItemDrawArgs)

-- Draw the selection box on top
self.editorUI:NewDraw("DrawSprites", data.picker.overDrawArgs)
editorUI:NewDraw("DrawSprites", data.picker.overDrawArgs)

end

Expand Down Expand Up @@ -569,16 +571,16 @@ end

function PixelVisionOS:CalculateItemPickerPosition(data, x, y)

x = x or self.editorUI.collisionManager.mousePos.x
y = y or self.editorUI.collisionManager.mousePos.y
x = x or editorUI.collisionManager.mousePos.x
y = y or editorUI.collisionManager.mousePos.y

local position =
{
x = math.floor((x - data.rect.x) / data.itemSize.x),
y = math.floor((y - data.rect.y) / data.itemSize.y),
}

if(self.editorUI.collisionManager:MouseInRect(data.visibleRect)) then
if(editorUI.collisionManager:MouseInRect(data.visibleRect)) then

-- Offset for scroll
position.x = position.x + (data.lastStartX / data.itemSize.x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ function PixelVisionOS:CreateSpritePicker(rect, itemSize, columns, rows, colorOf
data.pagePosition.x = data.pagePosition.x + 16
end

data.picker.onAction = function(value, doubleClick)

-- Clear the last over id to force the over box to redraw
data.lastSpriteID = value

value = self:CalculateItemPickerPosition(data)

if(data.onAction ~= nil) then
data.onAction(value.index, doubleClick)
end

end

data.pages = editorUI:CreateToggleGroup()

data.pages.onAction = function(value)
Expand Down
4 changes: 0 additions & 4 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,9 @@ end
function PixelVisionOS:Draw()

if(self.editorUI.inFocusUI ~= nil and self.editorUI.inFocusUI.toolTip ~= nil) then

self:DisplayToolTip(self.editorUI.inFocusUI.toolTip)

else
self:ClearToolTip()
-- clear tool tip message

end

-- We manually call draw on the message bar since it can be updated at any point outside of its own update call
Expand Down
10 changes: 6 additions & 4 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-ui-button-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@ function EditorUI:CreateButton(rect, spriteName, toolTip, forceDraw)
data.onClick = function(tmpData)

-- Only trigger the click action when the last pressed button name matches
if(self.currentButtonDown == tmpData.name) then
if(self.inFocusUI.name == tmpData.name) then
self:ClickButton(tmpData, true, tmpData.doubleClickActive and tmpData.doubleClickTime < tmpData.doubleClickDelay)

self.currentButtonDown = nil
-- self.inFocusUI = nil
tmpData.doubleClickTime = 0
tmpData.doubleClickActive = true
tmpData.doubleClick = true
end

end

-- On First Press (Called when the button)
data.onFirstPress = function(tmpData)

-- Save the name of the button that was just pressed
self.currentButtonDown = tmpData.name
-- self.inFocusUI = tmpData

self:PressButton(tmpData, true)
end
Expand Down Expand Up @@ -188,6 +189,7 @@ function EditorUI:UpdateButton(data, hitRect)
-- Click the button
data.onClick(data)
data.firstPress = true

elseif(self.collisionManager.mouseDown) then

if(data.firstPress ~= false) then
Expand All @@ -202,11 +204,11 @@ function EditorUI:UpdateButton(data, hitRect)

else

-- On Release Outside
if(data.inFocus == true) then
data.firstPress = true
-- If we are not in the button's rect, clear the focus
self:ClearFocus(data)

end

end
Expand Down
6 changes: 2 additions & 4 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-ui-picker-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ function EditorUI:CreatePicker(rect, itemWidth, itemHeight, total, spriteName, t

data.onClick = function(tmpData)

if(self.currentPickerDown == tmpData.name) then


if(self.inFocusUI.name == tmpData.name) then

self:PickerClick(tmpData, true, tmpData.doubleClickActive and tmpData.doubleClickTime < tmpData.doubleClickDelay)

Expand All @@ -78,7 +76,7 @@ function EditorUI:CreatePicker(rect, itemWidth, itemHeight, total, spriteName, t

data.onFirstPress = function(tmpData)

self.currentPickerDown = tmpData.name
self.inFocusUI = tmpData
self:PickerPress(tmpData, true)
end

Expand Down
20 changes: 16 additions & 4 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-ui-text-editor-v1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1142,20 +1142,32 @@ end

function EditorUI:TextEditorUpdate(data, dt)

-- Make sure we don't detect a collision if the mouse is down but not over this button
if(self.collisionManager.mouseDown and data.inFocus == false) then

-- If we lose focus while the mouse is down but still in edit mode we need to clear that
if(data.editing == true) then
self:EditTextEditor(data, false)
end

return

end

local overrideFocus = (data.inFocus == true and self.collisionManager.mouseDown)

-- TODO this should be only happen when in focus
local cx = self.collisionManager.mousePos.c - data.tiles.c
local cy = self.collisionManager.mousePos.r - data.tiles.r

-- print("Inside Text", data.name)
-- print("Inside Text", (editorUI.inFocusUI ~= nil and editorUI.inFocusUI.name or nil))
-- Ready to test finer collision if needed
if(self.collisionManager:MouseInRect(data.rect) == true or overrideFocus) then
if((self.collisionManager:MouseInRect(data.rect) == true or overrideFocus)) then

if(data.enabled == true and data.editable == true) then

if(data.inFocus == false) then

print("in focus")
-- Set focus
self:SetFocus(data, 3)
end
Expand All @@ -1179,7 +1191,7 @@ function EditorUI:TextEditorUpdate(data, dt)

end

else
elseif(data.inFocus == true) then
-- If the mouse isn't over the component clear the focus
self:ClearFocus(data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function EditorUI:CreateToggleButton(rect, spriteName, toolTip, forceDraw)
data.onClick = function(tmpData)

-- Only trigger the click action when the last pressed button name matches
if(self.currentButtonDown == tmpData.name) then
if(self.inFocusUI == tmpData) then
self:ToggleButton(tmpData)
end

Expand Down

0 comments on commit c21a985

Please sign in to comment.