DEADSOFTWARE

Holmes cosmetix
[d2df-sdl.git] / src / game / g_holmes.pas
index 98c458c7619d1e33d06c594789aa10ae4f25db73..1f68911b260c4c44994f6b1b982779dcec03a057 100644 (file)
@@ -108,7 +108,10 @@ var
   showMonsLOS2Plr: Boolean = false;
   showAllMonsCells: Boolean = false;
   showMapCurPos: Boolean = false;
-
+  showLayersWindow: Boolean = false;
+  showOutlineWindow: Boolean = false;
+  oldShowLayersWindow: Boolean = false;
+  oldShowOutlineWindow: Boolean = false;
 
 // ////////////////////////////////////////////////////////////////////////// //
 {$INCLUDE g_holmes.inc}
@@ -145,6 +148,9 @@ begin
   llb.appendItem('monster info', @showMonsInfo);
   llb.appendItem('monster LOS to player', @showMonsLOS2Plr);
   llb.appendItem('monster cells (SLOW!)', @showAllMonsCells);
+  llb.appendItem('', nil);
+  llb.appendItem('layers window', @showLayersWindow);
+  llb.appendItem('outline window', @showOutlineWindow);
   winOptions := THTopWindow.Create('Holmes Options', 100, 100);
   winOptions.escClose := true;
   winOptions.appendChild(llb);
@@ -194,7 +200,7 @@ end;
 // ////////////////////////////////////////////////////////////////////////// //
 procedure g_Holmes_VidModeChanged ();
 begin
-  e_WriteLog(Format('Inspector: videomode changed: %dx%d', [gScreenWidth, gScreenHeight]), MSG_NOTIFY);
+  e_WriteLog(Format('Holmes: videomode changed: %dx%d', [gScreenWidth, gScreenHeight]), MSG_NOTIFY);
   // texture space is possibly lost here, idc
   curtexid := 0;
   font6texid := 0;
@@ -312,30 +318,130 @@ begin
 end;
 
 
-procedure plrDebugDraw ();
+var
+  edgeBmp: array of Byte = nil;
 
-  procedure drawTileGrid ();
+
+procedure drawOutlines ();
+  procedure clearEdgeBmp ();
+  begin
+    SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
+    FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
+  end;
+
+  procedure drawPanel (pan: TPanel);
+  var
+    sx, len, y0, y1: Integer;
+  begin
+    if (pan = nil) or (pan.Width < 1) or (pan.Height < 1) then exit;
+    if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) or (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
+    if g_ol_nice then
+    begin
+      sx := pan.X-(vpx-1);
+      len := pan.Width;
+      if (len > vpw+2) then len := vpw+2;
+      if (sx < 0) then begin len += sx; sx := 0; end;
+      if (sx+len > vpw+2) then len := vpw+2-sx;
+      if (len < 1) then exit;
+      assert(sx >= 0);
+      assert(sx+len <= vpw+2);
+      y0 := pan.Y-(vpy-1);
+      y1 := y0+pan.Height;
+      if (y0 < 0) then y0 := 0;
+      if (y1 > vph+2) then y1 := vph+2;
+      while (y0 < y1) do
+      begin
+        FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
+        Inc(y0);
+      end;
+    end
+    else
+    begin
+      drawRect(pan.X, pan.Y, pan.Width, pan.Height, 255, 255, 255);
+    end;
+  end;
+
+  procedure drawEdges ();
   var
     x, y: Integer;
+    a: PByte;
   begin
-    {
-    y := mapGrid.gridY0;
-    while (y < mapGrid.gridY0+mapGrid.gridHeight) do
+    glDisable(GL_BLEND);
+    glDisable(GL_TEXTURE_2D);
+    glLineWidth(1);
+    glPointSize(1);
+    glDisable(GL_LINE_SMOOTH);
+    glDisable(GL_POLYGON_SMOOTH);
+    glColor4f(1.0, 1.0, 1.0, 1.0);
+    glBegin(GL_POINTS);
+    for y := 1 to vph do
     begin
-      x := mapGrid.gridX0;
-      while (x < mapGrid.gridX0+mapGrid.gridWidth) do
+      a := @edgeBmp[y*(gWinSizeX+4)+1];
+      for x := 1 to vpw do
       begin
-        if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and
-           (x < vpx+vpw) and (y < vpy+vph) then
+        if (a[0] <> 0) then
         begin
-          //e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
-          drawRect(x, y, mapGrid.tileSize, mapGrid.tileSize, 96, 96, 96, 255);
+          if (a[-1] = 0) or (a[1] = 0) or (a[-(gWinSizeX+4)] = 0) or (a[gWinSizeX+4] = 0) or
+             (a[-(gWinSizeX+4)-1] = 0) or (a[-(gWinSizeX+4)+1] = 0) or
+             (a[gWinSizeX+4-1] = 0) or (a[gWinSizeX+4+1] = 0) then
+          begin
+            glVertex2f(x-1+vpx+0.37, y-1+vpy+0.37);
+          end;
         end;
-        Inc(x, mapGrid.tileSize);
+        Inc(a);
       end;
-      Inc(y, mapGrid.tileSize);
     end;
-    }
+    glEnd();
+  end;
+
+  procedure doWallsOld (parr: array of TPanel; ptype: Word);
+  var
+    f: Integer;
+    pan: TPanel;
+  begin
+    if g_ol_nice then clearEdgeBmp();
+    for f := 0 to High(parr) do
+    begin
+      pan := parr[f];
+      if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
+      if ((pan.PanelType and ptype) = 0) then continue;
+      drawPanel(pan);
+    end;
+    if g_ol_nice then drawEdges();
+  end;
+
+  function doWallCB (pan: TPanel; tag: Integer): Boolean;
+  begin
+    result := false; // don't stop
+    //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
+    drawPanel(pan);
+  end;
+
+  procedure doWalls (parr: array of TPanel; ptype: Word);
+  begin
+    if g_ol_nice then clearEdgeBmp();
+    mapGrid.forEachInAABB(vpx-1, vpy-1, vpw+2, vph+2, doWallCB, panelTypeToTag(ptype));
+    if g_ol_nice then drawEdges();
+  end;
+
+begin
+  if g_ol_rlayer_back then doWalls(gRenderBackgrounds, PANEL_BACK);
+  if g_ol_rlayer_step then doWalls(gSteps, PANEL_STEP);
+  if g_ol_rlayer_wall then doWalls(gWalls, PANEL_WALL);
+  if g_ol_rlayer_door then doWalls(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR);
+  if g_ol_rlayer_acid1 then doWalls(gAcid1, PANEL_ACID1);
+  if g_ol_rlayer_acid2 then doWalls(gAcid2, PANEL_ACID2);
+  if g_ol_rlayer_water then doWalls(gWater, PANEL_WATER);
+  if g_ol_rlayer_fore then doWalls(gRenderForegrounds, PANEL_FORE);
+end;
+
+
+procedure plrDebugDraw ();
+
+  procedure drawTileGrid ();
+  var
+    x, y: Integer;
+  begin
     for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
     begin
       drawLine(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize, 96, 96, 96, 255);
@@ -494,6 +600,7 @@ begin
   glTranslatef(-vpx, -vpy, 0);
 
   if (showGrid) then drawTileGrid();
+  drawOutlines();
 
   if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
 
@@ -627,16 +734,14 @@ begin
     if (ev.scan = SDL_SCANCODE_L) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
     begin
       result := true;
-      if (winLayers = nil) then createLayersWindow();
-      if not uiVisibleWindow(winLayers) then uiAddWindow(winLayers) else uiRemoveWindow(winLayers);
+      showLayersWindow := not showLayersWindow;
       exit;
     end;
     // C-O: toggle outlines window
     if (ev.scan = SDL_SCANCODE_O) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
     begin
       result := true;
-      if (winOutlines = nil) then createOutlinesWindow();
-      if not uiVisibleWindow(winOutlines) then uiAddWindow(winOutlines) else uiRemoveWindow(winOutlines);
+      showOutlineWindow := not showOutlineWindow;
       exit;
     end;
     // F1: toggle options window
@@ -679,6 +784,44 @@ end;
 // ////////////////////////////////////////////////////////////////////////// //
 procedure g_Holmes_Draw ();
 begin
+  if (oldShowLayersWindow <> showLayersWindow) then
+  begin
+    oldShowLayersWindow := showLayersWindow;
+    if showLayersWindow then
+    begin
+      if (winLayers = nil) then createLayersWindow();
+      uiAddWindow(winLayers);
+    end
+    else
+    begin
+      uiRemoveWindow(winLayers);
+    end;
+  end
+  else
+  begin
+    showLayersWindow := uiVisibleWindow(winLayers);
+    oldShowLayersWindow := showLayersWindow;
+  end;
+
+  if (oldShowOutlineWindow <> showOutlineWindow) then
+  begin
+    oldShowOutlineWindow := showOutlineWindow;
+    if showOutlineWindow then
+    begin
+      if (winOutlines = nil) then createOutlinesWindow();
+      uiAddWindow(winOutlines);
+    end
+    else
+    begin
+      uiRemoveWindow(winOutlines);
+    end;
+  end
+  else
+  begin
+    showOutlineWindow := uiVisibleWindow(winOutlines);
+    oldShowOutlineWindow := showOutlineWindow;
+  end;
+
   glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
   glDisable(GL_STENCIL_TEST);
   glDisable(GL_BLEND);