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

Commit

Permalink
Fixes for #301, #328, #330, #332, #340, #212, #358, #360, #361, #363, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Jul 14, 2020
1 parent 345aff3 commit 8e08ede
Show file tree
Hide file tree
Showing 150 changed files with 1,944 additions and 569 deletions.
8 changes: 5 additions & 3 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-canvas-v3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,12 @@ function PixelVisionOS:DrawOnCanvas(data, mousePos, toolID)

-- TODO this doesn't appear to do anything
data.overColor = data.paintCanvas:ReadPixelAt(mousePos.x, mousePos.y) - data.colorOffset

-- elseif(data.tool == "select") then

-- -- print("select", data.startPos.x, data.startPos.y)
if(data.overColor > pixelVisionOS.colorsPerSprite) then
data.overColor = -1
end

-- TODO should we display this value or that it is out of bounds?

end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ function PixelVisionOS:ImportColorsFromGame()

local tmpMaskColor = self.systemColors[1]

self.palettesAreEmpty = true

for i = 129, self.totalColors do

local index = i - 1
Expand All @@ -125,12 +127,16 @@ function PixelVisionOS:ImportColorsFromGame()

end

if(self.palettesAreEmpty == true and color ~= tmpMaskColor) then
self.palettesAreEmpty = false
end

Color(index + self.colorOffset, color)

end

self.totalSystemColors = #self.systemColors

end

function PixelVisionOS:CopyToolColorsToGameMemory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,24 +362,25 @@ end
function PixelVisionOS:UpdateItemPicker(data)

editorUI:UpdatePicker(data.picker)
editorUI:UpdateSlider(data.vSlider)
editorUI:UpdateSlider(data.hSlider)


if(data.invalidateDisplay == true) then

self:UpdateItemPickerSelection(data)

-- Calculate the bg color
local bgColor = data.showBGColor and gameEditor:BackgroundColor() or (self.emptyColorID - data.colorOffset - 1)
--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 )

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), data.isolateSpriteColors)

-- Reset the display invalidation
data.invalidateDisplay = false

end

editorUI:UpdateSlider(data.vSlider)
editorUI:UpdateSlider(data.hSlider)

-- Clear dragging value if dragging is not enabled
if(data.enableDragging == false) then
data.dragging = false
Expand Down Expand Up @@ -431,7 +432,7 @@ function PixelVisionOS:UpdateItemPicker(data)
data.emptyDrawArgs[3] = data.visibleRect.y + (data.pressSelection.y * data.itemSize.y) - data.lastStartY

-- Make sure that the empty sprites are inside the viewport before drawing them
if(data.viewport:Contains(NewPoint(data.emptyDrawArgs[2] - data.visibleRect.x, data.emptyDrawArgs[3] - data.visibleRect.y))) then
if(data.drawEmpty ~= false and data.viewport:Contains(NewPoint(data.emptyDrawArgs[2] - data.visibleRect.x, data.emptyDrawArgs[3] - data.visibleRect.y))) then

-- Draw empty tiles
editorUI:NewDraw("DrawSprites", data.emptyDrawArgs)
Expand Down Expand Up @@ -508,7 +509,7 @@ function PixelVisionOS:UpdateItemPicker(data)

local offscreen = Clamp(data.tmpItemRect.width / 2, 0, 8)

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
if( data.drawOver ~= false and 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
editorUI:NewDraw("DrawRect", data.maskSpriteDrawArgs)

Expand Down
160 changes: 160 additions & 0 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-message-modal-v3.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
MessageModal = {}
MessageModal.__index = MessageModal

function MessageModal:Init(title, message, width, showCancel)

local _messageModal = {} -- our new object
setmetatable(_messageModal, MessageModal) -- make Account handle lookup

_messageModal:Configure(title, message, width, showCancel)

return _messageModal

end

function MessageModal:Configure(title, message, width, showCancel, okButtonSpriteName)

self.showCancel = showCancel or false

self.okButtonSpriteName = okButtonSpriteName or "ok"
-- Reset the modal so it redraws correctly when opened
self.firstRun = nil

width = width or 96

-- Need to calculate the height ahead of time
-- Draw message text
local wrap = WordWrap(message, (width / 4) - 4)
self.lines = SplitLines(wrap)

height = #self.lines * 8 + 42

-- Make sure width and height are on the grid
width = math.floor(width / 8) * 8
height = math.floor(height / 8) * 8

self.canvas = NewCanvas(width, height)

local displaySize = Display()

self.title = title or "Message Modal"

self.rect = {
x = math.floor(((displaySize.x - width) * .5) / 8) * 8,
y = math.floor(((displaySize.y - height) * .5) / 8) * 8,
w = width,
h = height
}

self.selectionValue = false

end

function MessageModal:Open()

if(self.firstRun == nil) then

-- Draw the black background
self.canvas:SetStroke({5}, 1, 1)
self.canvas:SetPattern({0}, 1, 1)
self.canvas:DrawSquare(0, 0, self.canvas.width - 1, self.canvas.height - 1, true)

-- Draw the brown background
self.canvas:SetStroke({12}, 1, 1)
self.canvas:SetPattern({11}, 1, 1)
self.canvas:DrawSquare(3, 9, self.canvas.width - 4, self.canvas.height - 4, true)

local tmpX = (self.canvas.width - (#self.title * 4)) * .5

self.canvas:DrawText(self.title:upper(), tmpX, 1, "small", 15, - 4)

-- draw highlight stroke
self.canvas:SetStroke({15}, 1, 1)
self.canvas:DrawLine(3, 9, self.canvas.width - 5, 9)
self.canvas:DrawLine(3, 9, 3, self.canvas.height - 5)

local total = #self.lines
local startX = 8
local startY = 16

-- We want to render the text from the bottom of the screen so we offset it and loop backwards.
for i = 1, total do
self.canvas:DrawText(self.lines[i]:upper(), startX, (startY + ((i - 1) * 8)), "medium", 0, - 4)
end

self.buttons = {}

local buttonSize = {x = 32, y = 16}

-- TODO center ok button when no cancel button is shown
local bX = self.showCancel == true and (self.rect.w - buttonSize.x - 8) or ((self.rect.w - buttonSize.x) * .5)

-- snap the x value to the grid
bX = math.floor((bX + self.rect.x) / 8) * 8

-- Fix the button to the bottom of the window
local bY = math.floor(((self.rect.y + self.rect.h) - buttonSize.y - 8) / 8) * 8

local backBtnData = editorUI:CreateButton({x = bX, y = bY}, "modal".. self.okButtonSpriteName .. "button", "")

backBtnData.onAction = function()

-- Set value to true when ok is pressed
self.selectionValue = true

if(self.onParentClose ~= nil) then
self.onParentClose()
end
end

table.insert(self.buttons, backBtnData)

if(self.showCancel) then

-- Offset the bX value and snap to the grid
bX = math.floor((bX - buttonSize.x - 8) / 8) * 8

local cancelBtnData = editorUI:CreateButton({x = bX, y = bY}, "modalcancelbutton", "")

cancelBtnData.onAction = function()

-- Set value to true when cancel is pressed
self.selectionValue = false

-- Close the panel
if(self.onParentClose ~= nil) then
self.onParentClose()
end
end

table.insert(self.buttons, cancelBtnData)

end

self.firstRun = false;

end

for i = 1, #self.buttons do
editorUI:Invalidate(self.buttons[i])
end

self.canvas:DrawPixels(self.rect.x, self.rect.y, DrawMode.TilemapCache)

end

function MessageModal:Update(timeDelta)

for i = 1, #self.buttons do
editorUI:UpdateButton(self.buttons[i])
end

if(Key(Keys.Enter, InputState.Released)) then
self.selectionValue = true
self.onParentClose()
elseif(Key(Keys.Escape, InputState.Released) and self.showCancel) then
self.selectionValue = false
self.onParentClose()
end

end
3 changes: 2 additions & 1 deletion Disks/PixelVisionOS/System/Libs/pixel-vision-os-modal-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function PixelVisionOS:UpdateModal(timeDelta)
if(self.onCloseCallback ~= nil) then
self.onCloseCallback()

self.onCloseCallback = nil
-- TODO disabled this because of a race condition when one modal is called after another
-- self.onCloseCallback = nil
end

-- Enable the menu button in the toolbar
Expand Down

0 comments on commit 8e08ede

Please sign in to comment.