- {
- DrawField(X, Y);
- }
- }
- }
-}
-
-#if 0
-
-static void cmbFile_Click()
-{
- CurPath = CAT(StripDir(OrigPath), CAT("/", cmbFile.List(cmbFile.ListIndex)));
- OrigPath = CurPath;
- FillLevelList(CurPath, LevelNumber);
- if (STRING_IS_LIKE(OrigPath, "*.mpx") || STRING_IS_LIKE(OrigPath, "*.sp"))
- {
- menSave.Enabled = True;
- }
- else
- {
- menSave.Enabled = False;
- }
-}
-
-static void cmbFile_KeyDown(int KeyCode, int Shift)
-{
- picPane_KeyDown(KeyCode, Shift);
-}
-
-static void cmbFile_KeyUp(int KeyCode, int Shift)
-{
- picPane_KeyUp(KeyCode, Shift);
-}
-
-static int GetFileNameToSave()
-{
- static int GetFileNameToSave;
-
- char *T;
-
- (char *)T = StripFileName(OrigPath);
- if (STRING_IS_LIKE(T, "*.dat") || STRING_IS_LIKE(T, "*.d##"))
- {
- T = "Level" & Format(LevelNumber, "#000");
- }
-
- GetFileNameToSave = T;
-
- return GetFileNameToSave;
-}
-
-static void cmbLevel_Click()
-{
- long InfoCount;
- boolean Oldflag;
- int Msg;
- static long LastIndex = 0;
- static boolean bBlock = False;
-
- if (bBlock)
- return;
-
- // //////////////////////////////////////////////////////////////////
- if (ModifiedFlag)
- {
- VbMsgBoxResult Res;
-
- Msg = "Save changes to " & GetFileNameToSave() & " ?";
- Res = MsgBox(Msg, vbYesNoCancel, AppTitle & " - close level");
- if (Res == vbCancel) // fallback
- {
- bBlock = True;
-
- // --- On Error Resume Next
- cmbLevel.ListIndex = LastIndex;
- // --- On Error GoTo 0
-
- bBlock = False;
- Debug.Assert cmbLevel.ListIndex = LastIndex;
- return;
- }
-
- if (Res == vbYes)
- {
- // Dim oldCurPath$
- // oldCurPath = CurPath
- if (FileExists(OrigPath) && menSave.Enabled)
- {
- menSave_Click();
- }
- else
- {
- if (! SaveAs()) // fallback
- {
- bBlock = True;
-
- // --- On Error Resume Next
- cmbLevel.ListIndex = LastIndex;
- // --- On Error GoTo 0
-
- bBlock = False;
- Debug.Assert cmbLevel.ListIndex = LastIndex;
- return;
- }
- }
-
- // CurPath = oldCurPath
- }
-
- Let_ModifiedFlag(False);
- CurPath = OrigPath;
- }
-
- // //////////////////////////////////////////////////////////////////
- {
- LevelNumber = cmbLevel.ListIndex + 1;
- DemoFlag = False;
- if (Loaded)
- {
- Oldflag = NoDisplayFlag;
- NoDisplayFlag = False;
- subFetchAndInitLevel();
- if ((0 < SignatureDelay) && ! (WindowState == vbMinimized))
- {
- Msg = LInfo.LevelTitle & vbNewLine & "(" & FieldWidth & " x " & FieldHeight & ")";
- if (DemoAvailable && bSignatureAvailable)
- Msg = Msg & vbNewLine & vbNewLine & gSignature;
-
- SignatureForm.Signature = Msg;
- SignatureForm.DelayMS = SignatureDelay;
- int X, Y;
-
- X = left + (Width - SignatureForm.Width) / 2;
- Y = top + (Height - SignatureForm.Height) / 2;
- SignatureForm.Move X, Y;
- SignatureForm.Show vbModeless, Me;
- Me.SetFocus;
- }
-
- lblStatus = "MegaPlex";
- lblFrameCount = GetTotalFramesOfDemo();
- if (EditFlag)
- EdAll();
-
- ReStretch(Stretch);
- // picPane_Paint
- Stage.Blt();
- NoDisplayFlag = Oldflag;
- LastIndex = cmbLevel.ListIndex;
- }
-
- }
- menPlayDemo.Enabled = DemoAvailable;
- cmdPlayDemo.Enabled = DemoAvailable;
-}
-
-static void cmblevel_KeyDown(int KeyCode, int Shift)
-{
- if (GameLoopRunning != 0)
- return;
-
- switch (KeyCode)
- {
- case vbKeySpace:
- if (menPlay.Enabled == True)
- menPlay_Click();
-
- break;
-
- default:
- picPane_KeyDown(KeyCode, Shift);
- break;
- }
-}
-
-static void cmbLevel_KeyUp(int KeyCode, int Shift)
-{
- picPane_KeyUp(KeyCode, Shift);
-}
-
-static void cmdPause_Click()
-{
- menPause_Click();
-}
-
-static void cmdPause_MouseUp(int Button, int Shift, float X, float Y)
-{
- FocusTim.Enabled = True;
-}
-
-static void cmdPlay_Click()
-{
- if (menPlay.Enabled)
- menPlay_Click();
-}
-
-static void cmdPlay_MouseUp(int Button, int Shift, float X, float Y)
-{
- FocusTim.Enabled = True;
-}
-
-static void cmdPlayAll_Click()
-{
- menPlayAll_Click();
-}
-
-static void cmdPlayAll_MouseUp(int Button, int Shift, float X, float Y)
-{
- FocusTim.Enabled = True;
-}
-
-static void cmdPlayDemo_Click()
-{
- menPlayDemo_Click();
-}
-
-static void cmdPlayDemo_MouseUp(int Button, int Shift, float X, float Y)
-{
- FocusTim.Enabled = True;
-}
-
-static void cmdRecordDemo_Click()
-{
- if (menRec.Enabled)
- menRec_Click();
-}
-
-static void cmdRecordDemo_MouseUp(int Button, int Shift, float X, float Y)
-{
- FocusTim.Enabled = True;
-}
-
-static void cmdStop_Click()
-{
- if (menStop.Enabled)
- menStop_Click();
-}
-
-static void cmdStop_MouseUp(int Button, int Shift, float X, float Y)
-{
- FocusTim.Enabled = True;
-}
-
-static void FocusTim_Timer()
-{
- FocusTim.Enabled = False;
-
- // --- On Error Resume Next
- picPane.SetFocus;
-}
-
-static void Form_KeyDown(int KeyCode, int Shift)
-{
- picPane_KeyDown(KeyCode, Shift);
-}
-
-static void Form_KeyUp(int KeyCode, int Shift)
-{
- picPane_KeyUp(KeyCode, Shift);
-}
-
-#endif
-
-void Form_Load()
-{
-#if 0
-
- long i;
- SettingsObject s;
-
-#endif
-
- Loaded = False;
- DemoFlag = 0;
- PanelSeq = 0;
- EditFlag = False;
- EditMode = edMove;
- // FMark = New MarkerObject; // (handle this later, if needed)
-
- InitGlobals();
-
-#if 0
-
- LoadMenus();
-
- TmpPath = GetValidTempPath();
- if (TmpPath == "")
- exit(-1);
-
- CleanTempDir(TmpPath);
- TmpPath = CAT(WithSlash(TmpPath), GetMyTempFileName());
- GetSettings();
- ShowPanel = 1;
-
- InitDirectX(hWnd, picPane.hWnd);
-
- // AllowRedDiskCheat = 1
- MpxBmp = CAT(App.Path, "/mpx.bmp");
- // // Set NormalSprites = New DDSpriteBuffer // (handle this later, if needed)
- // NormalSprites.CreateFromFile MPXBMP, 16, 16
-
- Field = REDIM_2D(sizeof(int), 0, 2 + 1 - 1, 0, 2 + 1 - 1);
-
- picViewPort.ScaleMode = vbPixels;
-
-#endif
-
- PauseMode = 0;
- // BaseWidth = 16
-
-#if 1
- if (0)
- menBorder_Click();
-#endif
-
- Loaded = True;
-
- ReStretch(Stretch);
-
-#if 0
-
- LoadKeyIndicators();
-
- Show();
-
- FillFileList(CurPath);
- if (s.Read("ShowSplash", True))
- {
- // frmSplash.EnableTimer
- frmSplash.Show vbModal, Me;
- }
-
-#endif
-}
-
-#if 0
-
-static void FillLevelList(char *Path, int LevelIndex)
-{
- long FNum, LevLen, i, iMax;
- char *TFile;
-
- cmbLevel.Clear;
- if (! FileExists(Path))
- return;
-
- if ((STRING_IS_LIKE(Path, "*.D??")) || (STRING_IS_LIKE(Path, "*.sp")))
- {
- FNum = FreeFile();
- LevLen = 1536;
- FNum = fopen(Path, "rb");
- {
- i = 0;
- FILE_GET(FNum, (long)1441 + i * LevLen, &LInfo, sizeof(LInfo));
- cmbLevel.AddItem Format(i + 1, "#000") & " " & LInfo.LevelTitle, i;
- if (STRING_IS_LIKE(Path, "*.D??"))
- {
- while (!(EOF(FNum)))
- {
- i = i + 1;
- FILE_GET(FNum, (long)1441 + i * LevLen, &LInfo, sizeof(LInfo));
- if (EOF(FNum))
- break;
-
- cmbLevel.AddItem Format(i + 1, "#000") & " " & LInfo.LevelTitle, i;
- }
- }
-
- if (LevelIndex <= i && 0 < LevelIndex)
- i = LevelIndex - 1;
- else
- i = 0;
-
- cmbLevel.ListIndex = i;
- }
- fclose(FNum);
- }
- else if (STRING_IS_LIKE(Path, "*.mpx"))
- {
- FNum = FreeFile();
- LevLen = 1536;
- FNum = fopen(Path, "rb");
- {
- i = 0;
- if (MpxOpen(Path))
- {
- for (i = 1; i <= LevelCount; i++)
- {
- if (! MpxLoadLInfo(CInt(i)))
- break;
-
- cmbLevel.AddItem Format(i, "#000") & " " & LInfo.LevelTitle, i - 1;
- }
-
- MpxClose();
- }
-
- if (LevelIndex < i && 0 < LevelIndex)
- i = LevelIndex - 1;
- else
- i = 0;
-
- if (i < cmbLevel.ListCount)
- cmbLevel.ListIndex = i;
-
- }
- fclose(FNum);
- }
-}
-
-static void FillFileList(char *Path)
-{
- long FNum, LevLen, i;
- int nDemoCount;
- char *TFile, *TPath, *OFile;
-
- cmbFile.Clear;
- i = 0;
- nDemoCount = 0;
- TPath = WithSlash(StripDir(Path));
- OFile = StripFileName(Path);
- TFile = Dir(TPath & "*.D??");
- while (TFile != "")
- {
- if (FileLen(TPath & TFile) == 170496)
- {
- cmbFile.AddItem TFile;
- }
-
- TFile = Dir;
- }
-
- TFile = Dir(TPath & "*.SP");
- while (TFile != "")
- {
- nDemoCount = nDemoCount + 1;
- cmbFile.AddItem TFile;
- TFile = Dir;
- }
-
- TFile = Dir(TPath & "*.mpx");
- while (TFile != "")
- {
- nDemoCount = nDemoCount + 1;
- cmbFile.AddItem TFile;
- TFile = Dir;
- }
-
- i = cmbFile.ListCount - 1;
- if (0 < cmbFile.ListCount)
- {
- do
- {
- if ((cmbFile.List(i) Like OFile) || i == 0)
- break;
-
- i = i - 1;
- }
- while (!(i < 1));
-
- cmbFile.ListIndex = i;
- }
-
- DemosAvailable = (1 < nDemoCount);
- menPlayAll.Enabled = DemosAvailable;
- cmdPlayAll.Enabled = DemosAvailable;
-}
-
-static void LoadMenus()
-{
- long i;
-
- // speeds
- menFaster.Enabled = False;
- menSlower.Enabled = False;
- InitSpeeds();
- for (i = 1; i <= nSpeedCount; i++)
- {
- if (1 < i)
- {
- Load menPlaySpeed(i);
- Load menDemoSpeed(i);
- }
-
- menPlaySpeed(i).Caption = GetSpeedDescriptionFPS(SpeedsByDelayUS[i]);
- menDemoSpeed(i).Caption = GetSpeedDescriptionFPS(SpeedsByDelayUS[i]);
- }
-
- // zoom
- menStretch(1).Caption = Format(0.25, "#0.00") & ";
- 1";
- if (Stretch == 0.25)
- menStretch(1).Checked = True;
-
- for (i = 2; i <= 20; i++)
- {
- Load menStretch(i);
- menStretch(i).Caption = Format(0.25 * i, "#0.00") & ";
- 1";
- menStretch(i).Checked = ((i * 0.25) == Stretch);
- }
-
- menSp.Enabled = False;
-}
-
-//
-// Function DisplayShift&()
-// Dim X&, Y&, A&, B&, iX&, iiX&, LD&
-// Dim Sprite&
-// DisplayShift = 0
-// For A = 0 To picPane.ScaleWidth
-// For Y = DisplayMinY To DisplayMaxY
-// For X = DisplayMinX To DisplayMaxX
-// iX = StretchWidth * X + A
-// Sprite = Field(X, Y).SpritePos
-// If picPane.ScaleWidth < (iX + 1) Then
-// iX = iX - picPane.ScaleWidth
-// Else
-// If picPane.ScaleWidth < (iX + 1 + BaseWidth) Then
-// iiX = iX - picPane.ScaleWidth
-// Sprites.BitBltSprite picPane.hdc, iiX, StretchWidth * Y, Sprite
-// End If
-// End If
-// Sprites.BitBltSprite picPane.hdc, iX, StretchWidth * Y, Sprite
-// Next X
-// Next Y
-// DisplayShift = DisplayShift + 1
-// 'DoEvents
-// Next A
-// End Function
-
-static void Form_Paint()
-{
- // Debug.Print "Form_Paint()"
-}
-
-static void Form_Resize()
-{
- long Space, NW, NH;
- int Tmp;
-
- if (WindowState == vbMinimized || ! Loaded)
- return;
-
- Space = Panel.left;
- // NW = ScaleWidth - 2 * Space: If NW < 0 Then NW = 0
- // NH = ScaleHeight - 3 * Space - cmbLevel.Height: If NH < 0 Then NH = 0
- // picViewPort.Move Space, Space, NW, NH
- Tmp = (ShowPanel != 0 ? ScaleHeight - Panel.Height : ScaleHeight);
- if (Tmp < 0)
- Tmp = 0;
-
- picViewPort.Move 0, 0, ScaleWidth, Tmp;
- // Tmp = 2 * Space + picViewPort.Height
- Panel.top = Tmp;
- Panel.left = (ScaleWidth - Panel.Width) / 2;
- // 'cmdNormal.Top = 2 * Space + picViewPort.Height
- // cmbLevel.Top = Tmp
- // lblRedDiskCount.Top = Tmp
- // lblInfoCount.Top = Tmp
- // picKeys.Top = Tmp
- // lblFrameCount.Top = Tmp
- // cmdPlayAll.Top = Tmp
-}
-
-#endif
-
-#if 1
-
-static void DrawFrame(int Delta)
-{
- int i, LX, tY, RX, BY;
-
- LX = -1 + Delta;
- tY = -1 + Delta;
- RX = FieldWidth - Delta;
- BY = FieldHeight - Delta;
- DrawImage(LX, tY, imgFrameCorner);
- DrawImage(LX, BY, imgFrameCorner);
- DrawImage(RX, tY, imgFrameCorner);
- DrawImage(RX, BY, imgFrameCorner);
- for (i = LX + 1; i <= RX - 1; i++)
- {
- DrawImage(i, tY, imgFrameHorizontal);
- DrawImage(i, BY, imgFrameHorizontal);
- }
-
- for (i = tY + 1; i <= BY - 1; i++)
- {
- DrawImage(LX, i, imgFrameVertical);
- DrawImage(RX, i, imgFrameVertical);
- }
-}
-
-#else
-
-static void DrawFrame(int Delta)
-{
- int i, LX, tY, RX, BY;
-
- LX = -1 + Delta;
- tY = -1 + Delta;
- RX = FieldWidth - Delta;
- BY = FieldHeight - Delta;
- DrawSprite(LX, tY, posFrameCorner);
- DrawSprite(LX, BY, posFrameCorner);
- DrawSprite(RX, tY, posFrameCorner);
- DrawSprite(RX, BY, posFrameCorner);
- for (i = LX + 1; i <= RX - 1; i++)
- {
- DrawSprite(i, tY, posFrameHorizontal);
- DrawSprite(i, BY, posFrameHorizontal);
- }
-
- for (i = tY + 1; i <= BY - 1; i++)
- {
- DrawSprite(LX, i, posFrameVertical);
- DrawSprite(RX, i, posFrameVertical);
- }
-}
-
-#endif
-
-static void RestoreFrame()
-{
- int i, LX, tY, RX, BY;
-
- LX = 0;
- tY = 0;
- RX = FieldWidth - 1;
- BY = FieldHeight - 1;
- for (i = LX; i <= RX; i++)
- {
- DrawField(i, tY);
- DrawField(i, BY);
- }
-
- for (i = tY + 1; i <= BY - 1; i++)
- {
- DrawField(LX, i);
- DrawField(RX, i);
- }
-}
-
-#if 0
-
-static void Form_Unload(int Cancel)
-{
- EndFlag = True;
- ExitToMenuFlag = 1;
- if (cmdPlayAll.STRING_IS_LIKE(Caption, "Quit*"))
- {
- cmdPlayAll_Click();
- }
-
- if (menEdit.Checked)
- menEdit_Click();
-
- if (ModifiedFlag)
- {
- char *Msg;
- VbMsgBoxResult Res;
-
- Msg = "Save changes to " & GetFileNameToSave() & " ?";
- Res = MsgBox(Msg, vbYesNoCancel, AppTitle & " - closing");
- if (Res == vbCancel)
- {
- Cancel = -1;
- return;
- }
-
- if (Res == vbYes)
- {
- if (FileExists(OrigPath) && menSave.Enabled)
- {
- menSave_Click();
- }
- else
- {
- menSaveAs_Click();
- }
- }
- }
-
- if (FileExists(TmpPath) || ModifiedFlag)
- {
- MayKill(TmpPath);
- CurPath = OrigPath;
- }
-
- ReleaseDirectDraw();
- SaveSettings();
- End;
-}
-
-static void fpsTim_Timer()
-{
- currency TickDiff;
- static int count5 = 0;
-
- count5 = count5 + 1;
- if (4 < count5)
- {
- TickDiff = T.TickDiffUS(LastTick);
- lblFps.Caption = CLng(Round((1000000 * (TimerVar - LastFrame)) / (TickDiff), 0));
- LastFrame = TimerVar;
- LastTick = T.TickNow();
- count5 = 0;
- }
-
- // If NoDisplayFlag Then lblFrameCount = TimerVar
- lblFrameCount = TimerVar;
-}
-
-static void menAbout_Click()
-{
- frmSplash.Show vbModal, Me;
-}
-
-static void menAutoScroll_Click()
-{
- {
- menAutoScroll.Checked = ! menAutoScroll.Checked;
- AutoScrollFlag = menAutoScroll.Checked;
- }
-}
-
-#endif
-
-static void menBorder_Click()
-{
- if (menBorder.Checked)
- {
- menBorder.Checked = False;
- DisplayMinX = 1;
- DisplayMaxX = FieldWidth - 2;
- DisplayWidth = FieldWidth;
- DisplayMinY = 1;
- DisplayMaxY = FieldHeight - 2;
- DisplayHeight = FieldHeight;
-
- if (Loaded && LevelLoaded)
- DrawFrame(1);
-
- }
- else
- {
- menBorder.Checked = True;
- DisplayMinX = 0;
- DisplayMaxX = FieldWidth - 1;
- DisplayWidth = FieldWidth + 2;
- DisplayMinY = 0;
- DisplayMaxY = FieldHeight - 1;
- DisplayHeight = FieldHeight + 2;
-
- if (Loaded && LevelLoaded)
- RestoreFrame();
- }
-
- ReStretch(Stretch);
- // DisplayLevel True
-}
-
-void SetDisplayRegion()
-{
- if (! menBorder.Checked)
- {
- DisplayMinX = 1;
- DisplayMaxX = FieldWidth - 2;
- DisplayWidth = FieldWidth;
- DisplayMinY = 1;
- DisplayMaxY = FieldHeight - 2;
- DisplayHeight = FieldHeight;
-
- if (LevelLoaded)
- DrawFrame(1);
-
- }
- else
- {
- DisplayMinX = 0;
- DisplayMaxX = FieldWidth - 1;
- DisplayWidth = FieldWidth + 2;
- DisplayMinY = 0;
- DisplayMaxY = FieldHeight - 1;
- DisplayHeight = FieldHeight + 2;
-
- if (LevelLoaded)
- RestoreFrame();
- }
-}
-
-#if 0
-
-static void menCopy_Click()
-{
- FMark.Copy;
-}
-
-void menEdit_Click()
-{
- long L;
-
- if (menEdit.Checked)
- {
- menEdit.Checked = False;
- // leave edit mode
- if (EditFlag)
- Unload ToolBox;
-
- EditFlag = False;
- UnEdAll();
- FMark.ShowMarker False;
- picViewPort.MousePointer = 0;
- if (ModifiedFlag)
- {
- if (! STRING_IS_LIKE(CurPath, TmpPath))
- {
- OrigPath = CurPath;
- CurPath = TmpPath;
- }
-
- SaveMPX(TmpPath);
- }
-
- DisplayLevel();
- Stage.Blt();
- }
- else
- {
- if (! LevelLoaded)
- {
- Beep();
- return;
- }
-
- if (ModifiedFlag)
- {
- if (! STRING_IS_LIKE(CurPath, TmpPath))
- {
- OrigPath = CurPath;
- CurPath = TmpPath;
- }
-
- SaveMPX(TmpPath);
- }
-
- subFetchAndInitLevel();
- menEdit.Checked = True;
- // enter edit mode
- EditFlag = True;
- // ScaleMode = vbTwips
- ToolBox.Move (Width - ToolBox.Width) / 2, Height - ToolBox.Height;
- // ScaleMode = vbPixels
- // L = GetWindowLong(ToolBox.hWnd, GWL_STYLE)
- // L = L And (Not WS_POPUP)
- // L = L Or WS_CHILD
- // SetWindowLong ToolBox.hWnd, GWL_STYLE, L
- // SetParent ToolBox.hWnd, hWnd
- ToolBox.Show vbModeless, Me;
- EdAll();
- DisplayLevel();
- Stage.Blt();
- FMark.ShowMarker True;
- }
-}
-
-static void menEnOff_Click()
-{
- menEnOn.Checked = False;
- menEnOff.Checked = True;
- SpSaveMenu();
- SpLoadMenu();
-}
-
-static void menEnOn_Click()
-{
- menEnOn.Checked = True;
- menEnOff.Checked = False;
- SpSaveMenu();
- SpLoadMenu();
-}
-
-static void menExit_Click()
-{
- Unload Me;
-}
-
-static void menFaster_Click()
-{
- int i;
-
- if (! bPlaying)
- {
- Debug.Assert(False);
- return;
- }
-
- if (DemoFlag != 0) // demoplayback
- {
- i = GetSpeedIndex(DeltaTDemo);
- i = i - 1;
- If i < 2 Then i = 2;
- menDemoSpeed_Click (i);
- }
- else
- {
- i = GetSpeedIndex(DeltaTPlay);
- i = i - 1;
- If i < 2 Then i = 2;
- menPlaySpeed_Click (i);
- }
-}
-
-static void menSlower_Click()
-{
- int i;
-
- if (! bPlaying)
- {
- Debug.Assert(False);
- return;
- }
-
- if (DemoFlag != 0) // demoplayback
- {
- i = GetSpeedIndex(DeltaTDemo);
- i = i + 1;
- If nSpeedCount < i Then i = nSpeedCount;
- menDemoSpeed_Click (i);
- }
- else
- {
- i = GetSpeedIndex(DeltaTPlay);
- i = i + 1;
- If nSpeedCount < i Then i = nSpeedCount;
- menPlaySpeed_Click (i);
- }
-}
-
-void menPlaySpeed_Click(int Index)
-{
- int i;
-
- // If NoDisplayFlag And (GameLoopRunning <> 0) Then
- // NoDisplayFlag = False
- // DisplayLevel
- // End If
- // NoDisplayFlag = False
- for (i = menPlaySpeed.LBound; i <= menPlaySpeed.UBound; i++)
- {
- {
- menPlaySpeed(i).Checked = (Index == i);
- }
- }
-
- BlockingSpeed = False;
- DeltaTPlay = SpeedsByDelayUS[Index];
- UpdateDeltaT();
- // If DeltaTPlay < 0 Then
- // Stage.Blt
- // DeltaT = 0
- // NoDisplayFlag = True
- // End If
-}
-
-void menDemoSpeed_Click(int Index)
-{
- int i;
-
- // If NoDisplayFlag And (GameLoopRunning <> 0) Then
- // NoDisplayFlag = False
- // DisplayLevel
- // End If
- NoDisplayFlag = False;
- for (i = menDemoSpeed.LBound; i <= menDemoSpeed.UBound; i++)
- {
- {
- menDemoSpeed(i).Checked = (Index == i);
- }
- }
-
- BlockingSpeed = False;
- DeltaTDemo = SpeedsByDelayUS[Index];
- UpdateDeltaT();
- // If DeltaTPlay < 0 Then
- // Stage.Blt
- // DeltaT = 0
- // NoDisplayFlag = True
- // End If
-}
-
-static void UpdateDeltaT()
-{
- if (! bPlaying)
- return;
-
- DeltaT = (DemoFlag != 0 ? DeltaTDemo : DeltaTPlay);
- if (DeltaT < 0)
- {
- Stage.Blt();
- DeltaT = 0;
- NoDisplayFlag = True;
- }
- else
- {
- if (NoDisplayFlag && GameLoopRunning != 0)
- {
- NoDisplayFlag = False;
- DisplayLevel();
- }
- else
- {
- NoDisplayFlag = False;
- }
- }
-}
-
-static void menGravOff_Click()
-{
- menGravOn.Checked = False;
- menGravOff.Checked = True;
- SpSaveMenu();
- SpLoadMenu();
-}
-
-static void menGravOn_Click()
-{
- menGravOn.Checked = True;
- menGravOff.Checked = False;
- SpSaveMenu();
- SpLoadMenu();
-}
-
-static void menNew_Click()
-{
- NewForm.Show vbModal, Me;
- CreateLevel(FieldWidth, FieldHeight);
- ReStretch(Stretch);
-}
-
-static void menNewStd_Click()
-{
- CreateLevel(60, 24);
- ReStretch(Stretch);
-}
-
-static void menOpen_Click()
-{
- long LFilt;
-
- {
- // cmDlg.DefaultExt = "sp"
-
- /*
-
- (prevent compiler warning here due to suspected use of trigraph)
-
- cmDlg.Filter = "All Levels (*.DAT;*.D??;*.sp;*.mpx)|*.DAT;*.D??;*.sp;*.mpx|MegaPlex Levels (*.mpx)|*.mpx" & "|Supaplex Level Sets (*.DAT;*.D??)|*.DAT;*.D??|SpeedFix Demos (*.sp)|*.sp";
- */
-
- LFilt = LastOpenFilter;
- cmDlg.FilterIndex = (0 < LFilt & LFilt < 5 ? LFilt : 1);
- if (FileExists(CurPath))
- cmDlg.InitDir = WithSlash(StripDir(CurPath));
-
- cmDlg.flags = cdlOFNHideReadOnly | cdlOFNLongNames;
- }
-
- // --- On Error GoTo menOpenEH
- cmDlg.ShowOpen;
- // --- On Error GoTo 0
-
- LFilt = cmDlg.FilterIndex;
- LastOpenFilter = LFilt;
- CurPath = cmDlg.FileName;
- OrigPath = CurPath;
- FillFileList (CurPath);
-
-menOpenEH:
-}
-
-static void menOptions_Click()
-{
- OptionsForm oFrm;
-
- oFrm.Show vbModal, Me;
- SaveSettings();
- picViewPort_Resize();
-}
-
-static void menPanel_Click()
-{
- {
- PanelVisible = ! menPanel.Checked;
- }
-}
-
-void Let_PanelVisible(boolean NewVal)
-{
- static boolean HidePanel = False;
-
- if (HidePanel != NewVal)
- return;
-
- HidePanel = ! NewVal;
- PanelTim.Enabled = True;
-}
-
-static void DrawPauseLayer(long Layer)
-{
- DirectDrawPalette Pal;
- PALETTEENTRY *Val;
- long i;
-
- // Dim X&, Y&
- // For Y = 0 To bmpStage.Height Step BaseWidth
- // For X = 0 To bmpStage.Width Step BaseWidth
- // Pause.TransparentDraw bmpStageHDC, X, Y, Layer
- // Next X
- // Next Y
- // With Stage.Surface
- // Set Pal = .GetPalette
- // for i=1 to pal.GetEntries(
- // Stage.Surface.SetPalette
-}
-
-static void menPaste_Click()
-{
- FMark.Paste;
- DisplayLevel();
- Stage.Blt();
-}
-
-static void menPause_Click()
-{
- static StdPicture OldPic;
- static char *OldText = 0;
-
- PauseMode = (PauseMode != 0 ? 0 : 1);
- if (PauseMode != 0)
- {
- if (IS_NOTHING(&OldPic, sizeof(OldPic)))
- OldPic = cmdPause.Picture;
-
- cmdPause.Picture = cmdPause.DownPicture;
- OldText = lblStatus.Caption;
- lblStatus = "Paused ...";
- }
- else
- {
- cmdPause.Picture = OldPic;
- lblStatus.Caption = OldText;
- }
-}
-
-static void menPlayAll_Click()
-{
- long iMin, iMax, i;
- int FNum;
- char *LogPath, *OutStr, *ReRecPath, *SPPath;
- boolean bEqual;
- static boolean QuitFlag = False;
-
- if (cmdPlayAll.STRING_IS_LIKE(Caption, "Play) All Demos")
- {
- cmdPlayAll.Caption = "Quit All";
- menPlayAll.Caption = "Quit All";
- FocusTim.Enabled = True;
- QuitFlag = False;
- iMin = 0;
- iMax = cmbFile.ListCount - 1;
- LogPath = StripDir(CurPath) & "/Error.Log";
- if (Dir(LogPath) != "")
- Kill(LogPath);
-
- for (i = iMin; i <= iMax; i++)
- {
- cmbFile.ListIndex = i;
- // If CurPath Like "*.sp" Or CurPath Like "*.mpx" Then
- if (DemoAvailable)
- {
- SPPath = CurPath;
- ReRecPath = SPPath & ".ReRec";
- menPlayDemo_Click();
- // SaveSP ReRecPath
- // bEqual = FilesEqual(ReRecPath, SPPath)
- // If bEqual Then MayKill ReRecPath
- bEqual = True;
- OutStr = cmbFile.List(i) & " -> ";
- //
- if (Val(lblFrameCount) != GetTotalFramesOfDemo())
- {
- OutStr = OutStr & "Error in GetTotalFramesOfDemo()! ";
- Debug.Assert(False);
- }
-
- //
- if ((LevelStatus == 1) && bEqual)
- {
- OutStr = OutStr & "Success";
- }
- else if (QuitFlag)
- {
- OutStr = OutStr & "All Demos (float)Canceled";
- }
- else
- {
- if (LevelStatus != 1)
- {
- OutStr = OutStr & "### Level Failed ### (TimerVar == " & TimerVar & ")";
- }
-
- if (! bEqual)
- {
- OutStr = OutStr & "### ReRecording is binary different ###";
- }
- }
-
- FNum = FreeFile();
- FNum = fopen(LogPath, "ab");
- Print #FNum, OutStr;
- fclose(FNum);
- if (QuitFlag)
- break;
- }
- }
-
- cmdPlayAll.Caption = "Play All Demos";
- menPlayAll.Caption = "Play All Demos";
- SettingsObject Settings;
-
- MySignature = Settings.Read("MySignature", "");
- FirstDemoByte = 0x81;
- }
- else
- {
- QuitFlag = True;
- if (menStop.Enabled)
- menStop_Click();
- }
-}
-
-static void menRemSP_Click()
-{
- RemoveSP();
- SpLoadMenu();
-}
-
-static void menRestoreBorder_Click()
-{
- RestoreBorder();
-}
-
-static void menSave_Click()
-{
- if (! ModifiedFlag)
- return;
-
- if (STRING_IS_LIKE(CurPath, TmpPath))
- CurPath = OrigPath;
-
- if (STRING_IS_LIKE(CurPath, "") || STRING_IS_LIKE(CurPath, "*.dat"))
- {
- menSaveAs_Click();
- return;
- }
-
- if (STRING_IS_LIKE(CurPath, "*.sp"))
- {
- menSaveAs_Click();
- return;
- }
-
- if (! FileExists(CurPath) || STRING_IS_LIKE(CurPath, "Untitled"))
- {
- menSaveAs_Click();
- return;
- }
-
- SaveMPX(CurPath);
- Let_ModifiedFlag(False);
-}
-
-static void menSaveAs_Click()
-{
- if (SaveAs())
- FillFileList (CurPath);
-}
-
-static boolean SaveAs()
-{
- static boolean SaveAs;
-
- char *FN;
- SettingsObject s;
-
- SaveAs = False;
- {
- // cmDlg.DefaultExt = "sp"
- cmDlg.Filter = "MegaPlex Level (*.mpx)|*.mpx|SpeedFix Demo (*.sp)|*.sp";
- cmDlg.FilterIndex = LastSaveFilter;
- // If OrigPath Like "*.sp" Then cmDlg.FilterIndex = 1 Else cmDlg.FilterIndex = 0
- if (FileExists(OrigPath))
- {
- cmDlg.InitDir = WithSlash(StripDir(OrigPath));
- cmDlg.InitDir = s.Read("LastSaveDir", cmDlg.InitDir);
- cmDlg.FileName = StripExtensionlessFileName(GetFileNameToSave());
- }
-
- cmDlg.flags = cdlOFNHideReadOnly | cdlOFNLongNames;
- }
-
- // --- On Error GoTo SaveAsEH
- cmDlg.ShowSave;
- // --- On Error GoTo 0
-
- LastSaveFilter = cmDlg.FilterIndex;
- FN = cmDlg.FileName;
- SettingsObject_Save("LastSaveDir", WithSlash(StripDir(FN)));
- if (STRING_IS_LIKE(FN, "*.sp"))
- {
- SaveSP(FN);
- }
- else if (STRING_IS_LIKE(FN, "*.mpx"))
- {
- SaveMPX(FN);
- }
-
- Let_ModifiedFlag(False);
- SaveAs = True;
-
-SaveAsEH:
-
- return SaveAs;
-}
-
-static void menSelectAll_Click()
-{
- FMark.SetPoint1 0, 0;
- FMark.SetPoint2 FieldWidth - 1, FieldHeight - 1;
-}
-
-static void menShowLInfo_Click()
-{
- char *Msg;
-
- Msg = LInfo.LevelTitle & vbNewLine & "(" & FieldWidth & " x " & FieldHeight & ")";
- if (DemoAvailable && bSignatureAvailable)
- Msg = Msg & vbNewLine & vbNewLine & gSignature;
-
- SignatureForm.Signature = Msg;
- SignatureForm.DelayMS = 5000;
- int X, Y;
-
- X = left + (Width - SignatureForm.Width) / 2;
- Y = top + (Height - SignatureForm.Height) / 2;
- SignatureForm.Move X, Y;
- SignatureForm.Show vbModeless, Me;
- Me.SetFocus;
-}
-
-static void menSoundFX_Click()
-{
- {
- menSoundFX.Checked = ! menSoundFX.Checked;
- FXOnFlag = (menSoundFX.Checked ? -1 : 0);
- }
-}
-
-#endif
-
-// static void menPlay_Click()
-void menPlay_Click()
-{
-#if 0
-
- boolean OldEditFlag;
-
- // Trace "MainForm", "--> menPlay_Click()"
- if (! LevelLoaded)
- {
- Beep();
- return;
- }
-
- SignatureForm.DelayMS = 1;
- menPlay.Enabled = False;
- menPause.Enabled = True;
- menStop.Enabled = True;
- cmdPlay.Enabled = False;
- cmdPause.Enabled = True;
- cmdStop.Enabled = True;
- cmdPlayDemo.Enabled = False;
- menPlayDemo.Enabled = False;
- cmdRecordDemo.Enabled = False;
- menRec.Enabled = False;
- menFaster.Enabled = True;
- menSlower.Enabled = True;
- if (cmdPlayAll.STRING_IS_LIKE(Caption, "Play*"))
- {
- cmdPlayAll.Enabled = False;
- menPlayAll.Enabled = False;
- }
-
- cmbFile.Enabled = False;
- cmbLevel.Enabled = False;
- OldEditFlag = EditFlag;
- if (EditFlag)
- menEdit_Click();
-
- menEditMain.Enabled = False;
- if (DemoFlag == 0 && RecordDemoFlag == 0)
- lblStatus = "Playing";
-
- lblFrameCount = 0;
-
-#endif
-
- LastFrame = 0;
-
-#if 0
- LastTick = T.TickNow();
-#endif
-
-#if 0
- fpsTim.Enabled = True;
-#endif
-
- // DimPrimary 100
- bPlaying = True;
-
-#if 0
- UpdateDeltaT();
-#endif
-
-#if 1
-#endif
-
-#if 0
- printf("::: MainForm.c: menPlay_Click(): subFetchAndInitLevelB(): ...\n");
-#endif
-
- subFetchAndInitLevelB();
-
-#if 0
- printf("::: MainForm.c: menPlay_Click(): subFetchAndInitLevelB(): done\n");
-#endif
-
- ReStretch(Stretch);
-
- // Trace "MainForm", "CountDown 1"
- CountDown(2, (0 == DemoFlag));
- // Trace "MainForm", "Call GoPlay"
-
- GoPlay();
-
- // Trace "MainForm", "GoPlay returned"
-
-#if 0
-
- if (LevelStatus == 1)
- {
- lblStatus = "(float)Success";
- }
- else
- {
- lblStatus = "Try (float)again";
- }
-
-#endif
-
- // Trace "MainForm", "CountDown 1"
- CountDown(1, False);
- RecordDemoFlag = 0;
-
-#if 0
- ShowKey(0);
-#endif
-
- bPlaying = False;
- // Trace "MainForm", "Call subFetchAndInitLevel"
-
- subFetchAndInitLevel();
-
- // Trace "MainForm", "subFetchAndInitLevel returned"
-
-#if 0
- Stage.Blt();
-#endif
-
-#if 0
-
- menEditMain.Enabled = True;
- if (OldEditFlag)
- menEdit_Click();
-
- // Trace "MainForm", "<-- menPlay_Click()"
-
-#endif
-}
-
-#if 1
-
-// static void menPlayDemo_Click()
-void menPlayDemo_Click()
-{
- DemoFlag = 1;
- RecordDemoFlag = 0;
-
-#if 0
- lblStatus = "Demo Playback";
-#endif
-
- menPlay_Click();
-
-#if 1
- return; /* return after initialization phase */
-#endif
-
-#if 0
- if (LevelStatus != 1)
- lblStatus = "Demo Failed";
-#endif
-
- DemoFlag = 0;
-}
-
-#else
-
-// static void menPlayDemo_Click()
-void menPlayDemo_Click()
-{
- DemoFlag = 1;
- RecordDemoFlag = 0;
-
-#if 0
- lblStatus = "Demo Playback";
-#endif
-
- menPlay_Click();
-
-#if 0
- if (LevelStatus != 1)
- lblStatus = "Demo Failed";
-#endif
-
- DemoFlag = 0;
-}
-
-#endif
-
-#if 0
-
-static void menRec_Click()
-{
- Trace("MainForm", "--> menRec_Click()");
- if (! LevelLoaded)
- {
- Beep();
- return;
- }
-
- RecordDemoFlag = 1;
- DemoFlag = 0;
- lblStatus.ForeColor = vbRed;
- lblStatus = "Recording Demo";
- // DemoBuffer = New DemoBufferObject; // (handle this later, if needed)
- Debug.Assert(! IS_NOTHING(&DemoBuffer, sizeof(DemoBuffer)));
- Trace("MainForm", "Call menPlayClick");
- menPlay_Click();
- Trace("MainForm", "menPlayClick returned");
-
- lblStatus.ForeColor = vbButtonText;
- RecordDemoFlag = 0;
- Let_ModifiedFlag(True);
- if (! STRING_IS_LIKE(CurPath, TmpPath))
- {
- OrigPath = CurPath;
- CurPath = TmpPath;
- }
-
- LInfo.DemoRandomSeed = RecDemoRandomSeed;
- Trace("MainForm", "Call SaveMPX(TmpPath)");
- SaveMPX(TmpPath);
- Trace("MainForm", "Set DemoBuffer == Nothing");
- SET_TO_NOTHING(&DemoBuffer, sizeof(DemoBuffer));
- Trace("MainForm", "Call subFetchAndInitLevel");
- subFetchAndInitLevel();
- cmdPlayDemo.Enabled = DemoAvailable;
- Trace("MainForm", "<-- menRec_Click()");
-}
-
-static void menReRecordDemo_Click()
-{
- if (! LevelLoaded)
- {
- Beep();
- return;
- }
-
- RecordDemoFlag = 1;
- DemoFlag = 1;
- lblStatus.ForeColor = vbRed;
- lblStatus = "ReRecording Demo";
- // DemoBuffer = New DemoBufferObject; // (handle this later, if needed)
- Debug.Assert(! IS_NOTHING(&DemoBuffer, sizeof(DemoBuffer)));
- menPlay_Click();
- lblStatus.ForeColor = vbButtonText;
- RecordDemoFlag = 0;
- Let_ModifiedFlag(True);
- if (! STRING_IS_LIKE(CurPath, TmpPath))
- {
- OrigPath = CurPath;
- CurPath = TmpPath;
- }
-
- LInfo.DemoRandomSeed = RecDemoRandomSeed;
- SaveMPX(TmpPath);
- SET_TO_NOTHING(&DemoBuffer, sizeof(DemoBuffer));
- subFetchAndInitLevel();
-}
-
-void menStop_Click()
-{
- EndFlag = True;
- LeadOutCounter = 1;
- if (PauseMode != 0)
- menPause_Click();
-
- fpsTim.Enabled = False;
- fpsTim_Timer();
- lblFps.Caption = "";
- menRec.Enabled = True;
- menPlay.Enabled = True;
- menPause.Enabled = False;
- menStop.Enabled = False;
- cmdPlay.Enabled = True;
- cmdPause.Enabled = False;
- cmdStop.Enabled = False;
- cmdRecordDemo.Enabled = True;
- cmdPlayDemo.Enabled = DemoAvailable;
- cmdPlayAll.Enabled = DemosAvailable;
- menPlayDemo.Enabled = DemoAvailable;
- menPlayAll.Enabled = DemosAvailable;
- menFaster.Enabled = False;
- menSlower.Enabled = False;
- cmbFile.Enabled = True;
- cmbLevel.Enabled = True;
-}
-
-static void menStretch_Click(int Index)
-{
- ReStretch(0.25 * Index);
- // DisplayLevel True
-}
-
-static void menToolTips_Click()
-{
- {
- menToolTips.Checked = ! menToolTips.Checked;
- if (menToolTips.Checked)
- {
- cmdPlay.ToolTipText = "Play Game (Space)";
- cmdPause.ToolTipText = "Pause (P)";
- cmdStop.ToolTipText = "Stop (Q)";
- cmdPlayDemo.ToolTipText = "Play demo (Ctrl+Space)";
- cmdRecordDemo.ToolTipText = "Record demo (Ctrl+R)";
- lblInfoCount.ToolTipText = "Number of infotrons needed";
- lblRedDiskCount.ToolTipText = "Number of red disks";
- cmbLevel.ToolTipText = "List of all levels in the file";
- cmbFile.ToolTipText = "List of files in current directory";
- lblFps.ToolTipText = "Animation speed in fps";
- lblFrameCount.ToolTipText = "Game time in frames";
- }
- else
- {
- cmdPlay.ToolTipText = "";
- cmdPause.ToolTipText = "";
- cmdStop.ToolTipText = "";
- cmdPlayDemo.ToolTipText = "";
- cmdRecordDemo.ToolTipText = "";
- lblInfoCount.ToolTipText = "";
- lblRedDiskCount.ToolTipText = "";
- cmbLevel.ToolTipText = "";
- cmbFile.ToolTipText = "";
- lblFps.ToolTipText = "";
- lblFrameCount.ToolTipText = "";
- }
-
- }
-}
-
-static void menTrim_Click()
-{
- LevelInfoType Tmp;
- char *OldOPath;
-
- OldOPath = OrigPath;
- Tmp = LInfo;
- Tmp.SpecialPortCount = 0; // hack: all special ports are deleted
- menCopy_Click();
- CreateLevel(FMark.Width, FMark.Height);
- LInfo = Tmp;
- OrigPath = OldOPath;
- CurPath = OldOPath;
- menSelectAll_Click();
- menPaste_Click();
- picViewPort_Resize();
-}
-
-static void menZonkOff_Click()
-{
- menZonkOn.Checked = False;
- menZonkOff.Checked = True;
- SpSaveMenu();
- SpLoadMenu();
-}
-
-static void menZonkOn_Click()
-{
- menZonkOn.Checked = True;
- menZonkOff.Checked = False;
- SpSaveMenu();
- SpLoadMenu();
-}
-
-static void PanelTim_Timer()
-{
- int Tmp;
-
- Tmp = Panel.Height;
- if (PanelSeq < Panel.Height && -1 < PanelSeq)
- {
- PanelSeq = (ShowPanel != 0 ? PanelSeq + 2 : PanelSeq - 2);
- Tmp = ScaleHeight - Tmp + PanelSeq;
- Panel.top = Tmp;
- picViewPort.Height = Tmp;
- }
- else
- {
- PanelTim.Enabled = False;
- PanelSeq = (PanelSeq < 0 ? 0 : PanelSeq - );
- ShowPanel = (ShowPanel == 0 ? 1 : 0);
- menPanel.Checked = (ShowPanel != 0);
- }
-}
-
-static void picKeys_MouseUp(int Button, int Shift, float X, float Y)
-{
- FocusTim.Enabled = True;
-}
-
-static void picMenu_Click()
-{
-}
-
-static void picPane_KeyDown(int KeyCode, int Shift)
-{
- if (KeyCode < 0 || 255 < KeyCode)
- return;
-
- KeyState[KeyCode] = True;
- switch (KeyCode)
- {
- case vbKeyControl:
- if (MouseButton == 0 && EditFlag)
- picPane.MousePointer = 15;
-
- break;
-
- case vbKeyUp:
- case vbKeyLeft:
- case vbKeyDown:
- case vbKeyRight:
- case vbKeySpace:
- if (DemoFlag != 0)
- {
- DemoFlag = 0;
- UpdateDeltaT();
- }
-
- break;
-
- case vbKeyF12:
- if (DemoFlag != 0 && 2 == Shift)
- {
- DemoFlag = 0;
- UpdateDeltaT();
- }
-
- break;
-
- case vbKeyF11:
- bCapturePane = ! bCapturePane;
- break;
- }
-}
-
-static void picPane_KeyUp(int KeyCode, int Shift)
-{
- if (KeyCode < 0 || 255 < KeyCode)
- return;
-
- KeyState[KeyCode] = False;
- switch (KeyCode)
- {
- case vbKeyPageUp:
- if (menFaster.Enabled)
- menFaster_Click();
-
- break;
-
- case vbKeyPageDown:
- if (menSlower.Enabled)
- menSlower_Click();
-
- break;
-
- case vbKeySpace:
- if (2 == Shift) // ctrl+space
- {
- if (menPlayDemo.Enabled)
- menPlayDemo_Click();
-
- }
- else
- {
- if (menPlay.Enabled)
- menPlay_Click();
- }
-
- break;
-
- case vbKeyQ:
- if (menStop.Enabled)
- menStop_Click();
-
- break;
-
- case vbKeyR:
- if (menRec.Enabled)
- menRec_Click();
-
- break;
-
- case vbKeyP:
- case vbKeyPause:
- if (menPause.Enabled && (Shift == 0))
- menPause_Click();