DEADSOFTWARE

added "r_smallmap_align_h" and "r_smallmap_align_v" cvars
[d2df-sdl.git] / src / game / g_game.pas
index 4e33cad10f28e10a42aeb2709acff3725a37abbd..5ecf971a519062e9917cd5ce0038164723bd8258 100644 (file)
@@ -22,7 +22,8 @@ uses
   SysUtils, Classes,
   MAPDEF,
   g_basic, g_player, e_graphics, g_res_downloader,
-  g_sound, g_gui, utils, md5, mempool, xprofiler;
+  g_sound, g_gui, utils, md5, mempool, xprofiler,
+  g_touch;
 
 type
   TGameSettings = record
@@ -314,6 +315,8 @@ var
   gChatSounds: Array of TChatSound;
 
   g_dbg_ignore_bounds: Boolean = false;
+  r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
+  r_smallmap_v: Integer = 0; // 0: top; 1: center; 2: bottom
 
   // move button values:
   // bits 0-1: l/r state:
@@ -351,12 +354,17 @@ function gPause (): Boolean; inline;
 implementation
 
 uses
+{$IFDEF USE_NANOGL}
+  nanoGL,
+{$ELSE}
+  GL, GLExt,
+{$ENDIF}
   e_texture, g_textures, g_main, g_window, g_menu,
   e_input, e_log, g_console, g_items, g_map, g_panel,
   g_playermodel, g_gfx, g_options, g_weapons, Math,
   g_triggers, g_monsters, e_sound, CONFIG,
   g_language, g_net,
-  ENet, e_msg, g_netmsg, g_netmaster, GL, GLExt,
+  ENet, e_msg, g_netmsg, g_netmaster,
   sfs, wadreader, g_holmes;
 
 
@@ -556,6 +564,7 @@ var
   EndingGameCounter: Byte = 0;
   MessageText: String;
   MessageTime: Word;
+  MessageLineLength: Integer = 80;
   MapList: SSArray = nil;
   MapIndex: Integer = -1;
   MegaWAD: record
@@ -1589,7 +1598,10 @@ begin
         if (not g_Game_IsClient) and
         (
           (
-            (e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE))
+            (
+              e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
+              e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN)
+            )
             and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
             and (g_ActiveWindow = nil)
           )
@@ -1685,23 +1697,25 @@ begin
       begin
         if g_ActiveWindow = nil then
         begin
-          if e_KeyPressed(gGameControls.GameControls.Chat) then
+          if e_KeyPressed(gGameControls.GameControls.Chat) or e_KeyPressed(VK_CHAT) then
             g_Console_Chat_Switch(False)
-          else if (e_KeyPressed(gGameControls.GameControls.TeamChat)) and
+          else if (e_KeyPressed(gGameControls.GameControls.TeamChat) or e_KeyPressed(VK_TEAM)) and
                   (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
             g_Console_Chat_Switch(True);
         end;
       end else
         if not gChatEnter then
           if (not e_KeyPressed(gGameControls.GameControls.Chat))
-             and (not e_KeyPressed(gGameControls.GameControls.TeamChat)) then
+             and (not e_KeyPressed(gGameControls.GameControls.TeamChat))
+             and (not e_KeyPressed(VK_CHAT))
+             and (not e_KeyPressed(VK_TEAM)) then
             gChatEnter := True;
 
 // Ñòàòèñòèêà ïî Tab:
   if gGameOn then
     IsDrawStat := (not gConsoleShow) and (not gChatShow) and
                   (gGameSettings.GameType <> GT_SINGLE) and
-                  e_KeyPressed(gGameControls.GameControls.Stat);
+                  (e_KeyPressed(gGameControls.GameControls.Stat) or e_KeyPressed(VK_STATUS));
 
 // Èãðà èäåò:
   if gGameOn and not gPause and (gState <> STATE_FOLD) then
@@ -1986,6 +2000,7 @@ begin
       e_WriteLog('Changing resolution', TMsgType.Notify);
       g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
       gResolutionChange := False;
+      g_ActiveWindow := nil;
     end;
 
   // Íóæíî ñìåíèòü ÿçûê:
@@ -2000,7 +2015,7 @@ begin
   end;
 
 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
-  if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) then
+  if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) or e_KeyPressed(VK_PRINTSCR) then
     if (GetTimer()-LastScreenShot) > 200000 div 1000 then
     begin
       g_TakeScreenShot();
@@ -2293,7 +2308,7 @@ begin
 
   g_ProcessMessages();
 
-  if e_KeyPressed(IK_TAB) then
+  if e_KeyPressed(IK_TAB) or e_KeyPressed(VK_STATUS) then
   begin
     if not gStatsPressed then
     begin
@@ -3000,7 +3015,6 @@ begin
    *     glBlendFunc(GL_DST_ALPHA, GL_ONE);
    *     draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
    *)
-
   wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
   if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
 
@@ -3330,13 +3344,47 @@ begin
   //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
   fixViewportForScale();
   //conwritefln('     (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
+
   if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
   begin
     if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
     if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
     if (sX < 0) then sX := 0;
     if (sY < 0) then sY := 0;
+
+    if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
+    if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
+  end;
+
+  //r_smallmap_h: 0: left; 1: center; 2: right
+  //r_smallmap_v: 0: top; 1: center; 2: bottom
+  // horiz small map?
+  if (gMapInfo.Width = sWidth) then
+  begin
+    sX := 0;
+  end
+  else if (gMapInfo.Width < sWidth) then
+  begin
+    case r_smallmap_h of
+      1: sX := -((sWidth-gMapInfo.Width) div 2); // center
+      2: sX := -(sWidth-gMapInfo.Width); // right
+      else sX := 0; // left
+    end;
   end;
+  // vert small map?
+  if (gMapInfo.Height = sHeight) then
+  begin
+    sY := 0;
+  end
+  else if (gMapInfo.Height < sHeight) then
+  begin
+    case r_smallmap_v of
+      1: sY := -((sHeight-gMapInfo.Height) div 2); // center
+      2: sY := -(sHeight-gMapInfo.Height); // bottom
+      else sY := 0; // top
+    end;
+  end;
+
   p.viewPortX := sX;
   p.viewPortY := sY;
   p.viewPortW := sWidth;
@@ -3750,6 +3798,8 @@ begin
   if gGameOn then drawProfilers();
 
   g_Holmes_DrawUI();
+
+  g_Touch_Draw;
 end;
 
 procedure g_Game_Quit();
@@ -3761,7 +3811,7 @@ begin
   g_PlayerModel_FreeData();
   g_Texture_DeleteAll();
   g_Frames_DeleteAll();
-  g_Menu_Free();
+  //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
 
   if NetInitDone then g_Net_Free;
 
@@ -4203,6 +4253,10 @@ begin
     gPlayer2.Name := gPlayer2Settings.Name;
   end;
 
+  g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
+  if NetForwardPorts then
+    g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
+
 // Ñòàðòóåì ñåðâåð
   if not g_Net_Host(IPAddr, Port, NetMaxClients) then
   begin
@@ -4384,7 +4438,7 @@ begin
 
     ProcessLoading(true);
 
-    if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
+    if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then
     begin
       State := 0;
       break;
@@ -6967,7 +7021,8 @@ end;
 
 procedure g_Game_Message(Msg: string; Time: Word);
 begin
-  MessageText := b_Text_Format(Msg);
+  MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
+  MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
   MessageTime := Time;
 end;
 
@@ -7541,4 +7596,7 @@ begin
 
   conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
   conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
+
+  conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
+  conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
 end.