将 Inno Setup 子组件显示为同级组件,并在复选框中显示检查而不是方块

问题描述 投票:0回答:1

我正在尝试让一个子组件显示为兄弟组件。 我正在为一个游戏制作一个安装程序,该游戏可以在同一安装文件夹中共存多个版本的游戏。

现在我希望能够安装可选模组,这些模组需要安装特定版本的游戏(依赖项)。因此,当用户单击某个模组时,就会选择所需的游戏,如果取消选择该游戏,则所有模组都会被取消选择。代码按预期工作并且行为如前所述。有时它会让用户感到有点困惑。例如,如果没有安装 mod,则游戏中会显示一个正方形而不是检查,并且 mod 的层次结构是不必要的。

我想要实现的目标:

  1. 我想要
    game_2
    显示 check 而不是 square
  2. game_2\com_mods
    作为
    game_2
    的兄弟姐妹,而不是作为孩子。

据我所知,我想没有简单的方法可以达到这种效果。如果我没有错误地使用

[Code]
部分,则可以修改 UI,但我不知道如何强制使用复选框而不是正方形并删除子项的填充。

这是我的示例代码:

[Setup]
AppName=Demo
AppVersion=1.0
DefaultDirName=.

[Components]
Name: "game_1";    Description: "Game v1";  Types: full custom; Flags: checkablealone
Name: "game_2";    Description: "Game v2";  Types: full custom; Flags: checkablealone
Name: "game_2\com_mods";    Description: "Game Community Mods"; Types: full custom;  Flags: dontinheritcheck
Name: "game_2\com_mods\3rdmod1"; Description: "Mod 1"; Flags: exclusive
Name: "game_2\com_mods\3rdmod1"; Description: "Mod 2"; Flags: exclusive
Name: "game_2\com_mods\3rdmod1"; Description: "Mod 3"; Flags: exclusive 

我希望有人可以帮助我或为我指明正确的方向以产生预期的效果。

问候和感谢。

checkbox inno-setup hierarchy pascalscript
1个回答
5
投票

如果我正确理解你的问题,你想要这个布局:

[Components]
Name: "game_1";    Description: "Game v1";  Types: full custom
Name: "game_2";    Description: "Game v2";  Types: full custom
Name: "com_mods";    Description: "Game Community Mods"; Types: full custom
Name: "com_mods\3rdmod1"; Description: "Mod 1"; Flags: exclusive
Name: "com_mods\3rdmod1"; Description: "Mod 2"; Flags: exclusive
Name: "com_mods\3rdmod1"; Description: "Mod 3"; Flags: exclusive 

但是您想保留当前布局的行为。

然后您必须在 Pascal 脚本中编写行为代码:

[Code]

const
  Game2Index = 1;
  Game2ModsIndex = 2;

var
  Game2Checked: Boolean;

procedure ComponentsListClickCheck(Sender: TObject);
var
  ComponentsList: TNewCheckListBox;
begin
  ComponentsList := WizardForm.ComponentsList;

  // If Game 2 got unchecked
  if Game2Checked and
     (not ComponentsList.Checked[Game2Index]) then
  begin
    // uncheck the mods
    ComponentsList.Checked[Game2ModsIndex] := False;
  end; 

  // If Game 2 mods got checked, make sure Game 2 is checked too
  if ComponentsList.Checked[Game2ModsIndex] and
     (not ComponentsList.Checked[Game2Index]) then
  begin
    ComponentsList.Checked[Game2Index] := True;
  end; 

  Game2Checked := ComponentsList.Checked[Game2Index];
end;

procedure InitializeWizard();
begin
  WizardForm.ComponentsList.OnClickCheck := @ComponentsListClickCheck;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectComponents then
  begin
    // Remember the initial state
    Game2Checked := WizardForm.ComponentsList.Checked[Game2Index];
  end;
end;

在 Inno Setup 6 中,您可以使用

WizardIsComponentSelected
WizardSelectComponents
来代替使用索引。

© www.soinside.com 2019 - 2024. All rights reserved.