Skip to content

Commit

Permalink
Merge pull request #99 from Silverlan/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan authored Jul 29, 2024
2 parents df56b04 + df0013e commit 0f8a474
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 40 deletions.
23 changes: 13 additions & 10 deletions assets/lua/autorun/gui/skin_default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,21 @@ skin["table_row_offset"] = {
["witext"] = {
Initialize = function(GUI, pElement)
local pCell = pElement:GetParent()
if pCell:IsValid() and pCell:GetClass() == "witablecell" then
local fcSetSize = function()
if pElement:IsValid() == false then
return
if pCell:IsValid() then
local childIdx = pCell:FindChildIndex(pElement)
if childIdx == 0 and pCell:GetClass() == "witablecell" then
local fcSetSize = function()
if pElement:IsValid() == false then
return
end
local sz = pCell:GetSize()
pElement:SetY(pCell:GetHeight() * 0.5 - pElement:GetHeight() * 0.5)
pElement:SetX(GUI.TABLE_TEXT_OFFSET_X)
end
local sz = pCell:GetSize()
pElement:SetY(pCell:GetHeight() * 0.5 - pElement:GetHeight() * 0.5)
pElement:SetX(GUI.TABLE_TEXT_OFFSET_X)
local cbSetSize = pCell:AddCallback("SetSize", fcSetSize)
add_skin_element(pElement, cbSetSize)
fcSetSize()
end
local cbSetSize = pCell:AddCallback("SetSize", fcSetSize)
add_skin_element(pElement, cbSetSize)
fcSetSize()
end
end,
Release = clear_element,
Expand Down
192 changes: 170 additions & 22 deletions assets/lua/gui/wifileexplorer.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
include("wibasefileexplorer.lua")

util.register_class("gui.WIFileExplorer", gui.Base, gui.BaseFileExplorer)
local Element = util.register_class("gui.WIFileExplorer", gui.Base, gui.BaseFileExplorer)
Element.COLUMN_NAME = 1
Element.COLUMN_TYPE = 2
Element.COLUMN_FILE_SIZE = 3
Element.COLUMN_DATE_MODIFIED = 4
Element.COLUMN_COUNT = 5

local names = {
[Element.COLUMN_NAME] = locale.get_text("name"),
[Element.COLUMN_TYPE] = locale.get_text("type"),
[Element.COLUMN_FILE_SIZE] = locale.get_text("file_size"),
[Element.COLUMN_DATE_MODIFIED] = locale.get_text("date_modified"),
}

function gui.WIFileExplorer:__init()
gui.Base.__init(self)
Expand All @@ -14,19 +26,111 @@ end
function gui.WIFileExplorer:OnInitialize()
gui.Base.OnInitialize(self)

self.m_tRowInfo = {}
local t = gui.create("WITable", self)
t:SetAutoAlignToParent(true)
t:SetScrollable(true)
t:SetSortable(true)
t:SetSelectableMode(gui.Table.SELECTABLE_MODE_MULTI)
t:SetSortFunction(function(a, b, colIdx, ascending)
local adata = self.m_tRowInfo[a]
local bdata = self.m_tRowInfo[b]
if adata ~= nil and bdata ~= nil then
if adata.isDirectory and not bdata.isDirectory then
return true
end
if not adata.isDirectory and bdata.isDirectory then
return false
end
end
-- ".." should always be first item
if a:GetValue(0) == ".." then
return true
end
if b:GetValue(0) == ".." then
return false
end
local valA = a:GetValue(colIdx)
local valB = b:GetValue(colIdx)
local colType = self:GetColumnType(colIdx)
if colType ~= Element.COLUMN_NAME and valA == valB then
-- Fall-back to alphabetical sorting
local idx = self:GetColumnIndex(Element.COLUMN_NAME)
if idx ~= nil then
valA = a:GetValue(idx)
valB = b:GetValue(idx)
end
end
local res = valA < valB
if ascending then
return res
end
return not res
end)
t:SetSelectableMode(gui.Table.SELECTABLE_MODE_SINGLE)
t:SetRowHeight(20)
local row = t:AddHeaderRow()
row:SetValue(0, locale.get_text("name"))
row:SetValue(1, locale.get_text("type"))
row:SetValue(2, locale.get_text("size"))
self.m_pFileList = t

self.m_columnStates = {}
self.m_columIndexToType = {}
for i = 1, Element.COLUMN_COUNT - 1 do
self:SetColumnEnabled(i, false)
end
self:SetColumnEnabled(Element.COLUMN_NAME, true)
self:SetColumnEnabled(Element.COLUMN_TYPE, true)
self:SetColumnEnabled(Element.COLUMN_FILE_SIZE, true)
self:UpdateColumns()

self:SetPath("/")
end
function gui.WIFileExplorer:SetColumnEnabled(colType, enabled)
self.m_columnStates[colType] = {
enabled = enabled,
}
end
function gui.WIFileExplorer:IsColumnEnabled(colType)
return self.m_columnStates[colType].enabled or false
end
function gui.WIFileExplorer:GetColumnType(colIdx)
return self.m_columIndexToType[colIdx]
end
function gui.WIFileExplorer:GetColumnIndex(colType)
return self.m_columnStates[colType].columnIndex
end
function gui.WIFileExplorer:SetEnabledColumns(cols)
local colMap = {}
for _, col in ipairs(cols) do
colMap[col] = true
end
for i = 1, Element.COLUMN_COUNT - 1 do
self:SetColumnEnabled(i, colMap[i] or false)
end
self:UpdateColumns()
end
function gui.WIFileExplorer:GetEnabledColumns()
local t = {}
for i = 1, Element.COLUMN_COUNT - 1 do
if self:IsColumnEnabled(i) then
table.insert(t, i)
end
end
return t
end
function gui.WIFileExplorer:UpdateColumns()
local t = self.m_pFileList
t:Clear(true)

self.m_columIndexToType = {}
for i = 1, Element.COLUMN_COUNT - 1 do
self.m_columnStates[i].columnIndex = nil
end
local row = t:AddHeaderRow()
for colIdx, colType in ipairs(self:GetEnabledColumns()) do
row:SetValue(colIdx - 1, names[colType])
self.m_columnStates[colType].columnIndex = colIdx - 1
self.m_columIndexToType[colIdx - 1] = colType
end
end
function gui.WIFileExplorer:GetSelectedFile(relativePath)
relativePath = relativePath or false
local path
Expand Down Expand Up @@ -56,78 +160,122 @@ function gui.WIFileExplorer:GetSelectedFile(relativePath)
end
return path
end
function gui.WIFileExplorer:GetIcon(row)
return self.m_tRowInfo[row].icon
end
function gui.WIFileExplorer:ListFiles()
local t = self.m_pFileList
if util.is_valid(t) == false then
return
end
t:Clear()
self.m_tItems = {}
self.m_tRowInfo = {}

local tFiles, tDirectories = self:FindFiles()

local function create_icon(icon)
local margin = 4
local margin = 2
local pContainer = gui.create("WIBase")
local pIcon = gui.create("WISilkIcon", pContainer)
pIcon:SetIcon(icon)
local size = pIcon:GetSize()
size.x = size.x + margin * 2
size.y = size.y + margin * 2
size.x = size.x + margin
pContainer:SetSize(size)
return pContainer
end

for _, file in ipairs(tDirectories) do
local cols = self:GetEnabledColumns()
local path = self:GetPath()
local rootPath = self:GetRootPath()
for _, dirName in ipairs(tDirectories) do
local pIcon = create_icon("folder")

local fPath = dirName
if path ~= "/" then
fPath = rootPath .. path .. fPath
else
fPath = rootPath
end

local row = t:AddRow()
row:InsertElement(0, pIcon)
row:SetValue(0, file)
row:SetValue(1, locale.get_text("file_folder"))
row:SetValue(2, "")
for colIdx, colType in ipairs(cols) do
if colType == Element.COLUMN_NAME then
row:SetValue(colIdx - 1, dirName)
elseif colType == Element.COLUMN_TYPE then
row:SetValue(colIdx - 1, locale.get_text("file_folder"))
elseif colType == Element.COLUMN_FILE_SIZE then
row:SetValue(colIdx - 1, "")
elseif colType == Element.COLUMN_DATE_MODIFIED then
row:SetValue(colIdx - 1, file.get_last_write_time(fPath) or "")
end
end
row:GetCell(0):SetTooltip(path .. fPath)
row:AddCallback("OnDoubleClick", function(pRow)
if util.is_valid(self) == false then
return
end
self:SetPath(self:GetPath() .. file)
self:SetPath(self:GetPath() .. dirName)
self:Update()
end)
self.m_tRowInfo[row] = {
isDirectory = true,
icon = pIcon,
}
self:CallCallbacks("OnDirectoryRowAdded", row, fPath)
end
local path = self:GetPath()
if self.m_isDirExplorer ~= true then
for _, fName in ipairs(tFiles) do
local pIcon = create_icon("page")

local fPath = fName
if path ~= "/" then
fPath = path .. fPath
fPath = rootPath .. path .. fPath
else
fPath = rootPath
end
local sz = file.get_size(fPath)
local ext = file.get_file_extension(fPath)
local fileType = (ext ~= nil) and ext:upper() or locale.get_text("unknown")
fileType = fileType .. " " .. locale.get_text("file")

local row = t:AddRow()
row:InsertElement(0, pIcon)
row:SetValue(0, fName)
row:SetValue(1, fileType)
row:SetValue(2, util.get_pretty_bytes(sz))
for colIdx, colType in ipairs(cols) do
if colType == Element.COLUMN_NAME then
row:SetValue(colIdx - 1, fName)
elseif colType == Element.COLUMN_TYPE then
row:SetValue(colIdx - 1, fileType)
elseif colType == Element.COLUMN_FILE_SIZE then
row:SetValue(colIdx - 1, util.get_pretty_bytes(sz))
elseif colType == Element.COLUMN_DATE_MODIFIED then
row:SetValue(colIdx - 1, file.get_last_write_time(fPath) or "")
end
end
row:GetCell(0):SetTooltip(path .. fPath)
row:AddCallback("OnMouseEvent", function(pRow, button, action, mods)
if util.is_valid(self) == false then
return
end
if button == input.MOUSE_BUTTON_LEFT and action == input.STATE_PRESS then
self:CallCallbacks("OnFileClicked", fName)
if self:CallCallbacks("OnFileClicked", fName) == util.EVENT_REPLY_HANDLED then
return
end
end
self:CallCallbacks("OnFileMouseEvent", pRow, path .. fPath, button, action, mods)
end)
row:AddCallback("OnDoubleClick", function(pRow)
if util.is_valid(self) == false then
return
end
self:CallCallbacks("OnFileSelected", fPath)
end)
self.m_tRowInfo[row] = {
isDirectory = false,
icon = pIcon,
}
self:CallCallbacks("OnFileRowAdded", row, fPath)
end
end
t:Sort()
t:SetSize(self:GetSize())
end
gui.register("WIFileExplorer", gui.WIFileExplorer)
2 changes: 2 additions & 0 deletions assets/scripts/localization/en/texts/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ copy_to_clipboard = "Copy to clipboard"
custom = "Custom"
cut = "Cut"
data = "Data"
date_modified = "Date Modified"
decline = "Decline"
default = "Default"
degree_x = "{0} Degree"
Expand Down Expand Up @@ -84,6 +85,7 @@ explorer_location = "Location"
export = "Export"
fast = "Fast"
favorites = "Favorites"
file_size = "File Size"
filter = "Filter"
flex_animation = "Flex Animation"
flex_controller_limits = "Flex Controller Limits"
Expand Down
2 changes: 1 addition & 1 deletion build_scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ def download_addon(name,addonName,url,commitId=None):
curDir = os.getcwd()
if not skip_repository_updates:
if with_pfm:
download_addon("PFM","filmmaker","https://github.com/Silverlan/pfm.git","627f4f89649d2826e0115fad5e7b5f26b0afe44e")
download_addon("PFM","filmmaker","https://github.com/Silverlan/pfm.git","8d939308fff00677f1a010d211aa0d792a3e4569")
download_addon("model editor","tool_model_editor","https://github.com/Silverlan/pragma_model_editor.git","56d46dacb398fa7540e794359eaf1081c9df1edd")

if with_vr:
Expand Down
4 changes: 2 additions & 2 deletions build_scripts/scripts/external_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
get_submodule("util_versioned_archive","https://github.com/Silverlan/util_versioned_archive.git","77531a4e93ded49dc8e5fe402db4198ab9aaa369")
get_submodule("util_vmf","https://github.com/Silverlan/util_vmf.git","3080ba05280ae5b0a76ef283870864c16d1c7826")
get_submodule("util_zip","https://github.com/Silverlan/util_zip.git","1f13d86fef96462248de222d7978a078a38efe00")
get_submodule("vfilesystem","https://github.com/Silverlan/vfilesystem.git","1cd076213f5e213a25f1d71438755a2cb65e02cd")
get_submodule("wgui","https://github.com/Silverlan/wgui.git","8cdc13687dc49b564769d9b000374b30c7618961")
get_submodule("vfilesystem","https://github.com/Silverlan/vfilesystem.git","25c839e313b1bb1c2b4dee56c4a0298c53f546b4")
get_submodule("wgui","https://github.com/Silverlan/wgui.git","525f76a73545c4bbe31a425ca6ec9a65122797e8")
get_submodule("util_unicode","https://github.com/Silverlan/util_unicode.git","6936adeaa9a054a9530078c9a47e3fa94cf4bffa")
get_submodule("cppbezierfit","https://github.com/Silverlan/cppbezierfit.git","eb08f35ad74c1124f3cd4ef3a8958cded6a04b0e")

Expand Down
12 changes: 9 additions & 3 deletions core/client/include/pragma/gui/witable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <wgui/wibase.h>
#include "pragma/gui/wicontainer.h"
#include <unordered_map>
#include <functional>

class WITable;
class WITableRow;
Expand All @@ -27,6 +28,7 @@ class DLLCLIENT WITableCell : public WIContainer {
virtual void Initialize() override;
virtual void SetSize(int x, int y) override;
virtual void OnChildAdded(WIBase *child) override;
virtual void DoUpdate() override;
WIBase *GetFirstElement();
// Not yet implemented
void SetRowSpan(int32_t span);
Expand Down Expand Up @@ -55,6 +57,9 @@ class DLLCLIENT WITable : public WIContainer {
void RemoveRow(uint32_t rowIdx);
void SetSortable(bool b);
bool IsSortable() const;
void SetSortFunction(const std::function<bool(const WITableRow &, const WITableRow &, uint32_t, bool)> &sortFunc);
const std::function<bool(const WITableRow &, const WITableRow &, uint32_t, bool)> &GetSortFunction() const;
void Sort();
void SetRowHeight(int h);
int GetRowHeight() const;
void SetSelectable(SelectableMode mode);
Expand All @@ -70,8 +75,8 @@ class DLLCLIENT WITable : public WIContainer {
virtual void SizeToContents(bool x = true, bool y = true) override;
protected:
struct SortData {
SortData(WITable *t, bool bAsc, unsigned int col) : table(t), ascending(bAsc), column(col) {}
bool operator()(const WIHandle &a, const WIHandle &b) { return table->SortRows(ascending, column, a, b); }
SortData(WITable *t, bool bAsc, unsigned int col);
bool operator()(const WIHandle &a, const WIHandle &b);
WITable *table;
bool ascending;
unsigned int column;
Expand All @@ -80,6 +85,7 @@ class DLLCLIENT WITable : public WIContainer {
int m_rowHeight;
SelectableMode m_selectableMode = SelectableMode::None;
bool m_bSortable;
std::function<bool(const WITableRow &, const WITableRow &, uint32_t, bool)> m_sortFunction;
unsigned int m_sortColumn;
bool m_bSortAsc;
WIHandle m_hSortArrow;
Expand All @@ -92,7 +98,7 @@ class DLLCLIENT WITable : public WIContainer {
void OnRowSelected(WITableRow *row);
std::vector<WIHandle> m_selectedRows;
static bool SortRows(bool bAsc, unsigned int col, const WIHandle &a, const WIHandle &b);
void Sort(bool bAsc = true, unsigned int col = 0);
void Sort(bool bAsc, unsigned int col = 0);
virtual void DoUpdate() override;
WITableRow *GetHeaderRow();
void InitializeRow(WITableRow *row, bool bHeader = false);
Expand Down
Loading

0 comments on commit 0f8a474

Please sign in to comment.