Skip to content

Commit

Permalink
final push with UI alterations
Browse files Browse the repository at this point in the history
add SetProperty all over the place
move the Profiles UI
remove unnecessary popups and buttons
generally introduce an unfathomable amount of sleek, the likes of which MCT has never seen before
  • Loading branch information
chadvandy committed May 28, 2022
1 parent e86a682 commit aaf1e12
Show file tree
Hide file tree
Showing 19 changed files with 1,219 additions and 1,277 deletions.
9 changes: 8 additions & 1 deletion script/mct/settings/mct.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local mct = get_mct()

local mct_mod = mct:register_mod("mct_mod")

mct_mod:set_tooltip_text("Testing this tooltip text out!")

local section = mct_mod:add_new_section("my_section", "This Is My Section")
section:set_tooltip_text("My Section||This section is all about cool stuff.")

Expand Down Expand Up @@ -150,4 +152,9 @@ input:add_validity_test(

local my_dummy = mct_mod:add_new_option("dummy", "dummy")
my_dummy:set_text("This is a Dummy object!")
my_dummy:set_tooltip_text("Yallooooo")
my_dummy:set_tooltip_text("Yallooooo")


local second_mod = mct:register_mod("my_test_mod")
second_mod:set_author("")
second_mod:set_title("bloop")
12 changes: 12 additions & 0 deletions script/vlib/extensions.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
--- Extend Lua functionality.
function math.clamp(x, min, max)
if not is_number(max) then max = math.huge end
if min > max then
--- errmsg
return x
end

if x < min then return min end
if x > max then return max end

return x
end

--- Create a new table by completely copying an existing one.
---@param tbl table
Expand Down
13 changes: 4 additions & 9 deletions script/vlib/mct/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -524,23 +524,19 @@ end

---@param option_obj MCT.Option
function Settings:get_selected_setting_for_option(option_obj)
logf("Is this being called?")
local value

local mod_key = option_obj:get_mod_key()
local option_key = option_obj:get_key()
logf("Getting selected setting for [%s]_[%s]", mod_key, option_key)

---@type any
logf("Querying changed settings")
value = self:get_changed_settings(mod_key, option_key)
if not is_nil(value) then logf("Changed found: %s", tostring(value)) return value end
if not is_nil(value) then return value end

local current_profile = self:get_selected_profile()
value = current_profile:query_mod_option(mod_key, option_key)

if not is_nil(value) then
logf("Current profile found: %s", tostring(value))
return value
end
end
Expand All @@ -549,13 +545,11 @@ end
function Settings:get_finalized_setting_for_option(option_obj)
local mod_key = option_obj:get_mod_key()
local option_key = option_obj:get_key()
logf("getting finalized setting for %s", option_key)

-- local ret

local profile = self:get_selected_profile()
local value = profile:query_mod_option(mod_key, option_key)
if not is_nil(value) then logf("Found! %s", tostring(value)) end

-- ret = value
return value
Expand Down Expand Up @@ -646,7 +640,7 @@ function Settings:delete_profile_with_key(key)
self:set_selected_profile("Default Profile")

-- refresh the dropdown UI
mct.ui:populate_profiles_dropdown_box()
mct.ui:set_actions_states()

self:save()
end
Expand Down Expand Up @@ -726,6 +720,7 @@ function Settings:rename_profile(key, new_key, desc)

self.__profiles[key] = nil
self.__profiles[new_key] = profile
self.__selected_profile = new_key
end

function Settings:apply_profile_with_key(key)
Expand Down Expand Up @@ -821,7 +816,7 @@ function Settings:add_profile_with_key(name, desc, mods)
self:set_selected_profile(name)
self.__settings_changed = true

mct.ui:populate_profiles_dropdown_box()
mct.ui:set_actions_states()

return true
end
Expand Down
26 changes: 26 additions & 0 deletions script/vlib/mct/objects/layout.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- TODO a visual layout within MCT, so you can do stuff like "3 equal columns" or "a double-wide column on the left and an image on the right" or whatever, inserting spots for options or text or wiki or whatever you want
--- TODO this should be an object which holds sections or different data in it, ie. a "description" layout might have description text, optional patch note / author / workshop link details, optional image, etc.

---@class MCT.Layout : Class
local defaults = {

}

---@class MCT.Layout : Class
---@field __new fun():MCT.Layout
local Layout = VLib.NewClass("Layout", defaults)

function Layout:new()
local o = self:__new()
o:init()

return o
end

function Layout:init()

end



return Layout
22 changes: 22 additions & 0 deletions script/vlib/mct/objects/mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ local mct_mod_defaults = {
_title = "No Title Assigned",
_author = "No Author Assigned",
_description = "No Description Assigned",

---@type string The tooltip text for this mod, shown on the row header.
_tooltip_text = "",
-- _workshop_url = "",
}

Expand Down Expand Up @@ -752,6 +755,25 @@ function mct_mod:set_description(desc_text, is_localised)
end
end

function mct_mod:set_tooltip_text(text, is_localised)
if is_string(text) then
if is_localised then text = "{{loc:"..text.."}}" end

self._tooltip_text = text
end
end

function mct_mod:get_tooltip_text()
local tooltip = common.get_localised_string("mct_"..self:get_key().."_tooltip_text")
if tooltip ~= "" then
return tooltip
end

tooltip = VLib.FormatText(self._tooltip_text)

return tooltip or ""
end

--[[function mct_mod:set_workshop_link(link_text)
if is_string(link_text) then
self._workshop_link = link_text
Expand Down
6 changes: 5 additions & 1 deletion script/vlib/mct/objects/option.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ function mct_option:set_uic_with_key(key, uic, force_override)
end

self._uics[key] = uic

if key == "option" then
uic:SetProperty("mct_option", self:get_key())
uic:SetProperty("mct_mod", self:get_mod_key())
end
end

---comment
Expand Down Expand Up @@ -780,7 +785,6 @@ end
--- Used when finalizing settings.
--- @treturn any val The value set as the selected_setting for this mct_option.
function mct_option:get_selected_setting()
logf("Getting selected setting for %s", self:get_key())
return Settings:get_selected_setting_for_option(self)
end

Expand Down
2 changes: 1 addition & 1 deletion script/vlib/mct/objects/section.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ local mct_section_defaults = {
---@type function
_visibility_change_callback = nil,

_sort_order_function = sorting.key,
_sort_order_function = sorting.index,
}

---@class MCT.Section : Class
Expand Down
9 changes: 3 additions & 6 deletions script/vlib/mct/option_types/checkbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,12 @@ core:add_listener(
end,
function(context)
local uic = UIComponent(context.component)

-- will tell us the name of the option
local parent_id = UIComponent(uic:Parent()):Id()
--log("Checkbox Pressed - parent id ["..parent_id.."]")
local mod_obj = mct:get_selected_mod()
local option_obj = mod_obj:get_option_by_key(parent_id)
local option_key = uic:GetProperty("mct_option")
local option_obj = mod_obj:get_option_by_key(option_key)

if not mct:is_mct_option(option_obj) then
err("mct_checkbox_toggle_option_selected listener trigger, but the checkbox pressed ["..parent_id.."] doesn't have a valid mct_option attached. Returning false.")
err("mct_checkbox_toggle_option_selected listener trigger, but the checkbox pressed ["..option_key.."] doesn't have a valid mct_option attached. Returning false.")
return false
end

Expand Down
67 changes: 34 additions & 33 deletions script/vlib/mct/option_types/dropdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function Dropdown:ui_create_option(dummy_parent)

local new_uic = core:get_or_create_component("mct_dropdown_box", box, dummy_parent)
new_uic:SetVisible(true)
new_uic:Resize(dummy_parent:Width() * 0.4, new_uic:Height())

local popup_menu = find_uicomponent(new_uic, "popup_menu")
popup_menu:PropagatePriority(1000) -- higher z-value than other shits
Expand Down Expand Up @@ -282,6 +283,8 @@ function Dropdown:refresh_dropdown_box()
local tt = dropdown_value.tt

local new_entry = core:get_or_create_component(key, dropdown_option_template, popup_list)
new_entry:SetProperty("mct_option", self:get_key())
new_entry:SetProperty("mct_mod", self:get_mod_key())

-- if they're localised text strings, localise them!
do
Expand Down Expand Up @@ -349,6 +352,8 @@ end


---- Specific listeners for the UI ----

--- TODO shouldn't the sub listener be inside of this listener?
core:add_listener(
"mct_dropdown_box",
"ComponentLClickUp",
Expand All @@ -358,8 +363,13 @@ core:add_listener(
function(context)
local box = UIComponent(context.component)
local menu = find_uicomponent(box, "popup_menu")

local mod_obj = mct:get_selected_mod()
local option_key = box:GetProperty("mct_option")
local option_obj = mod_obj:get_option_by_key(option_key)

if is_uicomponent(menu) then
if menu:Visible() then
if menu:Visible(false) then
menu:SetVisible(false)
else
menu:SetVisible(true)
Expand All @@ -370,6 +380,7 @@ core:add_listener(
"ComponentLClickUp",
true,
function(context)
core:remove_listener("mct_dropdown_box_option_selected")
if box:CurrentState() == "selected" then
box:SetState("active")
end
Expand All @@ -379,42 +390,32 @@ core:add_listener(
end,
false
)

-- Set Selected listeners
core:add_listener(
"mct_dropdown_box_option_selected",
"ComponentLClickUp",
function(context)
local uic = UIComponent(context.component)

return UIComponent(uic:Parent()):Id() == "popup_list" and uicomponent_descended_from(uic, "mct_dropdown_box")
end,
function(context)
-- core:remove_listener("mct_dropdown_box_close")
log("mct_dropdown_box_option_selected")
local uic = UIComponent(context.component)

-- this operation is set externally (so we can perform the same operation outside of here)
local ok, msg = pcall(function()
option_obj:set_selected_setting(uic:Id())
end) if not ok then err(msg) end
end,
false
)
end
end
end,
true
)

-- Set Selected listeners
core:add_listener(
"mct_dropdown_box_option_selected",
"ComponentLClickUp",
function(context)
local uic = UIComponent(context.component)

return UIComponent(uic:Parent()):Id() == "popup_list" and UIComponent(UIComponent(UIComponent(uic:Parent()):Parent()):Parent()):Id() == "mct_dropdown_box"
end,
function(context)
log("mct_dropdown_box_option_selected")
core:remove_listener("mct_dropdown_box_close")

local uic = UIComponent(context.component)
local popup_list = UIComponent(uic:Parent())
local popup_menu = UIComponent(popup_list:Parent())
local dropdown_box = UIComponent(popup_menu:Parent())


-- will tell us the name of the option
local parent_id = UIComponent(dropdown_box:Parent()):Id()
local mod_obj = mct:get_selected_mod()
local option_obj = mod_obj:get_option_by_key(parent_id)

-- this operation is set externally (so we can perform the same operation outside of here)
local ok, msg = pcall(function()
option_obj:set_selected_setting(uic:Id())
end) if not ok then err(msg) end
end,
true
)

return Dropdown
Loading

0 comments on commit aaf1e12

Please sign in to comment.