summaryrefslogtreecommitdiff
path: root/src/components/ConfigurationSection.tsx
blob: eeacf0514b2e37917be06e82c339b6737e309aaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import { PanelSectionRow, ToggleField, SliderField, ButtonItem } from "@decky/ui";
import { useState, useEffect } from "react";
import { RiArrowDownSFill, RiArrowUpSFill } from "react-icons/ri";
import { ConfigurationData } from "../config/configSchema";
import {
  FLOW_SCALE, PERFORMANCE_MODE, HDR_MODE,
  EXPERIMENTAL_PRESENT_MODE, DXVK_FRAME_RATE, DISABLE_STEAMDECK_MODE,
  MANGOHUD_WORKAROUND, DISABLE_VKBASALT, FORCE_ENABLE_VKBASALT, ENABLE_WSI, ENABLE_ZINK
} from "../config/generatedConfigSchema";

interface ConfigurationSectionProps {
  config: ConfigurationData;
  onConfigChange: (fieldName: keyof ConfigurationData, value: boolean | number | string) => Promise<void>;
}

const WORKAROUNDS_COLLAPSED_KEY = "lsfg-workarounds-collapsed";
const CONFIG_COLLAPSED_KEY = "lsfg-config-collapsed";

export function ConfigurationSection({
  config,
  onConfigChange
}: ConfigurationSectionProps) {
  // Initialize with localStorage value, fallback to true if not found
  const [configCollapsed, setConfigCollapsed] = useState(() => {
    try {
      const saved = localStorage.getItem(CONFIG_COLLAPSED_KEY);
      return saved !== null ? JSON.parse(saved) : false;
    } catch {
      return false;
    }
  });

  const [workaroundsCollapsed, setWorkaroundsCollapsed] = useState(() => {
    try {
      const saved = localStorage.getItem(WORKAROUNDS_COLLAPSED_KEY);
      return saved !== null ? JSON.parse(saved) : true;
    } catch {
      return true;
    }
  });

  // Persist workarounds collapse state to localStorage
  useEffect(() => {
    try {
      localStorage.setItem(CONFIG_COLLAPSED_KEY, JSON.stringify(configCollapsed));
    } catch (error) {
      console.warn("Failed to save config collapse state:", error);
    }
  }, [configCollapsed]);

  useEffect(() => {
    try {
      localStorage.setItem(WORKAROUNDS_COLLAPSED_KEY, JSON.stringify(workaroundsCollapsed));
    } catch (error) {
      console.warn("Failed to save workarounds collapse state:", error);
    }
  }, [workaroundsCollapsed]);

  return (
    <>
      <style>
        {`
        .LSFG_ConfigCollapseButton_Container > div > div > div > button,
        .LSFG_ConfigCollapseButton_Container > div > div > div > div > button,
        .LSFG_WorkaroundsCollapseButton_Container > div > div > div > button {
          height: 10px !important;
        }
        .LSFG_WorkaroundsCollapseButton_Container > div > div > div > div > button {
          height: 10px !important;
        }
        `}
      </style>

      {/* Config Section */}
      <PanelSectionRow>
        <div
          style={{
            fontSize: "14px",
            fontWeight: "bold",
            marginTop: "16px",
            marginBottom: "8px",
            borderBottom: "1px solid rgba(255, 255, 255, 0.2)",
            paddingBottom: "4px",
            color: "white"
          }}
        >
          Config
        </div>
      </PanelSectionRow>

      <PanelSectionRow>
        <div className="LSFG_ConfigCollapseButton_Container">
          <ButtonItem
            layout="below"
            bottomSeparator={configCollapsed ? "standard" : "none"}
            onClick={() => setConfigCollapsed(!configCollapsed)}
          >
            {configCollapsed ? (
              <RiArrowDownSFill
                style={{ transform: "translate(0, -13px)", fontSize: "1.5em" }}
              />
            ) : (
              <RiArrowUpSFill
                style={{ transform: "translate(0, -12px)", fontSize: "1.5em" }}
              />
            )}
          </ButtonItem>
        </div>
      </PanelSectionRow>

      {!configCollapsed && (
        <>
          <PanelSectionRow>
            <SliderField
              label={`Flow Scale (${Math.round(config.flow_scale * 100)}%)`}
              description="Lowers internal motion estimation resolution, improving performance slightly"
              value={config.flow_scale}
              min={0.25}
              max={1.0}
              step={0.01}
              onChange={(value) => onConfigChange(FLOW_SCALE, value)}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <SliderField
              label={`Base FPS Cap${config.dxvk_frame_rate > 0 ? ` (${config.dxvk_frame_rate} FPS)` : " (Off)"}`}
              description="Base framerate cap for DirectX games, before frame multiplier. (Requires game restart to apply)"
              value={config.dxvk_frame_rate}
              min={0}
              max={60}
              step={1}
              onChange={(value) => onConfigChange(DXVK_FRAME_RATE, value)}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label={`Present Mode (${(config.experimental_present_mode || "fifo") === "fifo" ? "FIFO - VSync" : "Mailbox"})`}
              description="Toggle between FIFO - VSync (default) and Mailbox presentation modes for better performance or compatibility"
              checked={(config.experimental_present_mode || "fifo") === "fifo"}
              onChange={(value) => onConfigChange(EXPERIMENTAL_PRESENT_MODE, value ? "fifo" : "mailbox")}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label="Performance Mode"
              description="Uses a lighter model for FG (Recommended for most games)"
              checked={config.performance_mode}
              onChange={(value) => onConfigChange(PERFORMANCE_MODE, value)}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label="HDR Mode"
              description="Enables HDR mode (only for games that support HDR)"
              checked={config.hdr_mode}
              onChange={(value) => onConfigChange(HDR_MODE, value)}
            />
          </PanelSectionRow>
        </>
      )}

      {/* Workarounds Section */}
      <PanelSectionRow>
        <div
          style={{
            fontSize: "14px",
            fontWeight: "bold",
            marginTop: "16px",
            marginBottom: "8px",
            borderBottom: "1px solid rgba(255, 255, 255, 0.2)",
            paddingBottom: "4px",
            color: "white"
          }}
        >
          Workarounds
        </div>
      </PanelSectionRow>

      <PanelSectionRow>
        <div className="LSFG_WorkaroundsCollapseButton_Container">
          <ButtonItem
            layout="below"
            bottomSeparator={workaroundsCollapsed ? "standard" : "none"}
            onClick={() => setWorkaroundsCollapsed(!workaroundsCollapsed)}
          >
            {workaroundsCollapsed ? (
              <RiArrowDownSFill
                style={{ transform: "translate(0, -13px)", fontSize: "1.5em" }}
              />
            ) : (
              <RiArrowUpSFill
                style={{ transform: "translate(0, -12px)", fontSize: "1.5em" }}
              />
            )}
          </ButtonItem>
        </div>
      </PanelSectionRow>

      {!workaroundsCollapsed && (
        <>
        <PanelSectionRow>
            <ToggleField
              label="Enable WSI"
              description="Re-Enable Gamescope WSI Layer. Requires game restart to apply."
              checked={config.enable_wsi}
              onChange={(value) => onConfigChange(ENABLE_WSI, value)}
            />
          </PanelSectionRow>
          
          <PanelSectionRow>
            <ToggleField
              label="Enable WOW64 for 32-bit games"
              description="Enables PROTON_USE_WOW64=1 for 32-bit games (Use with ProtonGE to fix crashing)"
              checked={config.enable_wow64}
              onChange={(value) => onConfigChange('enable_wow64', value)}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label="Disable Steam Deck Mode"
              description="Disables Steam Deck mode (Unlocks hidden settings in some games)"
              checked={config.disable_steamdeck_mode}
              onChange={(value) => onConfigChange(DISABLE_STEAMDECK_MODE, value)}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label="MangoHud Workaround"
              description="Enables a transparent mangohud overlay, sometimes fixes issues with 2X multiplier in game mode"
              checked={config.mangohud_workaround}
              onChange={(value) => onConfigChange(MANGOHUD_WORKAROUND, value)}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label="Disable vkBasalt"
              description="Disables vkBasalt layer which can conflict with LSFG (Reshade, some Decky plugins)"
              checked={config.disable_vkbasalt}
              disabled={config.force_enable_vkbasalt}
              onChange={(value) => {
                if (value && config.force_enable_vkbasalt) {
                  // Turn off force enable when enabling disable
                  onConfigChange(FORCE_ENABLE_VKBASALT, false);
                }
                onConfigChange(DISABLE_VKBASALT, value);
              }}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label="Force Enable vkBasalt"
              description="Force vkBasalt to engage to fix framepacing issues in gamemode"
              checked={config.force_enable_vkbasalt}
              disabled={config.disable_vkbasalt}
              onChange={(value) => {
                if (value && config.disable_vkbasalt) {
                  // Turn off disable when enabling force enable
                  onConfigChange(DISABLE_VKBASALT, false);
                }
                onConfigChange(FORCE_ENABLE_VKBASALT, value);
              }}
            />
          </PanelSectionRow>

          <PanelSectionRow>
            <ToggleField
              label="Enable Zink for OpenGL Games"
              description="Use Vulkan-based OpenGL implementation for OpenGL games (may cause crashes or freezes with some games)"
              checked={config.enable_zink}
              onChange={(value) => onConfigChange(ENABLE_ZINK, value)}
            />
          </PanelSectionRow>
        </>
      )}
    </>
  );
}