Skip to content

Commit c4624da

Browse files
committed
[settings] Add label helper function
1 parent 8113839 commit c4624da

1 file changed

Lines changed: 37 additions & 137 deletions

File tree

LuaMenu/widgets/gui_settings_window.lua

Lines changed: 37 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,21 @@ local function AddNumberSetting(offset, caption, desc, key, default, minVal, max
692692
return label, numberInput, offset + ITEM_OFFSET
693693
end
694694

695+
local function AddLabel(offset, caption, tooltip)
696+
local Configuration = WG.Chobby.Configuration
697+
return Label:New {
698+
x = 20,
699+
y = offset + TEXT_OFFSET,
700+
width = 90,
701+
height = 40,
702+
valign = "top",
703+
align = "left",
704+
font = Configuration:GetFont(2),
705+
caption = caption,
706+
tooltip = tooltip,
707+
}
708+
end
709+
695710
local function GetLobbyTabControls()
696711
local freezeSettings = true
697712

@@ -718,16 +733,7 @@ local function GetLobbyTabControls()
718733
langNum = langNum + 1
719734
end
720735

721-
children[#children + 1] = Label:New {
722-
x = 20,
723-
y = offset + TEXT_OFFSET,
724-
width = 90,
725-
height = 40,
726-
valign = "top",
727-
align = "left",
728-
objectOverrideFont = Configuration:GetFont(2),
729-
caption = "Language",
730-
}
736+
children[#children + 1] = AddLabel(offset, "Language")
731737
children[#children + 1] = ComboBox:New {
732738
x = COMBO_X,
733739
y = offset,
@@ -748,16 +754,7 @@ local function GetLobbyTabControls()
748754
}
749755
offset = offset + ITEM_OFFSET
750756

751-
children[#children + 1] = Label:New {
752-
x = 20,
753-
y = offset + TEXT_OFFSET,
754-
width = 90,
755-
height = 40,
756-
valign = "top",
757-
align = "left",
758-
objectOverrideFont = Configuration:GetFont(2),
759-
caption = "Split Panel Mode",
760-
}
757+
children[#children + 1] = AddLabel(offset, "Split Panel Mode")
761758
children[#children + 1] = ComboBox:New {
762759
x = COMBO_X,
763760
y = offset,
@@ -780,16 +777,7 @@ local function GetLobbyTabControls()
780777
children[#children + 1], children[#children + 2], offset = AddNumberSetting(offset, "Lobby Interface Scale", "Increase or decrease interface size, for accessibility and 4k screens.",
781778
"uiScale", Configuration.uiScale, Configuration.minUiScale*100, Configuration.maxUiScale*100, true)
782779

783-
children[#children + 1] = Label:New {
784-
x = 20,
785-
y = offset + TEXT_OFFSET,
786-
width = 90,
787-
height = 40,
788-
valign = "top",
789-
align = "left",
790-
objectOverrideFont = Configuration:GetFont(2),
791-
caption = "Chat Font Size",
792-
}
780+
children[#children + 1] = AddLabel(offset, "Chat Font Size")
793781
children[#children + 1] = Trackbar:New {
794782
x = COMBO_X,
795783
y = offset,
@@ -810,16 +798,7 @@ local function GetLobbyTabControls()
810798
}
811799
offset = offset + ITEM_OFFSET
812800

813-
children[#children + 1] = Label:New {
814-
x = 20,
815-
y = offset + TEXT_OFFSET,
816-
width = 90,
817-
height = 40,
818-
valign = "top",
819-
align = "left",
820-
objectOverrideFont = Configuration:GetFont(2),
821-
caption = "Menu Music Volume",
822-
}
801+
children[#children + 1] = AddLabel(offset, "Menu Music Volume")
823802
children[#children + 1] = Trackbar:New {
824803
x = COMBO_X,
825804
y = offset,
@@ -840,16 +819,7 @@ local function GetLobbyTabControls()
840819
}
841820
offset = offset + ITEM_OFFSET
842821

843-
children[#children + 1] = Label:New {
844-
x = 20,
845-
y = offset + TEXT_OFFSET,
846-
width = 90,
847-
height = 40,
848-
valign = "top",
849-
align = "left",
850-
objectOverrideFont = Configuration:GetFont(2),
851-
caption = "Notification Volume",
852-
}
822+
children[#children + 1] = AddLabel(offset, "Notification Volume")
853823
children[#children + 1] = Trackbar:New {
854824
x = COMBO_X,
855825
y = offset,
@@ -870,16 +840,7 @@ local function GetLobbyTabControls()
870840
}
871841
offset = offset + ITEM_OFFSET
872842

873-
children[#children + 1] = Label:New {
874-
x = 20,
875-
y = offset + TEXT_OFFSET,
876-
width = 90,
877-
height = 40,
878-
valign = "top",
879-
align = "left",
880-
objectOverrideFont = Configuration:GetFont(2),
881-
caption = "Background Brightness",
882-
}
843+
children[#children + 1] = AddLabel(offset, "Background Brightness")
883844
children[#children + 1] = Trackbar:New {
884845
x = COMBO_X,
885846
y = offset,
@@ -900,16 +861,7 @@ local function GetLobbyTabControls()
900861
}
901862
offset = offset + ITEM_OFFSET
902863

903-
children[#children + 1] = Label:New {
904-
x = 20,
905-
y = offset + TEXT_OFFSET,
906-
width = 90,
907-
height = 40,
908-
valign = "top",
909-
align = "left",
910-
objectOverrideFont = Configuration:GetFont(2),
911-
caption = "Game Overlay Opacity",
912-
}
864+
children[#children + 1] = AddLabel(offset, "Game Overlay Opacity")
913865
children[#children + 1] = Trackbar:New {
914866
x = COMBO_X,
915867
y = offset,
@@ -930,17 +882,10 @@ local function GetLobbyTabControls()
930882
}
931883
offset = offset + ITEM_OFFSET
932884

933-
children[#children + 1] = Label:New {
934-
x = 20,
935-
y = offset + TEXT_OFFSET,
936-
width = 90,
937-
height = 40,
938-
valign = "top",
939-
align = "left",
940-
objectOverrideFont = Configuration:GetFont(2),
941-
caption = "Coop Connection Delay",
942-
tooltip = "Hosts with poor internet may require their clients to add a delay in order to connect.",
943-
}
885+
children[#children + 1] = AddLabel(offset,
886+
"Coop Connection Delay",
887+
"Hosts with poor internet may require their clients to add a delay in order to connect."
888+
)
944889
children[#children + 1] = Trackbar:New {
945890
x = COMBO_X,
946891
y = offset,
@@ -988,7 +933,7 @@ local function GetLobbyTabControls()
988933
if not Configuration.gameConfig.disablePlanetwars then
989934
children[#children + 1], offset = AddCheckboxSetting(offset, i18n("planetwars_notifications"), "planetwarsNotifications", false)
990935
end
991-
936+
992937
children[#children + 1], offset = AddCheckboxSetting(offset, "Autosave SP on matchmaker", "autosaveOnMatchmaker", true)
993938
children[#children + 1], offset = AddCheckboxSetting(offset, i18n("ingame_notifcations"), "ingameNotifcations", true)
994939
children[#children + 1], offset = AddCheckboxSetting(offset, i18n("non_friend_notifications"), "nonFriendNotifications", true)
@@ -1000,20 +945,11 @@ local function GetLobbyTabControls()
1000945
children[#children + 1], offset = AddCheckboxSetting(offset, i18n("animate_lobby"), "animate_lobby", true)
1001946
children[#children + 1], offset = AddCheckboxSetting(offset, i18n("drawFullSpeed"), "drawAtFullSpeed", false)
1002947
children[#children + 1], offset = AddCheckboxSetting(offset, "Minimize lobby updates", "lobbyIdleSleep", true)
1003-
948+
1004949
-- Not needed as it happens automatically for spectating and singleplayer.
1005950
--children[#children + 1], offset = AddCheckboxSetting(offset, i18n("keep_queues"), "rememberQueuesOnStart2", false, nil, "Stay in the matchmaker when you launch a singleplayer game or replay, as well as when watching a multiplayer game.")
1006951

1007-
children[#children + 1] = Label:New {
1008-
x = 20,
1009-
y = offset + TEXT_OFFSET,
1010-
width = 90,
1011-
height = 40,
1012-
valign = "top",
1013-
align = "left",
1014-
objectOverrideFont = Configuration:GetFont(2),
1015-
caption = "Clear Channel History",
1016-
}
952+
children[#children + 1] = AddLabel(offset, "Clear Channel History")
1017953
children[#children + 1] = Button:New {
1018954
x = COMBO_X,
1019955
y = offset,
@@ -1031,16 +967,7 @@ local function GetLobbyTabControls()
1031967
}
1032968
offset = offset + ITEM_OFFSET
1033969

1034-
children[#children + 1] = Label:New {
1035-
x = 20,
1036-
y = offset + TEXT_OFFSET,
1037-
width = 90,
1038-
height = 40,
1039-
valign = "top",
1040-
align = "left",
1041-
objectOverrideFont = Configuration:GetFont(2),
1042-
caption = "Delete Path Cache",
1043-
}
970+
children[#children + 1] = AddLabel(offset, "Delete Path Cache")
1044971
children[#children + 1] = Button:New {
1045972
x = COMBO_X,
1046973
y = offset,
@@ -1116,16 +1043,7 @@ local function GetVoidTabControls()
11161043
children[#children + 1], offset = AddCheckboxSetting(offset, "Use wrong engine", "useWrongEngine", false)
11171044
children[#children + 1], offset = AddCheckboxSetting(offset, "Show old AI versions", "showOldAiVersions", false)
11181045

1119-
children[#children + 1] = Label:New {
1120-
x = 20,
1121-
y = offset + TEXT_OFFSET,
1122-
width = 90,
1123-
height = 40,
1124-
valign = "top",
1125-
align = "left",
1126-
objectOverrideFont = Configuration:GetFont(2),
1127-
caption = "Disable Lobby",
1128-
}
1046+
children[#children + 1] = AddLabel(offset, "Disable Lobby")
11291047
children[#children + 1] = Button:New {
11301048
x = COMBO_X,
11311049
y = offset,
@@ -1142,16 +1060,7 @@ local function GetVoidTabControls()
11421060
}
11431061
offset = offset + ITEM_OFFSET
11441062

1145-
children[#children + 1] = Label:New {
1146-
x = 20,
1147-
y = offset + TEXT_OFFSET,
1148-
width = 90,
1149-
height = 40,
1150-
valign = "top",
1151-
align = "left",
1152-
objectOverrideFont = Configuration:GetFont(2),
1153-
caption = "Server Address (zero-k.info or test.zero-k.info for testing)",
1154-
}
1063+
children[#children + 1] = AddLabel(offset, "Server Address (zero-k.info or test.zero-k.info for testing)")
11551064
children[#children + 1] = EditBox:New {
11561065
x = COMBO_X,
11571066
y = offset,
@@ -1174,16 +1083,7 @@ local function GetVoidTabControls()
11741083
}
11751084
offset = offset + ITEM_OFFSET
11761085

1177-
children[#children + 1] = Label:New {
1178-
x = 20,
1179-
y = offset + TEXT_OFFSET,
1180-
width = 90,
1181-
height = 40,
1182-
valign = "top",
1183-
align = "left",
1184-
objectOverrideFont = Configuration:GetFont(2),
1185-
caption = "Server Port (8200 or 8202 for testing)",
1186-
}
1086+
children[#children + 1] = AddLabel(offset, "Server Port (8200 or 8202 for testing)")
11871087
children[#children + 1] = EditBox:New {
11881088
x = COMBO_X,
11891089
y = offset,
@@ -1324,7 +1224,7 @@ local function MakeRestartWarning(offset)
13241224
objectOverrideFont = Configuration:GetFont(2),
13251225
caption = "Warning: Most changes do not affect battles in progress.",
13261226
}
1327-
1227+
13281228
return warningLabel, offset + ITEM_OFFSET
13291229
end
13301230

@@ -1671,7 +1571,7 @@ local function PopulateTab(settingPresets, settingOptions, settingsDefault)
16711571
label, list, customSettingsSwitch, offset = MakePresetsControl(settingPresets, offset)
16721572
children[#children + 1] = label
16731573
children[#children + 1] = list
1674-
1574+
16751575
label, offset = MakeRestartWarning(offset)
16761576
children[#children + 1] = label
16771577
end
@@ -1856,7 +1756,7 @@ function SettingsWindow.WriteGameSpringsettings(fileName)
18561756
WriteToFile("WindowBorderless", 0)
18571757
WriteToFile("Fullscreen", 1)
18581758
end
1859-
1759+
18601760
settingsFile:close()
18611761
end
18621762

@@ -1981,7 +1881,7 @@ function widget:Initialize()
19811881

19821882
-- Settings which rely on io
19831883
local gameSettings = Configuration.game_settings
1984-
1884+
19851885
if lobbyFullscreen ~= battleStartDisplay or battleStartDisplay >= 4 then
19861886
SetLobbyFullscreenMode(battleStartDisplay)
19871887

0 commit comments

Comments
 (0)