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

Commit

Permalink
Fixes for #144 and #248.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed May 3, 2020
1 parent 9cd0b96 commit 64dff28
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ function PixelVisionOS:OnNextColorPickerCacheStep(data)

end

function PixelVisionOS:ColorPickerChangeColor(data, index, color)

-- print("Change Color", index, color)
Color(index, color)

end

function PixelVisionOS:DrawColorPickerColorItem(data, id)

local totalPixels = data.itemSize.x * data.itemSize.y
Expand All @@ -221,10 +228,9 @@ function PixelVisionOS:DrawColorPickerColorItem(data, id)
if(Color(colorID) == self.maskColor) then
data.canvas.DrawSprites(emptymaskcolor.spriteIDs, x, y, emptymaskcolor.width, false, false)
else

data.canvas.Clear(colorID, x, y, data.itemSize.x, data.itemSize.y)

end

else
data.canvas.DrawSprites(emptycolor.spriteIDs, x, y, emptycolor.width, false, false)
end
Expand Down
43 changes: 39 additions & 4 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-item-picker-v1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function PixelVisionOS:CreateItemPicker(rect, itemSize, columns, rows, colorOffs

data.scrollShift = NewPoint()

data.ctrlCopyEnabled = true

-- Force the display to invalidate
data.invalidateDisplay = true

Expand Down Expand Up @@ -198,23 +200,50 @@ function PixelVisionOS:CreateItemPicker(rect, itemSize, columns, rows, colorOffs

data.UpdateToolTip = function(tmpData)

local action = ""
local label = tmpData.toolTipLabel
local index = 0
local ending = ""

local toolTipMessage = "%s %s ID %0" .. tmpData.totalItemStringPadding .. "d %s"


if(tmpData.dragging) then

if(tmpData.overPos.index ~= nil and tmpData.overPos.index ~= -1 and tmpData.overPos.index < tmpData.picker.total) then
tmpData.picker.toolTip = "Swap "..tmpData.toolTipLabel.." ID " .. string.lpad(tostring(tmpData.pressSelection.index), tmpData.totalItemStringPadding, "0") .. " with ".. string.lpad(tostring(tmpData.overPos.index), tmpData.totalItemStringPadding, "0")



action = tmpData.copyDrag == true and "Copy" or "Swap"

index = tmpData.pressSelection.index
ending = (tmpData.copyDrag == true and "to" or "width") .. " ".. string.lpad(tostring(tmpData.overPos.index), tmpData.totalItemStringPadding, "0")

-- tmpData.picker.toolTip = string.format(toolTipMessage, "swap", tmpData.toolTipLabel, tmpData.pressSelection.index, "with ".. string.lpad(tostring(tmpData.overPos.index), tmpData.totalItemStringPadding, "0"))--"Swap "..tmpData.toolTipLabel.." ID " .. string.lpad(tostring(tmpData.pressSelection.index), tmpData.totalItemStringPadding, "0") .. " with ".. string.lpad(tostring(tmpData.overPos.index), tmpData.totalItemStringPadding, "0")

else
tmpData.picker.toolTip = "Dragging "..tmpData.toolTipLabel.." ID " .. string.lpad(tostring(tmpData.pressSelection.index), tmpData.totalItemStringPadding, "0")

action = "Dragging"
index = tmpData.pressSelection.index

-- tmpData.picker.toolTip = "Dragging "..tmpData.toolTipLabel.." ID " .. string.lpad(tostring(tmpData.pressSelection.index), tmpData.totalItemStringPadding, "0")

end

elseif(tmpData.overPos.index ~= nil and tmpData.overPos.index ~= -1) then

action = "Select"
index = tmpData.overPos.index

-- Update the tooltip with the index and position
tmpData.picker.toolTip = "Select "..tmpData.toolTipLabel.." ID " .. string.lpad(tostring(tmpData.overPos.index), tmpData.totalItemStringPadding, "0")
-- tmpData.picker.toolTip = "Select "..tmpData.toolTipLabel.." ID " .. string.lpad(tostring(tmpData.overPos.index), tmpData.totalItemStringPadding, "0")

else
tmpData.picker.toolTip = ""
toolTipMessage = ""
end

tmpData.picker.toolTip = string.format(toolTipMessage, action, label, index, ending)

end

return data
Expand Down Expand Up @@ -356,8 +385,14 @@ function PixelVisionOS:UpdateItemPicker(data)

data.overPos = self:CalculateItemPickerPosition(data)

-- Reset copy drag flag
data.copyDrag = false

if(data.dragging == true) then

-- 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

-- data.overPos = self:CalculateItemPickerPosition(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ end
function EditorUI:ChangeInputField(data, text, trigger)
-- Input fields need to process the text before setting it

print(data.name, "ChangeInputField", text)
-- print(data.name, "ChangeInputField", text)

-- Look for any custom validation
if(data.onValidate ~= nil) then
Expand Down
39 changes: 25 additions & 14 deletions Disks/PixelVisionOS/System/Tools/ColorTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ function Init()
true -- drag between pages
)

systemColorPickerData.ctrlCopyEnabled = false

systemColorPickerData.onPageAction = function(value)

local bgColor = gameEditor:BackgroundColor()
Expand Down Expand Up @@ -403,7 +405,7 @@ function OnAddDroppedColor(id, dest, color)

local index = pixelVisionOS.colorOffset + pixelVisionOS.totalPaletteColors + (id)

Color(index, color)
pixelVisionOS:ColorPickerChangeColor(picker, index, color)

InvalidateData()

Expand All @@ -415,24 +417,29 @@ function OnSystemColorDropTarget(src, dest)
if(src.name == dest.name) then

-- Get the source color ID
srcPos = src.pressSelection
local srcPos = src.pressSelection

-- Get the destination color ID
local destPos = pixelVisionOS:CalculateItemPickerPosition(src)

local pageOffset = (systemColorPickerData.pages.currentSelection - 1) * systemColorPickerData.totalPerPage

if((destPos.index - pageOffset) < dest.picker.total) then
-- if((destPos.index - pageOffset) < dest.picker.total) then

-- Need to shift src and dest ids based onthe color offset
-- Need to shift src and dest ids based on the color offset
local realSrcID = srcPos.index + src.altColorOffset
local realDestID = destPos.index + dest.altColorOffset

-- Make sure the colors are not the same
if(realSrcID ~= realDestID) then

-- Get the src and dest color hex value
local srcColor = Color(realSrcID)
local destColor = Color(realDestID)
local destColor = src.copyDrag == true and srcColor or Color(realDestID)

if(Key(Keys.LeftControl) == true or Key(Keys.RightControl) == true) then
print("Copy")
end

-- Make sure we are not moving a transparent color
if(srcColor == pixelVisionOS.maskColor or destColor == pixelVisionOS.maskColor) then
Expand All @@ -448,8 +455,8 @@ function OnSystemColorDropTarget(src, dest)
end

-- Swap the colors in the tool's color memory
Color(realSrcID, destColor)
Color(realDestID, srcColor)
pixelVisionOS:ColorPickerChangeColor(picker, realSrcID, destColor)
pixelVisionOS:ColorPickerChangeColor(picker, realDestID, srcColor)

-- Update just the colors that changed
local srcPixelData = pixelVisionOS:ReadItemPickerOverPixelData(src, srcPos.x, srcPos.y)
Expand All @@ -471,7 +478,7 @@ function OnSystemColorDropTarget(src, dest)

end

end
-- end

end

Expand Down Expand Up @@ -585,7 +592,7 @@ function OnPaste()

-- print("Paste", lastMode, src.name, colorID, src.currentSelection, src.altColorOffset)

Color(colorID, copyValue)
pixelVisionOS:ColorPickerChangeColor(picker, colorID, copyValue)
pixelVisionOS:EnableMenuItem(CopyShortcut, true)
pixelVisionOS:EnableMenuItem(PasteShortcut, false)
copyValue = nil
Expand Down Expand Up @@ -783,7 +790,7 @@ function OnAdd()
for i = 1, pixelVisionOS.totalSystemColors do

local index = (i - 1) + pixelVisionOS.colorOffset
Color(index, colors[i])
pixelVisionOS:ColorPickerChangeColor(picker, index, colors[i])

end

Expand Down Expand Up @@ -829,9 +836,13 @@ function OnClear()
-- Get the real color ID from the offset
local realColorID = picker.currentSelection + picker.altColorOffset

print("Clear", picker.currentSelection, picker.altColorOffset, realColorID, pixelVisionOS.maskColor)


-- Set the color to the mask value
Color(realColorID, pixelVisionOS.maskColor)
pixelVisionOS:ColorPickerChangeColor(picker, realColorID, pixelVisionOS.maskColor)

-- pixelVisionOS:RebuildColorPickerCache(picker)
pixelVisionOS:DrawColorPickerColorItem(picker, picker.currentSelection)

-- Redraw the pickers current page
Expand Down Expand Up @@ -920,7 +931,7 @@ function UpdateHexColor(value)
-- end

-- Update the editor's color
local newColor = Color(realColorID, value)
local newColor = pixelVisionOS:ColorPickerChangeColor(picker, realColorID, value)


-- TODO this should be used in the palette not the system colors
Expand All @@ -941,7 +952,7 @@ function UpdateHexColor(value)
if(tmpColor == currentColor and tmpColor ~= pixelVisionOS.maskColor) then

-- Set the color to equal the new color
Color(index, value)
pixelVisionOS:ColorPickerChangeColor(picker, index, value)

end

Expand Down Expand Up @@ -993,7 +1004,7 @@ function DeleteSystemColor(value)
local realColorID = value + systemColorPickerData.altColorOffset

-- Set the current tool's color to the mask value
Color(realColorID, pixelVisionOS.maskColor)
pixelVisionOS:ColorPickerChangeColor(picker,realColorID, pixelVisionOS.maskColor)

-- Copy all the colors to the game
pixelVisionOS:CopyToolColorsToGameMemory()
Expand Down
16 changes: 15 additions & 1 deletion Disks/PixelVisionOS/System/Tools/ColorTool/saves.json
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
{"GameChip":{"savedData":{"selectedSprite": "-1","selectedPalette": "-1","selectedColor": "-1","rootDirectory": "/Workspace/Test/TestB/","sessionID": "202005020933213666","selectedSpritePage": "1","selectedPalettePage": "0"}}}
{

"GameChip":
{
"savedData":{
"selectedPalettePage": "1",
"selectedSpritePage": "1",
"sessionID": "202005031040599195",
"rootDirectory": "/Workspace/NewProjectB/",
"selectedColor": "-1",
"selectedPalette": "-1",
"selectedSprite": "-1"
}
}
}
4 changes: 2 additions & 2 deletions Disks/PixelVisionOS/System/Tools/WorkspaceTool/saves.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"GameChip":
{
"savedData":{
"sessionID": "202005030916473679",
"sessionID": "202005031040599195",
"scrollPos": "0",
"selection": "10",
"selection": "9",
"lastPath": "/Workspace/NewProjectB/"
}
}
Expand Down

0 comments on commit 64dff28

Please sign in to comment.