-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Module adjustments to make them compatible with the pigui Bulletin Board Allow passing Table to PiguiFace constructor Optional targetResolution parameter to allow rescaling ui into smaller windows
- Loading branch information
Showing
9 changed files
with
270 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,85 @@ | ||
-- Copyright © 2008-2020 Pioneer Developers. See AUTHORS.txt for details | ||
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt | ||
|
||
local Face = import 'PiGui.Modules.Face' | ||
local FaceTextureGenerator = import 'PiGui.Modules.Face' | ||
local Character = import 'Character' | ||
local ui = import 'pigui/pigui.lua' | ||
local colors = ui.theme.colors | ||
local orbiteer = ui.fonts.orbiteer | ||
local charInfoFlags = ui.WindowFlags {"AlwaysUseWindowPadding", "NoScrollbar"} | ||
|
||
local testCharacter = function (character) | ||
if not (character and (type(character)=='table') and (getmetatable(character).class == 'Character')) | ||
local ensureCharacter = function (character) | ||
if not (character and (type(character)=='table') and getmetatable(character) and (getmetatable(character).class == 'Character')) | ||
then | ||
error ('Character object expected') | ||
return Character.New(character) | ||
end | ||
end | ||
|
||
local getStyleVar = function(style, key, defaultValue) | ||
return (style and (type(style)=='table')) and style[key] or defaultValue | ||
return character | ||
end | ||
|
||
local PiGuiFace = {} | ||
|
||
function PiGuiFace.New (character, style) | ||
testCharacter(character) | ||
|
||
character = ensureCharacter(character) | ||
style = style or {} | ||
local faceDesc = character.faceDescription and character.faceDescription or { | ||
FEATURE_GENDER = character.female and 1 or 0, | ||
FEATURE_ARMOUR = character.armour and 1 or 0, | ||
} | ||
|
||
local faceTexGen = FaceTextureGenerator.New(faceDesc, character.seed) | ||
local piguiFace = { | ||
widget = Face.New(faceDesc, character.seed), | ||
character = character | ||
faceTextureGenerator = faceTexGen, | ||
character = character, | ||
texture = { | ||
id = faceTexGen.textureId, | ||
uv = faceTexGen.textureSize, | ||
}, | ||
style = { | ||
size = style.size or ui.rescaleUI(Vector2(320, 320), Vector2(1600, 900)), | ||
windowPadding = style.windowPadding or Vector2(0,0), | ||
itemSpacing = style.itemSpacing or Vector2(0,0), | ||
showCharInfo = style.showCharInfo == nil and true or style.showCharInfo, | ||
charInfoPadding = style.charInfoPadding or ui.rescaleUI(Vector2(24,24), Vector2(1600, 900)), | ||
charInfoBgColor = style.bgColor or Color(0,0,0,160), | ||
nameFont = style.nameFont or orbiteer.xlarge, | ||
titleFont = style.titleFont or orbiteer.large, | ||
} | ||
} | ||
|
||
piguiFace.texture = { | ||
id = piguiFace.widget.textureId, | ||
uv = piguiFace.widget.textureSize | ||
} | ||
piguiFace.style.charInfoHeight = math.ceil( | ||
piguiFace.style.nameFont.size + (character.title and piguiFace.style.titleFont.size or 0) | ||
+ piguiFace.style.charInfoPadding.y*2 | ||
) | ||
|
||
piguiFace.style = { | ||
windowPadding = getStyleVar(style, 'windowPadding', Vector2(0,0)), | ||
itemSpacing = getStyleVar(style, 'itemSpacing', Vector2(0,0)), | ||
bgColor = getStyleVar(style, 'bgColor', Color(0,0,0,160)), | ||
nameFont = getStyleVar(style, 'nameFont', orbiteer.xlarge), | ||
titleFont = getStyleVar(style, 'titleFont', orbiteer.large), | ||
} | ||
setmetatable(piguiFace, { | ||
__index = PiGuiFace, | ||
class = "UI.PiGuiFace", | ||
}) | ||
|
||
piguiFace.style.infoDetailsHeight = math.ceil( | ||
piguiFace.style.nameFont.size + piguiFace.style.titleFont.size | ||
+ getStyleVar(style, 'infoDetailsPadding',48) * (ui.screenHeight / 1200) | ||
) | ||
return piguiFace | ||
end | ||
|
||
piguiFace.Draw = function(self, faceSize) | ||
ui.image(self.texture.id, faceSize, Vector2(0.0, 0.0), self.texture.uv, colors.white) | ||
function PiGuiFace:render () | ||
ui.image(self.texture.id, self.style.size, Vector2(0.0, 0.0), self.texture.uv, colors.white) | ||
|
||
if(self.style.showCharInfo) then | ||
local lastPos = ui.getCursorPos() | ||
ui.setCursorPos(lastPos - Vector2(0.0, self.style.infoDetailsHeight + self.style.itemSpacing.y)) | ||
ui.withStyleColors({ChildWindowBg = self.style.bgColor}, function() | ||
ui.withStyleVars({WindowPadding = self.style.windowPadding, ItemSpacing = self.style.itemSpacing}, function() | ||
ui.child("PlayerInfoDetails", Vector2(faceSize.x, self.style.infoDetailsHeight), {"AlwaysUseWindowPadding", "NoScrollbar"}, function () | ||
ui.withFont(self.style.nameFont.name, self.style.nameFont.size, function() | ||
ui.text(self.character.name) | ||
end) | ||
ui.setCursorPos(lastPos - Vector2(0.0, self.style.charInfoHeight + self.style.itemSpacing.y)) | ||
ui.withStyleColorsAndVars({ChildWindowBg = self.style.charInfoBgColor}, {WindowPadding = self.style.charInfoPadding, ItemSpacing = self.style.itemSpacing}, function () | ||
ui.child("PlayerInfoDetails", Vector2(self.style.size.x, self.style.charInfoHeight), charInfoFlags, function () | ||
ui.withFont(self.style.nameFont.name, self.style.nameFont.size, function() | ||
ui.text(self.character.name) | ||
end) | ||
if self.character.title then | ||
ui.withFont(self.style.titleFont.name, self.style.titleFont.size, function() | ||
ui.text(self.character.title or '') | ||
ui.text(self.character.title) | ||
end) | ||
end) | ||
end | ||
end) | ||
end) | ||
ui.setCursorPos(lastPos) | ||
end | ||
|
||
setmetatable(piguiFace, { | ||
__index = PiGuiFace, | ||
class = "UI.PiGuiFace", | ||
}) | ||
|
||
return piguiFace | ||
end | ||
|
||
return PiGuiFace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.