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

Commit

Permalink
Adding mouse wheel support and rebuilding the Settings Tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Apr 26, 2020
1 parent 30a323e commit 4924fea
Show file tree
Hide file tree
Showing 47 changed files with 2,405 additions and 1,337 deletions.
22 changes: 14 additions & 8 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-message-bar-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function PixelVisionOS:CreateMessageBar(x, y, maxChars, clearColorID)
currentMessage = "",
mode = 1,
invalid = false,
clearColorID = clearColorID or BackgroundColor(),
clearColorID = clearColorID or nil,
modes = {
Empty = 1,
Message = 2,
Expand All @@ -51,7 +51,7 @@ function PixelVisionOS:CreateMessageBar(x, y, maxChars, clearColorID)
data.pos.y,
data.maxChars * 4,
8,
data.clearColorID,
-1,
DrawMode.TilemapCache
}

Expand All @@ -63,7 +63,7 @@ function PixelVisionOS:UpdateMessageBar(data)

if(data.delay == -1) then

if(self.editorUI.collisionManager.hovered == -1) then
if(editorUI.collisionManager.hovered == -1) then
-- If _messageBar delay is set to 0 then clear it
if(data.currentMessage ~= "") then
self:ClearMessage(data)
Expand All @@ -78,7 +78,7 @@ function PixelVisionOS:UpdateMessageBar(data)
return
end

data.time = data.time + self.editorUI.timeDelta
data.time = data.time + editorUI.timeDelta

if(data.delay > 0) then
if(data.time > data.delay) then
Expand All @@ -91,17 +91,23 @@ end
-- Unlike other components, the message bar is manually drawn last since its message can be updated outside of the update loop by other components
function PixelVisionOS:DrawMessageBar(data)
if(data.invalid == true) then

if(data.clearColorID == nil) then
data.clearColorID = BackgroundColor()
data.clearDrawArgs[5] = data.clearColorID
end

local length = data.maxChars - #data.currentMessage + 1

if(length < 0) then
length = 0
end

data.textDrawArgs[1] = string.upper(data.currentMessage)
self.editorUI:NewDraw("DrawRect", data.clearDrawArgs)
self.editorUI:NewDraw("DrawText", data.textDrawArgs)
editorUI:NewDraw("DrawRect", data.clearDrawArgs)
editorUI:NewDraw("DrawText", data.textDrawArgs)

self.editorUI:ResetValidation(data)
editorUI:ResetValidation(data)
end
end

Expand All @@ -128,7 +134,7 @@ function PixelVisionOS:DisplayMessage(text, delay, data)
data.delay = delay or 2
data.time = 0
data.mode = data.modes.Message
self.editorUI:Invalidate(data)
editorUI:Invalidate(data)

end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function MessageModal:Open()
-- 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 = self.editorUI:CreateButton({x = bX, y = bY}, "modalokbutton", "")
local backBtnData = editorUI:CreateButton({x = bX, y = bY}, "modalokbutton", "")

backBtnData.onAction = function()

Expand All @@ -113,7 +113,7 @@ function MessageModal:Open()
-- Offset the bX value and snap to the grid
bX = math.floor((bX - buttonSize.x - 8) / 8) * 8

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

cancelBtnData.onAction = function()

Expand All @@ -135,7 +135,7 @@ function MessageModal:Open()
end

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

self.canvas:DrawPixels(self.rect.x, self.rect.y, DrawMode.TilemapCache)
Expand All @@ -145,7 +145,7 @@ end
function MessageModal:Update(timeDelta)

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

if(Key(Keys.Enter, InputState.Released)) then
Expand Down
10 changes: 5 additions & 5 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-modal-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function PixelVisionOS:OpenModal(modal, callBack)
self.closeTime = -1

-- Clear the previous mouse focus
self.editorUI:ClearFocus()
editorUI:ClearFocus()

-- Set the active modal
self.activeModal = modal
Expand All @@ -38,7 +38,7 @@ function PixelVisionOS:OpenModal(modal, callBack)
self.activeModal:Open()

-- Disable the menu button in the toolbar
self.editorUI:Enable(self.titleBar.iconButton, false)
editorUI:Enable(self.titleBar.iconButton, false)

end

Expand All @@ -49,7 +49,7 @@ function PixelVisionOS:CloseModal()
self.activeModal:Close()
end

self.editorUI:ClearFocus()
editorUI:ClearFocus()

RestoreTilemapCache()

Expand All @@ -65,9 +65,9 @@ function PixelVisionOS:CloseModal()
end

-- Enable the menu button in the toolbar
self.editorUI:Enable(self.titleBar.iconButton, true)
editorUI:Enable(self.titleBar.iconButton, true)

self.editorUI:Invalidate(self.titleBar)
editorUI:Invalidate(self.titleBar)

end

Expand Down
92 changes: 84 additions & 8 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ LoadScript("pixel-vision-os-clipboard-v2")
LoadScript("pixel-vision-os-version")

function PixelVisionOS:Init()

-- Get a global reference to the Editor UI
_G["editorUI"] = EditorUI:Init()

-- Create a new object for the instance and register it
local _pixelVisionOS = {
editorUI = EditorUI:Init(),
version = _G["PixelVisionOSVersion"] or "v2.6"
editorUI = editorUI,
version = _G["PixelVisionOSVersion"] or "v2.6",
uiComponents = {},
uiTotal = 0
}
setmetatable(_pixelVisionOS, PixelVisionOS)

Expand Down Expand Up @@ -63,6 +69,26 @@ function PixelVisionOS:Update(timeDelta)
self:UpdateModal(timeDelta)
-- end

-- Loop through all of the registered UI and update them
for i = 1, self.uiTotal do

-- Get a reference to the UI data
local ref = self.uiComponents[i]

if(ref ~= nil) then

-- Only update UI when the modal is not active
if(pixelVisionOS:IsModalActive() == false or ref.ignoreModal) then

-- Call the UI scope's update and pass back in the UI data
ref.uiScope[ref.uiUpdate](ref.uiScope, ref.uiData)

end

end

end

end

function PixelVisionOS:Draw()
Expand Down Expand Up @@ -226,12 +252,6 @@ function PixelVisionOS:ValidateGameInDir(workspacePath, requiredFiles)

requiredFiles = requiredFiles or {"data.json", "info.json"}

-- if(extraFiles ~= nil) then
-- for i = 1, #extraFiles do
-- table.insert(requiredFiles, extraFiles[i])
-- end
-- end

local flag = 0

local total = #requiredFiles
Expand All @@ -245,3 +265,59 @@ function PixelVisionOS:ValidateGameInDir(workspacePath, requiredFiles)
return flag == total

end

function PixelVisionOS:RegisterUI(data, updateCall, scope, ignoreModal)

scope = scope or self

-- Try to remove an existing instance of the component
self:RemoveUI(data.name)

table.insert(self.uiComponents, {uiData = data, uiUpdate = updateCall, uiScope = scope, ignoreModal = ignoreModal or false})

self.uiTotal = #self.uiComponents

-- Return an instance of the component
return data

end

function PixelVisionOS:RemoveUI(name)

local i
local removeItem = -1

for i = 1, self.uiTotal do

if(self.uiComponents[i].uiData.name == name) then

-- Set the remove flag to true
removeItem = i

-- Exit out of the loop
break

end

end

-- If there is nothing to remove than exit out of the function
if(removeItem == -1) then
return
end

-- Remove item
table.remove(self.uiComponents, removeItem)

-- Update the total
self.uiTotal = #self.uiComponents

-- For debugging

print("Remove", removeItem, "total", self.uiTotal)

for i = 1, #self.uiComponents do
print("Left over", self.uiComponents[i].uiData.name)
end

end
64 changes: 35 additions & 29 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-ui-input-field-v3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,8 @@ function EditorUI:CreateInputField(rect, text, toolTip, pattern, font, colorOffs

data.captureInput = function(targetData)

local inputString = InputString()
local outputString = ""
return self:ValidateInputFieldText(targetData, InputString())

for char in inputString:gmatch"." do

local pattern = targetData.patterns[targetData.pattern]

if(pattern ~= nil) then
char = string.match(char, pattern)
end

if(char ~= nil) then

if(targetData.forceCase ~= nil) then
char = string[targetData.forceCase](char)
end

-- Text to see if the input field is a single character and clear it
if(targetData.tiles.w == 1) then
targetData.buffer[1] = char
else
outputString = outputString .. char
end

end

end

return outputString
end

data.onEdit = function(targetData, value)
Expand All @@ -121,9 +94,40 @@ function EditorUI:CreateInputField(rect, text, toolTip, pattern, font, colorOffs

end

function EditorUI:OnEditTextInputField(data, value)
function EditorUI:ValidateInputFieldText(targetData,inputString)

-- local inputString = InputString()
local outputString = ""

for char in inputString:gmatch"." do

local pattern = targetData.patterns[targetData.pattern]

if(pattern ~= nil) then
char = string.match(char, pattern)
end

if(char ~= nil) then

if(targetData.forceCase ~= nil) then
char = string[targetData.forceCase](char)
end

-- Text to see if the input field is a single character and clear it
if(targetData.tiles.w == 1) then
targetData.buffer[1] = char
else
outputString = outputString .. char
end

end

end

return outputString
end

function EditorUI:OnEditTextInputField(data, value)

-- Test to see if we are entering edit mode
if(value == true) then
Expand Down Expand Up @@ -172,6 +176,8 @@ end
function EditorUI:ChangeInputField(data, text, trigger)
-- Input fields need to process the text before setting it

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

-- Look for any custom validation
if(data.onValidate ~= nil) then
text = data.onValidate(text)
Expand Down
22 changes: 12 additions & 10 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-ui-mouse-cursor-v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ MouseCursor.__index = MouseCursor
function MouseCursor:Init()

-- Create a new object for the instance and register it
local _mouseCursor = {}
local _mouseCursor = {
cursorID = -1,
animationTime = 0,
animationDelay = .2,
animationFrame = 0,
colorOffset = 0,
lock = false,
pos = NewPoint(-1, -1)
}

setmetatable(_mouseCursor, MouseCursor)

-- This defines which set of data to use when drawing the cursor
_mouseCursor.cursorID = -1

_mouseCursor.animationTime = 0
_mouseCursor.animationDelay = .2
_mouseCursor.animationFrame = 0
_mouseCursor.colorOffset = 0
_mouseCursor.lock = false


-- Reference data for each of the different mouse cursors
_mouseCursor.cursors = {
-- Pointer
Expand Down Expand Up @@ -106,10 +108,10 @@ function MouseCursor:Init()
},
}

_mouseCursor.pos = {x = -1, y = -1}

_mouseCursor:SetCursor(1)
-- Return the new instance of the editor ui

return _mouseCursor

end
Expand Down

0 comments on commit 4924fea

Please sign in to comment.