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

Commit 99daefe

Browse files
committed
Cleaning up LoadMap(), bug fixes to the Paint Tool, and adding new options modal.
1 parent 83cbe9a commit 99daefe

File tree

19 files changed

+463
-91
lines changed

19 files changed

+463
-91
lines changed
151 Bytes
Loading
-117 Bytes
Loading
-122 Bytes
Loading
-7 Bytes
Loading

Disks/APIExamples/LoadTilemap/code.lua

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ local tilePosition = NewPoint()
1717
-- This will store the current flag ID
1818
local flagID = -1
1919

20-
function Init()
21-
-- Example Title
22-
DrawText("Flag()", 8, 8, DrawMode.TilemapCache, "large", 15)
23-
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)
20+
-- The total number of maps in the Tilemaps folder
21+
local totalMaps = 3;
22+
23+
-- The current map id which starts at -1 since we call next map on Init()
24+
local currentMap = -1;
2425

26+
function Init()
27+
2528
-- Change bg color
26-
BackgroundColor(2)
29+
BackgroundColor(2)
30+
31+
-- Load the first tilemap into memory
32+
NextTilemap()
33+
2734
end
2835

2936
function Update(timeDelta)
@@ -51,6 +58,29 @@ function Update(timeDelta)
5158
-- Get the flag value of the current tile
5259
flagID = Flag(tilePosition.x, tilePosition.y)
5360

61+
-- Look for the left mouse button to be pressed
62+
if(MouseButton( 0, InputState.Released )) then
63+
64+
-- Load the next tilemap
65+
NextTilemap()
66+
67+
end
68+
69+
end
70+
71+
function NextTilemap()
72+
73+
74+
-- Increment the current tilemap by 1 and loop back to 0 when greater than the total maps
75+
currentMap = Repeat( currentMap + 1, totalMaps )
76+
77+
-- Load the new tilemap into memory
78+
LoadTilemap("tilemap-" .. currentMap)
79+
80+
-- Example Title
81+
DrawText("LoadTilemap()", 8, 8, DrawMode.TilemapCache, "large", 15)
82+
DrawText("C Sharp Example - Click to load next level", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)
83+
5484
end
5585

5686
function Draw()
@@ -59,8 +89,9 @@ function Draw()
5989
RedrawDisplay()
6090

6191
-- Display the tile and flag text on the screen
62-
DrawText("Tile " .. tilePosition.x .. ",".. tilePosition.y, 8, 32, DrawMode.Sprite, "large", 15)
63-
DrawText("Flag " .. flagID, 8, 40, DrawMode.Sprite, "large", 15)
92+
DrawText("Name tilemap-" .. currentMap, 8, 32, DrawMode.Sprite, "large", 15)
93+
DrawText("Tile " .. tilePosition.X .. "," .. tilePosition.Y, 8, 40, DrawMode.Sprite, "large", 15)
94+
DrawText("Flag " .. flagID, 8, 48, DrawMode.Sprite, "large", 15)
6495

6596
-- Draw a rect to represent which tile the mouse is over and set the color to match the flag ID plus 1
6697
DrawRect(tilePosition.x * 8, tilePosition.y * 8, 8, 8, flagID + 1, DrawMode.Sprite)

Disks/PixelVisionOS/System/Libs/pixel-vision-os-export-modal-v1.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
ExportModal = {}
2-
ExportModal.__index = ExportModal
1+
OptionModal = {}
2+
OptionModal.__index = OptionModal
33

4-
function ExportModal:Init(title, editorUI)
4+
function OptionModal:Init(title, editorUI)
55

66
local _exportModal = {} -- our new object
7-
setmetatable(_exportModal, ExportModal) -- make Account handle lookup
7+
setmetatable(_exportModal, OptionModal) -- make Account handle lookup
88

99
_exportModal.editorUI = editorUI
1010
_exportModal:Configure(title)
@@ -13,7 +13,7 @@ function ExportModal:Init(title, editorUI)
1313

1414
end
1515

16-
function ExportModal:Configure(title)
16+
function OptionModal:Configure(title)
1717

1818
-- self.showCancel = showCancel or false
1919

@@ -45,7 +45,7 @@ function ExportModal:Configure(title)
4545

4646
end
4747

48-
function ExportModal:Open()
48+
function OptionModal:Open()
4949

5050
if(self.firstRun == nil) then
5151

@@ -82,7 +82,7 @@ function ExportModal:Open()
8282

8383
end
8484

85-
function ExportModal:UpdateMessage(currentItem, total)
85+
function OptionModal:UpdateMessage(currentItem, total)
8686

8787
local message = "Installing item "..string.lpad(tostring(currentItem), string.len(tostring(total)), "0") .. " of " .. installingTotal .. ".\n\n\nDo not restart or shut down Pixel Vision 8."
8888

@@ -127,21 +127,21 @@ function ExportModal:UpdateMessage(currentItem, total)
127127
-- self.editorUI:Invalidate(self.buttons[1])
128128
end
129129

130-
function ExportModal:Close()
130+
function OptionModal:Close()
131131
-- -- print("Modal Close")
132132
-- -- if(self.onParentClose ~= nil) then
133133
-- -- self.onParentClose()
134134
-- -- end
135135
end
136136
--
137-
function ExportModal:Update(timeDelta)
137+
function OptionModal:Update(timeDelta)
138138
-- --
139139
-- -- if(self.completed == true) then
140140
-- -- self.editorUI:UpdateButton(self.backBtnData)
141141
-- -- end
142142
--
143143
end
144144
--
145-
function ExportModal:Draw()
145+
function OptionModal:Draw()
146146
--
147147
end
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
--[[
2+
Pixel Vision 8 - Draw Tool
3+
Copyright (C) 2017, Pixel Vision 8 (http://pixelvision8.com)
4+
Created by Jesse Freeman (@jessefreeman)
5+
6+
Please do not copy and distribute verbatim copies
7+
of this license document, but modifications without
8+
distributing is allowed.
9+
]]--
10+
11+
OptionModal = {}
12+
OptionModal.__index = OptionModal
13+
14+
function OptionModal:Init(title, message, width, showCancel)
15+
16+
local _exportModal = {} -- our new object
17+
setmetatable(_exportModal, OptionModal) -- make Account handle lookup
18+
19+
_exportModal:Configure(title, message, width, showCancel)
20+
21+
return _exportModal
22+
23+
end
24+
25+
function OptionModal:Configure(title, message, width, showCancel, okButtonSpriteName)
26+
27+
self.showCancel = showCancel or false
28+
29+
self.okButtonSpriteName = okButtonSpriteName or "ok"
30+
-- Reset the modal so it redraws correctly when opened
31+
self.firstRun = nil
32+
33+
width = width or 96
34+
35+
-- Need to calculate the height ahead of time
36+
-- Draw message text
37+
local wrap = WordWrap(message, (width / 4) - 4)
38+
self.lines = SplitLines(wrap)
39+
40+
height = #self.lines * 8 + 42
41+
42+
-- Make sure width and height are on the grid
43+
width = math.floor(width / 8) * 8
44+
height = math.floor(height / 8) * 8
45+
46+
self.canvas = NewCanvas(width, height)
47+
48+
local displaySize = Display()
49+
50+
self.title = title or "Message Modal"
51+
52+
self.rect = {
53+
x = math.floor(((displaySize.x - width) * .5) / 8) * 8,
54+
y = math.floor(((displaySize.y - height) * .5) / 8) * 8,
55+
w = width,
56+
h = height
57+
}
58+
59+
self.selectionValue = false
60+
61+
end
62+
63+
function OptionModal:Open()
64+
65+
if(self.firstRun == nil) then
66+
67+
-- Draw the black background
68+
self.canvas:SetStroke(5, 1)
69+
self.canvas:SetPattern({0}, 1, 1)
70+
self.canvas:DrawRectangle(0, 0, self.canvas.width, self.canvas.height, true)
71+
72+
-- Draw the brown background
73+
self.canvas:SetStroke(12, 1)
74+
self.canvas:SetPattern({11}, 1, 1)
75+
self.canvas:DrawRectangle(3, 9, self.canvas.width - 6, self.canvas.height - 12, true)
76+
77+
local tmpX = (self.canvas.width - (#self.title * 4)) * .5
78+
79+
self.canvas:DrawText(self.title:upper(), tmpX, 1, "small", 15, - 4)
80+
81+
-- draw highlight stroke
82+
self.canvas:SetStroke(15, 1)
83+
self.canvas:DrawLine(3, 9, self.canvas.width - 5, 9)
84+
self.canvas:DrawLine(3, 9, 3, self.canvas.height - 5)
85+
86+
local total = #self.lines
87+
local startX = 8
88+
local startY = 16
89+
90+
self.selectionGroupData = editorUI:CreateToggleGroup(true)
91+
92+
self.optionGroupData = editorUI:CreateToggleGroup(false)
93+
self.optionGroupData.onAction = function(value)
94+
95+
local selected = self.optionGroupData.buttons[value].selected
96+
97+
print("Click value", value, selected)
98+
99+
if(Key(Keys.LeftShift) or Key(Keys.RightShift)) then
100+
101+
for i = 1, #self.optionGroupData.buttons do
102+
103+
editorUI:ToggleButton(self.optionGroupData.buttons[i], value, false)
104+
105+
end
106+
107+
end
108+
109+
end
110+
111+
self.buttons = {}
112+
113+
-- We want to render the text from the bottom of the screen so we offset it and loop backwards.
114+
for i = 1, total do
115+
116+
local newY = (startY + ((i - 1) * 8))
117+
118+
local firstChar = string.sub(self.lines[i], 0, 1)
119+
120+
-- # are check boxes
121+
if(firstChar == "#") then
122+
editorUI:ToggleGroupButton(self.optionGroupData, {x = startX + self.rect.x, y = newY + self.rect.y, w = 8, h = 8}, "checkbox", "Select" .. string.sub(self.lines[i], 3), true)
123+
124+
-- * are radio buttons
125+
elseif(firstChar == "*") then
126+
editorUI:ToggleGroupButton(self.selectionGroupData, {x = startX + self.rect.x, y = newY + self.rect.y, w = 8, h = 8}, "radiobutton", "Select" .. string.sub(self.lines[i], 3), true)
127+
end
128+
129+
self.canvas:DrawText(self.lines[i]:upper(), startX, newY, "medium", 0, - 4)
130+
131+
end
132+
133+
local buttonSize = {x = 32, y = 16}
134+
135+
-- TODO center ok button when no cancel button is shown
136+
local bX = self.showCancel == true and (self.rect.w - buttonSize.x - 8) or ((self.rect.w - buttonSize.x) * .5)
137+
138+
-- snap the x value to the grid
139+
bX = math.floor((bX + self.rect.x) / 8) * 8
140+
141+
-- Fix the button to the bottom of the window
142+
local bY = math.floor(((self.rect.y + self.rect.h) - buttonSize.y - 8) / 8) * 8
143+
144+
local backBtnData = editorUI:CreateButton({x = bX, y = bY}, "modal".. self.okButtonSpriteName .. "button", "")
145+
146+
backBtnData.onAction = function()
147+
148+
-- Set value to true when ok is pressed
149+
self.selectionValue = true
150+
151+
if(self.onParentClose ~= nil) then
152+
self.onParentClose()
153+
end
154+
end
155+
156+
table.insert(self.buttons, backBtnData)
157+
158+
if(self.showCancel) then
159+
160+
-- Offset the bX value and snap to the grid
161+
bX = math.floor((bX - buttonSize.x - 8) / 8) * 8
162+
163+
local cancelBtnData = editorUI:CreateButton({x = bX, y = bY}, "modalcancelbutton", "")
164+
165+
cancelBtnData.onAction = function()
166+
167+
-- Set value to true when cancel is pressed
168+
self.selectionValue = false
169+
170+
-- Close the panel
171+
if(self.onParentClose ~= nil) then
172+
self.onParentClose()
173+
end
174+
end
175+
176+
table.insert(self.buttons, cancelBtnData)
177+
178+
end
179+
180+
self.firstRun = false;
181+
182+
end
183+
184+
for i = 1, #self.buttons do
185+
editorUI:Invalidate(self.buttons[i])
186+
end
187+
188+
self.canvas:DrawPixels(self.rect.x, self.rect.y, DrawMode.TilemapCache)
189+
190+
end
191+
192+
function OptionModal:Update(timeDelta)
193+
194+
for i = 1, #self.buttons do
195+
editorUI:UpdateButton(self.buttons[i])
196+
end
197+
198+
editorUI:UpdateToggleGroup(self.optionGroupData)
199+
editorUI:UpdateToggleGroup(self.selectionGroupData)
200+
201+
if(Key(Keys.Enter, InputState.Released)) then
202+
self.selectionValue = true
203+
self.onParentClose()
204+
elseif(Key(Keys.Escape, InputState.Released) and self.showCancel) then
205+
self.selectionValue = false
206+
self.onParentClose()
207+
end
208+
209+
end

0 commit comments

Comments
 (0)
X Tutup