NSIS。特殊(带图像)部分页面

时间:2012-04-17 16:53:46

标签: nsis

我正在使用NSIS创建准备好的游戏服务器。

首先我需要用户选择服务器类型(公共/僵尸/其他游戏模式)

然后会显示插件列表,图片和每个插件的说明。

这样的事情:

公共插件将是其他

我该怎么做?

1 个答案:

答案 0 :(得分:2)

我不太清楚你是否也想要正常的部分,有两个组件页面使事情变得复杂但我认为这就是你想要的,所以这个例子就是这样:

outfile "$%temp%\sotest.exe"
RequestExecutionLevel user
!include MUI2.nsh
!include nsDialogs.nsh
!define MUI_COMPONENTSPAGE_NODESC
!define MUI_CUSTOMFUNCTION_GUIINIT onguiinit
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_PRE pagecbcmpnorm
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE pagecbcmpplugin
!define MUI_PAGE_CUSTOMFUNCTION_SHOW pagecbcmppluginshow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE pagecbcmppluginleave
!insertmacro MUI_PAGE_COMPONENTS 
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Section "Program Files (Required)" NSEC_BASE
SectionIn RO
SectionEnd

Section "Help" NSEC_HELP
SectionEnd

Section "Zombie base" PSEC_BASE
SectionIn RO
SectionEnd

Section "Super Gun" PSEC_SGUN
SectionEnd

Section "Zombie Invade" PSEC_INVADE
SectionEnd

Function onguiinit
InitPluginsDir
StrCpy $0 0
ClearErrors
loop:
    SectionGetFlags $0 $1
    IfErrors done
    SectionGetText $0 $1
    WriteIniStr "$pluginsdir\cmpnt.ini" "S" $0 $1
    IntOp $0 $0 + 1
    goto loop
done:
;Init dummy plugin descriptions and images
WriteIniStr "$pluginsdir\cmpnt.ini" "PData" "${PSEC_BASE}:txt" "Blah Blah"
WriteIniStr "$pluginsdir\cmpnt.ini" "PData" "${PSEC_SGUN}:txt" "Bang!"
WriteIniStr "$pluginsdir\cmpnt.ini" "PData" "${PSEC_INVADE}:txt" "Charge!!!"
File "/oname=$pluginsdir\cmpnt_p${PSEC_BASE}.bmp" "${NSISDIR}\contrib\Graphics\Header\nsis.bmp"
File "/oname=$pluginsdir\cmpnt_p${PSEC_SGUN}.bmp" "${NSISDIR}\contrib\Graphics\Header\orange-uninstall.bmp"
File "/oname=$pluginsdir\cmpnt_p${PSEC_INVADE}.bmp" "${NSISDIR}\contrib\Graphics\Header\win.bmp"
FunctionEnd


!define FIRSTPLUGINSECIDX ${PSEC_BASE}
!define /math LASTPLUGINSECIDX ${PSEC_INVADE} + 1

Function ToggleSections
StrCpy $0 0
ClearErrors
loop:
    SectionGetFlags $0 $1
    IfErrors done
    SectionSetText $0 ""
    IntOp $0 $0 + 1
    goto loop
done:
Pop $0
Pop $2
loopset:
    ReadIniStr $1 "$pluginsdir\cmpnt.ini" "S" $0
    SectionSetText $0 $1
    IntOp $0 $0 + 1
    IntCmp $0 $2 0 loopset
FunctionEnd


Function pagecbcmpnorm
Push ${FIRSTPLUGINSECIDX}
Push 0
call ToggleSections
FunctionEnd

Function pagecbcmpplugin
Push ${LASTPLUGINSECIDX}
Push ${FIRSTPLUGINSECIDX}
call ToggleSections
FunctionEnd

!define ID_TOP 0x3FF
!define ID_TXT 0x3FE
!define ID_IMG 0x3EE
!define ID_LST 0x408
Function pagecbcmppluginshow
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $2 $R0 ${ID_TOP}
ShowWindow $2 0

System::Call '*(i,i,i,i)i.r1'
System::Call 'user32::GetClientRect(i $R0,ir1)'
System::Call '*$1(i,i,i.r8,i.r7)'
System::Free $1

IntOp $8 $8 - 16 ;margin
GetDlgItem $2 $R0 ${ID_LST}
IntOp $6 $8 / 2
System::Call 'user32::SetWindowPos(i$2,i0,i0,i0,ir6,ir7,i0x14)'

IntOp $6 $6 + 8 ;half of margin
GetDlgItem $2 $R0 ${ID_IMG}
${NSD_AddStyle} $2 ${SS_BITMAP}
IntOp $7 $7 - 38
System::Call 'user32::SetWindowPos(i$2,i0,ir6,i0,ir6,ir7,i0x14)'

GetDlgItem $2 $R0 ${ID_TXT}
IntOp $7 $7 + 8
System::Call 'user32::SetWindowPos(i$2,i0,ir6,ir7,ir6,i 50,i0x14)'

StrCpy $9 0 ;make sure bitmap variable is null
StrCpy $0 ${FIRSTPLUGINSECIDX}
call .onMouseOverSection ;force update
FunctionEnd

Function pagecbcmppluginleave
${NSD_FreeBitmap} $9
StrCpy $9 0
FunctionEnd

Function .onMouseOverSection
ReadIniStr $1 "$pluginsdir\cmpnt.ini" "PData" "$0:txt"
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $2 $R0 ${ID_TXT}
SendMessage $2 ${WM_SETTEXT} 0 "STR:$1"
GetDlgItem $2 $R0 ${ID_IMG}
call pagecbcmppluginleave
${NSD_SetBitmap} $2 "$pluginsdir\cmpnt_p$0.bmp" $9
FunctionEnd