DEADSOFTWARE

Holmes UI fixes
[d2df-sdl.git] / src / game / g_holmes.pas
index b86827c92fc3fd7db1b2bc99d56e23eb5a85f0c4..0fb34c00c47a220fc175ebc1bc1b40ebcdb0c46f 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}
@@ -118,6 +121,7 @@ var
 // ////////////////////////////////////////////////////////////////////////// //
 var
   g_ol_nice: Boolean = false;
+  g_ol_fill_walls: Boolean = false;
   g_ol_rlayer_back: Boolean = false;
   g_ol_rlayer_step: Boolean = false;
   g_ol_rlayer_wall: Boolean = false;
@@ -145,6 +149,9 @@ begin
   llb.appendItem('monster info', @showMonsInfo);
   llb.appendItem('monster LOS to player', @showMonsLOS2Plr);
   llb.appendItem('monster cells (SLOW!)', @showAllMonsCells);
+  llb.appendItem('WINDOWS', nil);
+  llb.appendItem('layers window', @showLayersWindow);
+  llb.appendItem('outline window', @showOutlineWindow);
   winOptions := THTopWindow.Create('Holmes Options', 100, 100);
   winOptions.escClose := true;
   winOptions.appendChild(llb);
@@ -183,8 +190,9 @@ begin
   llb.appendItem('acid2', @g_ol_rlayer_acid2);
   llb.appendItem('water', @g_ol_rlayer_water);
   llb.appendItem('foreground', @g_ol_rlayer_fore);
-  llb.appendItem('', nil);
-  llb.appendItem('slow''n''nice', @g_ol_nice);
+  llb.appendItem('OPTIONS', nil);
+  llb.appendItem('fill walls', @g_ol_fill_walls);
+  llb.appendItem('contours', @g_ol_nice);
   winOutlines := THTopWindow.Create('outlines', 100, 10);
   winOutlines.escClose := true;
   winOutlines.appendChild(llb);
@@ -194,7 +202,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;
@@ -317,6 +325,9 @@ var
 
 
 procedure drawOutlines ();
+var
+  r, g, b: Integer;
+
   procedure clearEdgeBmp ();
   begin
     SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
@@ -328,21 +339,22 @@ procedure drawOutlines ();
     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
+    if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) then exit;
+    if (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
+    if g_ol_nice or g_ol_fill_walls then
     begin
       sx := pan.X-(vpx-1);
       len := pan.Width;
-      if (len > vpw+2) then len := vpw+2;
+      if (len > gWinSizeX+4) then len := gWinSizeX+4;
       if (sx < 0) then begin len += sx; sx := 0; end;
-      if (sx+len > vpw+2) then len := vpw+2-sx;
+      if (sx+len > gWinSizeX+4) then len := gWinSizeX+4-sx;
       if (len < 1) then exit;
       assert(sx >= 0);
-      assert(sx+len <= vpw+2);
+      assert(sx+len <= gWinSizeX+4);
       y0 := pan.Y-(vpy-1);
       y1 := y0+pan.Height;
       if (y0 < 0) then y0 := 0;
-      if (y1 > vph+2) then y1 := vph+2;
+      if (y1 > gWinSizeY+4) then y1 := gWinSizeY+4;
       while (y0 < y1) do
       begin
         FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
@@ -351,10 +363,51 @@ procedure drawOutlines ();
     end
     else
     begin
-      drawRect(pan.X, pan.Y, pan.Width, pan.Height, 255, 255, 255);
+      drawRect(pan.X, pan.Y, pan.Width, pan.Height, r, g, b);
     end;
   end;
 
+var
+  lsx: Integer = -1;
+  lex: Integer = -1;
+  lsy: Integer = -1;
+
+  procedure flushLine ();
+  begin
+    if (lsy > 0) and (lsx > 0) then
+    begin
+      if (lex = lsx) then
+      begin
+        glBegin(GL_POINTS);
+          glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
+        glEnd();
+      end
+      else
+      begin
+        glBegin(GL_LINES);
+          glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
+          glVertex2f(lex-0+vpx+0.37, lsy-1+vpy+0.37);
+        glEnd();
+      end;
+    end;
+    lsx := -1;
+    lex := -1;
+  end;
+
+  procedure startLine (y: Integer);
+  begin
+    flushLine();
+    lsy := y;
+  end;
+
+  procedure putPixel (x: Integer);
+  begin
+    if (x < 1) then exit;
+    if (lex+1 <> x) then flushLine();
+    if (lsx < 0) then lsx := x;
+    lex := x;
+  end;
+
   procedure drawEdges ();
   var
     x, y: Integer;
@@ -366,11 +419,11 @@ procedure drawOutlines ();
     glPointSize(1);
     glDisable(GL_LINE_SMOOTH);
     glDisable(GL_POLYGON_SMOOTH);
-    glColor4f(1.0, 1.0, 1.0, 1.0);
-    glBegin(GL_POINTS);
+    glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
     for y := 1 to vph do
     begin
       a := @edgeBmp[y*(gWinSizeX+4)+1];
+      startLine(y);
       for x := 1 to vpw do
       begin
         if (a[0] <> 0) then
@@ -379,21 +432,49 @@ procedure drawOutlines ();
              (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
-            glVertex2i(x-1+vpx, y-1+vpy);
+            putPixel(x);
           end;
         end;
         Inc(a);
       end;
+      flushLine();
     end;
-    glEnd();
   end;
 
-  procedure doWalls (parr: array of TPanel; ptype: Word);
+  procedure drawFilledWalls ();
+  var
+    x, y: Integer;
+    a: PByte;
+  begin
+    glDisable(GL_BLEND);
+    glDisable(GL_TEXTURE_2D);
+    glLineWidth(1);
+    glPointSize(1);
+    glDisable(GL_LINE_SMOOTH);
+    glDisable(GL_POLYGON_SMOOTH);
+    glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
+    for y := 1 to vph do
+    begin
+      a := @edgeBmp[y*(gWinSizeX+4)+1];
+      startLine(y);
+      for x := 1 to vpw do
+      begin
+        if (a[0] <> 0) then putPixel(x);
+        Inc(a);
+      end;
+      flushLine();
+    end;
+  end;
+
+  procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
   var
     f: Integer;
     pan: TPanel;
   begin
-    if g_ol_nice then clearEdgeBmp();
+    r := ar;
+    g := ag;
+    b := ab;
+    if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
     for f := 0 to High(parr) do
     begin
       pan := parr[f];
@@ -402,18 +483,43 @@ procedure drawOutlines ();
       drawPanel(pan);
     end;
     if g_ol_nice then drawEdges();
+    if g_ol_fill_walls then drawFilledWalls();
+  end;
+
+var
+  xptag: Word;
+
+  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;
+    if ((pan.PanelType and xptag) = 0) then exit;
+    drawPanel(pan);
+  end;
+
+  procedure doWalls (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
+  begin
+    r := ar;
+    g := ag;
+    b := ab;
+    xptag := ptype;
+    if ((ptype and (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) <> 0) then ptype := GridTagWall or GridTagDoor
+    else panelTypeToTag(ptype);
+    if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
+    mapGrid.forEachInAABB(vpx-1, vpy-1, vpw+2, vph+2, doWallCB, ptype);
+    if g_ol_nice then drawEdges();
+    if g_ol_fill_walls then drawFilledWalls();
   end;
 
 begin
-  //function forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1; allowDisabled: Boolean=false): ITP;
-  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);
+  if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
+  if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
+  if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
+  if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
+  if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
+  if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
+  if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
+  if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
 end;
 
 
@@ -715,16 +821,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
@@ -767,6 +871,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);