-
-
Notifications
You must be signed in to change notification settings - Fork 397
feat: imbuement system #1616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: imbuement system #1616
Changes from all commits
7ef8385
880d688
5ce1c26
ca7a635
f087906
aa3d6b7
876df5c
531d35c
a29e9aa
381e8f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| -- @docclass | ||
| UIProgressBarSD = extends(UIWidget, "UIProgressBarSD") | ||
|
|
||
| function UIProgressBarSD.create() | ||
| local progressbar = UIProgressBarSD.internalCreate() | ||
| progressbar:setFocusable(false) | ||
| progressbar:setOn(true) | ||
| progressbar.minimum = 0 | ||
| progressbar.maximum = 100 | ||
| progressbar.value = 0 | ||
| progressbar.bgBorderLeft = 0 | ||
| progressbar.bgBorderRight = 0 | ||
| progressbar.bgBorderTop = 0 | ||
| progressbar.bgBorderBottom = 0 | ||
| progressbar:insertLuaCall("onSetup") | ||
| progressbar:insertLuaCall("onGeometryChange") | ||
| return progressbar | ||
| end | ||
|
|
||
| function UIProgressBarSD:setMinimum(minimum) | ||
| self.minimum = minimum | ||
| if self.value < minimum then | ||
| self:setValue(minimum) | ||
| end | ||
| end | ||
|
|
||
| function UIProgressBarSD:setMaximum(maximum) | ||
| self.maximum = maximum | ||
| if self.value > maximum then | ||
| self:setValue(maximum) | ||
| end | ||
| end | ||
|
|
||
| function UIProgressBarSD:setValue(value, minimum, maximum) | ||
| if minimum then | ||
| self:setMinimum(minimum) | ||
| end | ||
|
|
||
| if maximum then | ||
| self:setMaximum(maximum) | ||
| end | ||
|
|
||
| self.value = math.max(math.min(value, self.maximum), self.minimum) | ||
| self:updateBackground() | ||
| end | ||
|
|
||
| function UIProgressBarSD:setPercent(percent) | ||
| self:setValue(percent, 0, 100) | ||
| end | ||
|
|
||
| function UIProgressBarSD:getPercent() | ||
| return self.value | ||
| end | ||
|
|
||
| function UIProgressBarSD:getPercentPixels() | ||
| return (self.maximum - self.minimum) / self:getWidth() | ||
| end | ||
|
|
||
| function UIProgressBarSD:getProgress() | ||
| if self.minimum == self.maximum then return 1 end | ||
| return (self.value - self.minimum) / (self.maximum - self.minimum) | ||
| end | ||
|
|
||
| function UIProgressBarSD:updateBackground() | ||
| if self:isOn() then | ||
| local width = math.round(math.max((self:getProgress() * (self:getWidth() - self.bgBorderLeft - self.bgBorderRight)), 1)) | ||
| local height = self:getHeight() - self.bgBorderTop - self.bgBorderBottom | ||
| local rect = { x = self.bgBorderLeft, y = self.bgBorderTop, width = width, height = height } | ||
| self:setImageRect(rect) | ||
|
|
||
| if width == 1 then | ||
| self:setImageVisible(false) | ||
| else | ||
| self:setImageVisible(true) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function UIProgressBarSD:onSetup() | ||
| self:updateBackground() | ||
| end | ||
|
|
||
| function UIProgressBarSD:onStyleApply(name, node) | ||
| for name,value in pairs(node) do | ||
| if name == 'background-border-left' then | ||
| self.bgBorderLeft = tonumber(value) | ||
| elseif name == 'background-border-right' then | ||
| self.bgBorderRight = tonumber(value) | ||
| elseif name == 'background-border-top' then | ||
| self.bgBorderTop = tonumber(value) | ||
| elseif name == 'background-border-bottom' then | ||
| self.bgBorderBottom = tonumber(value) | ||
| elseif name == 'background-border' then | ||
| self.bgBorderLeft = tonumber(value) | ||
| self.bgBorderRight = tonumber(value) | ||
| self.bgBorderTop = tonumber(value) | ||
| self.bgBorderBottom = tonumber(value) | ||
| elseif name == 'percent' then | ||
| self.percent = self:setPercent(tonumber(value)) | ||
| elseif name == 'tooltip-delayed' then | ||
| self.tooltipDelayed = value | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function UIProgressBarSD:onGeometryChange(oldRect, newRect) | ||
| if not self:isOn() then | ||
| self:setHeight(0) | ||
| end | ||
| self:updateBackground() | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,110 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| -- @docclass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| UIProgressBarSDInverted = extends(UIWidget, "UIProgressBarSDInverted") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted.create() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| local progressbar = UIProgressBarSDInverted.internalCreate() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar:setFocusable(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar:setOn(true) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar.minimum = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar.maximum = 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar.value = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar.bgBorderLeft = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar.bgBorderRight = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar.bgBorderTop = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar.bgBorderBottom = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar:insertLuaCall("onSetup") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize 🐛 Proposed fix- progressbar.min = 0
- progressbar.max = 100
+ progressbar.minimum = 0
+ progressbar.maximum = 100📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| progressbar:insertLuaCall("onGeometryChange") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return progressbar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:setMinimum(minimum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.minimum = minimum | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if self.value < minimum then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setValue(minimum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:setMaximum(maximum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.maximum = maximum | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if self.value > maximum then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setValue(maximum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:setValue(value, minimum, maximum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if minimum then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setMinimum(minimum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if maximum then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setMaximum(maximum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| self.value = math.max(math.min(value, self.maximum), self.minimum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:updateBackground() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:setPercent(percent) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setValue(percent, 0, 100) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:getPercent() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return self.value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:getPercentPixels() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return (self.maximum - self.minimum) / self:getWidth() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:getProgress() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if self.minimum == self.maximum then return 1 end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return (self.value - self.minimum) / (self.maximum - self.minimum) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:updateBackground() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if self:isOn() then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| local width = math.round(math.max((self:getProgress() * (self:getWidth() - self.bgBorderLeft - self.bgBorderRight)), 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| local height = self:getHeight() - self.bgBorderTop - self.bgBorderBottom | ||||||||||||||||||||||||||||||||||||||||||||||||||
| local rect = { x = self:getWidth() - (self:getProgress() * self:getWidth()), y = self.bgBorderTop, width = width, height = height } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if width == 1 then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| rect.x = rect.x - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setImageRect(rect) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if width == 1 then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setImageVisible(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setImageVisible(true) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:onSetup() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:updateBackground() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:onStyleApply(name, node) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for name,value in pairs(node) do | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if name == 'background-border-left' then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderLeft = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elseif name == 'background-border-right' then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderRight = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elseif name == 'background-border-top' then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderTop = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elseif name == 'background-border-bottom' then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderBottom = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elseif name == 'background-border' then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderLeft = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderRight = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderTop = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.bgBorderBottom = tonumber(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function UIProgressBarSDInverted:onGeometryChange(oldRect, newRect) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if not self:isOn() then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:setHeight(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self:updateBackground() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize
minimum/maximuminstead ofmin/maxto avoid nil clamps.setValueclamps viaself.minimum/self.maximum; with current init those are nil until setters run.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents