Skip to content

Commit

Permalink
Merge pull request #30 from Courseplay/Gui-Additions
Browse files Browse the repository at this point in the history
Gui additions
  • Loading branch information
Tensuko authored Dec 23, 2024
2 parents 4d2bef0 + 4379698 commit c8164ce
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
4 changes: 1 addition & 3 deletions scripts/CpSettingsUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function CpSettingsUtil.generateAndBindGuiElements(settingsData, parentGuiElemen
clonedSettingElement:getDescendantByName("setting"):setDataSource(setting)
clonedSettingElement.aiParameter = setting
-- clonedSettingElement:applyScreenAlignment()
FocusManager:loadElementFromCustomValues(clonedSettingElement)
FocusManager:loadElementFromCustomValues(clonedSettingElement:getDescendantByName("setting"))
end
end
parentGuiElement:invalidateLayout()
Expand All @@ -312,9 +312,7 @@ function CpSettingsUtil.generateAndBindGuiElementsToSettings(settingsBySubTitle,
local clonedSubTitleElement = genericSubTitleElement:clone(parentGuiElement)
clonedSubTitleElement:setText(g_i18n:getText(data.title))
clonedSubTitleElement.subTitleConfigData = data
-- clonedSubTitleElement:applyScreenAlignment()
FocusManager:loadElementFromCustomValues(clonedSubTitleElement)

CpSettingsUtil.generateAndBindGuiElements(data,
parentGuiElement, genericMultiSettingElement,
genericBooleanSettingElement, settings)
Expand Down
7 changes: 0 additions & 7 deletions scripts/gui/elements/CpOptionToggleElement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ end
function CpOptionToggleElement:addElement(element, ...)
CpOptionToggleElement:superClass().addElement(self, element, ...)
if self.textElement then
self.textElement.forceHighlight = true
self.textElement:setHandleFocus(false)
self.textElement.target = self
self.textElement:setCallback("onClickCallback", "onCenterButtonClicked")
end
Expand Down Expand Up @@ -84,9 +82,4 @@ function CpOptionToggleElement:inputEvent(action, value, eventUsed)
end
return eventUsed
end
function CpOptionToggleElement:raiseClickCallback(...)
CpOptionToggleElement:superClass().raiseClickCallback(self, ...)
--- Magic gui fix, no idea why this is needed ...
FocusManager:unsetFocus(self)
end
Gui.registerGuiElement("CpOptionToggle", CpOptionToggleElement)
6 changes: 3 additions & 3 deletions scripts/gui/pages/CpCourseManagerFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,10 @@ end

function CpCourseManagerFrame:onClickBack()
if self.courseStorage:getCanIterateBackwards() then
self:onClickIterateBack()
return true
-- self:onClickIterateBack()
-- return false
end
return false
return true
end

---------------------------------------------------
Expand Down
53 changes: 32 additions & 21 deletions scripts/gui/pages/CpGlobalSettingsFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function CpGlobalSettingsFrame.new(target, custom_mt)
local self = TabbedMenuFrameElement.new(target, custom_mt or CpGlobalSettingsFrame_mt)
self.subCategoryPages = {}
self.subCategoryTabs = {}
self.wasOpened = false
return self
end

Expand Down Expand Up @@ -53,7 +54,6 @@ function CpGlobalSettingsFrame:saveToXMLFile(xmlFile, baseKey)
end

function CpGlobalSettingsFrame:initialize(menu)

self.booleanPrefab:unlinkElement()
FocusManager:removeElement(self.booleanPrefab)
self.multiTextPrefab:unlinkElement()
Expand All @@ -66,42 +66,52 @@ function CpGlobalSettingsFrame:initialize(menu)
FocusManager:removeElement(self.containerPrefab)
for key = 1, CpGlobalSettingsFrame.NUM_CATEGORIES do
self.subCategoryPaging:addText(tostring(key))
self.subCategoryPages[key] = self.containerPrefab:clone(self)
local layout = self.subCategoryPages[key]:getDescendantByName("layout")
layout.scrollDirection = "vertical"
FocusManager:loadElementFromCustomValues(self.subCategoryPages[key])
self.subCategoryTabs[key] = self.selectorPrefab:clone(self.subCategoryBox)
FocusManager:loadElementFromCustomValues(self.subCategoryTabs[key])
self.subCategoryBox:invalidateLayout()
self.subCategoryTabs[key]:setText(g_i18n:getText(self.CATEGRORY_TEXTS[key]))
self.subCategoryTabs[key]:getDescendantByName("background"):setSize(
self.subCategoryTabs[key].size[1], self.subCategoryTabs[key].size[2])
self.subCategoryTabs[key].onClickCallback = function ()
self:updateSubCategoryPages(key)
end

self.subCategoryPages[key] = self.containerPrefab:clone(self)
local layout = self.subCategoryPages[key]:getDescendantByName("layout")
layout.scrollDirection = "vertical"
FocusManager:loadElementFromCustomValues(self.subCategoryPages[key])
end
self.subCategoryBox:invalidateLayout()
local settings = g_Courseplay.globalSettings:getSettings()
local settingsBySubTitle, pageTitle = g_Courseplay.globalSettings:getSettingSetup()
local _, pageTitle = g_Courseplay.globalSettings:getSettingSetup()
self.categoryHeaderText:setText(g_i18n:getText(pageTitle))
end

local ix = 1
for _, data in pairs(settingsBySubTitle) do
local layout = self.subCategoryPages[ix]:getDescendantByName("layout")
CpSettingsUtil.generateAndBindGuiElements(data, layout,
self.multiTextPrefab, self.booleanPrefab, settings)
CpSettingsUtil.updateGuiElementsBoundToSettings(layout)
if ix >= 2 then
break
end
ix = ix + 1
end
function CpGlobalSettingsFrame:delete()
self.booleanPrefab:delete()
self.multiTextPrefab:delete()
self.sectionHeaderPrefab:delete()
self.selectorPrefab:delete()
self.containerPrefab:delete()
CpGlobalSettingsFrame:superClass().delete(self)
end

function CpGlobalSettingsFrame:onFrameOpen()
CpGlobalSettingsFrame:superClass().onFrameOpen(self)
if not self.wasOpened then
self.wasOpened = true
local settings = g_Courseplay.globalSettings:getSettings()
local settingsBySubTitle = g_Courseplay.globalSettings:getSettingSetup()
local ix = 1
for _, data in pairs(settingsBySubTitle) do
local layout = self.subCategoryPages[ix]:getDescendantByName("layout")
CpSettingsUtil.generateAndBindGuiElements(data, layout,
self.multiTextPrefab, self.booleanPrefab, settings)
CpSettingsUtil.updateGuiElementsBoundToSettings(layout)
if ix >= 2 then
break
end
ix = ix + 1
end
end
self:updateSubCategoryPages(self.CATEGRORIES.BASIC_SETTINGS)
FocusManager:setFocus(self.subCategoryPages[self.subCategoryPaging:getState()]:getDescendantByName("layout"))
end

function CpGlobalSettingsFrame:onClickCpMultiTextOption(_, guiElement)
Expand All @@ -118,4 +128,5 @@ function CpGlobalSettingsFrame:updateSubCategoryPages(state)
local layout = self.subCategoryPages[state]:getDescendantByName("layout")
CpSettingsUtil.updateGuiElementsBoundToSettings(layout)
self.settingsSlider:setDataElement(layout)
FocusManager:setFocus(layout)
end
10 changes: 10 additions & 0 deletions scripts/gui/pages/CpVehicleSettingsFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ function CpVehicleSettingsFrame:initialize(menu)
end
end


function CpVehicleSettingsFrame:delete()
self.booleanPrefab:delete()
self.multiTextPrefab:delete()
self.sectionHeaderPrefab:delete()
self.selectorPrefab:delete()
self.containerPrefab:delete()
CpVehicleSettingsFrame:superClass().delete(self)
end

function CpVehicleSettingsFrame:onFrameOpen()
CpVehicleSettingsFrame:superClass().onFrameOpen(self)
local vehicle = self.cpMenu:getCurrentVehicle()
Expand Down

0 comments on commit c8164ce

Please sign in to comment.