]> granicus.if.org Git - nethack/commitdiff
(from Yitzhak)
authornethack.allison <nethack.allison>
Sun, 3 Mar 2002 16:46:40 +0000 (16:46 +0000)
committernethack.allison <nethack.allison>
Sun, 3 Mar 2002 16:46:40 +0000 (16:46 +0000)
Support for a graphical RIP.

-verified for successful source compile and display
of tombstone upon death only.

win/win32/mhmsg.h
win/win32/mhrip.c
win/win32/mhrip.h
win/win32/mswproc.c
win/win32/resource.h
win/win32/winMS.h
win/win32/winhack.c
win/win32/winhack.rc

index 135e8d9422f0e7dccc1bbaf09537fcfff5ef8e5f..e626b14dab7dd358930d7b0bc7ee86b0eb7f7939 100644 (file)
@@ -16,6 +16,7 @@
 #define MSNH_MSG_ADDMENU               106
 #define MSNH_MSG_CURSOR                        107
 #define MSNH_MSG_ENDMENU               108
+#define MSNH_MSG_DIED                  109
 
 typedef struct mswin_nhmsg_add_wnd {
   winid                  wid;
index 0ac68ec6b34d142483a16eee995f4f1c0eb37740..37099832b92d05c2e627659ed067fd4a529adec3 100644 (file)
 #include "winMS.h"
 #include "resource.h"
 #include "mhrip.h"
-#include "mhtext.h"
+#include "mhmsg.h"
+#include "mhfont.h"
 
-HWND mswin_init_RIP_window () 
-{
-       return mswin_init_text_window();
+
+PNHWinApp GetNHApp(void);
+
+typedef struct mswin_nethack_text_window {
+       HANDLE  rip_bmp;
+       TCHAR*  window_text;
+       TCHAR*  rip_text;
+} NHRIPWindow, *PNHRIPWindow;
+
+static WNDPROC  editControlWndProc = 0;
+
+BOOL   CALLBACK        NHRIPWndProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK       NHEditHookWndProc(HWND, UINT, WPARAM, LPARAM);
+static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
+static void LayoutText(HWND hwnd);
+
+HWND mswin_init_RIP_window () {
+       HWND ret;
+       PNHRIPWindow data;
+
+       ret = CreateDialog(
+                       GetNHApp()->hApp,
+                       MAKEINTRESOURCE(IDD_NHRIP),
+                       GetNHApp()->hMainWnd,
+                       NHRIPWndProc
+       );
+       if( !ret ) panic("Cannot create rip window");
+
+       data = (PNHRIPWindow)malloc(sizeof(NHRIPWindow));
+       if( !data ) panic("out of memory");
+
+       ZeroMemory(data, sizeof(NHRIPWindow));
+       SetWindowLong(ret, GWL_USERDATA, (LONG)data);
+       return ret;
 }
 
 void mswin_display_RIP_window (HWND hWnd)
 {
-       mswin_display_text_window (hWnd);
+       MSG msg;
+       RECT rt;
+       PNHRIPWindow data;
+       HWND mapWnd;
+       RECT riprt;
+       SIZE bmpDims;
+       RECT clientrect;
+       RECT textrect;
+       HDC hdc;
+
+       data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);
+
+       GetNHApp()->hPopupWnd = hWnd;
+       mapWnd = mswin_hwnd_from_winid(WIN_MAP);
+       if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd;
+       GetWindowRect(mapWnd, &rt);
+       GetWindowRect(hWnd, &riprt);
+       GetClientRect (hWnd, &clientrect);
+       textrect = clientrect;
+       textrect.top += 10;
+       textrect.left += 10;
+       textrect.right -= 10;
+       if (data->window_text)
+       {
+           hdc = GetDC (hWnd);
+           DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
+               DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
+           ReleaseDC(hWnd, hdc);
+       }
+       bmpDims.cx = 400;
+       bmpDims.cy = 200;
+       if (textrect.right - textrect.left > bmpDims.cx)
+           clientrect.right = textrect.right + 10 - clientrect.right;
+       else
+           clientrect.right = textrect.left + 20 + bmpDims.cx - clientrect.right;
+       clientrect.bottom = textrect.bottom + bmpDims.cy + 10 - clientrect.bottom;
+       GetWindowRect (GetDlgItem(hWnd, IDOK), &textrect);
+       textrect.right -= textrect.left;
+       textrect.bottom -= textrect.top;
+       clientrect.bottom += textrect.bottom + 10;
+       riprt.right -= riprt.left;
+       riprt.bottom -= riprt.top;
+       riprt.right += clientrect.right;
+       riprt.bottom += clientrect.bottom;
+       rt.left += (rt.right - rt.left - riprt.right) / 2;
+       rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;
+
+       MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
+       GetClientRect (hWnd, &clientrect);
+       MoveWindow (GetDlgItem(hWnd, IDOK),
+           (clientrect.right - clientrect.left - textrect.right) / 2,
+           clientrect.bottom - textrect.bottom - 10, textrect.right, textrect.bottom, TRUE);
+       ShowWindow(hWnd, SW_SHOW);
+
+       while( IsWindow(hWnd) &&
+                  GetMessage(&msg, NULL, 0, 0)!=0 ) {
+               if( !IsDialogMessage(hWnd, &msg) ) {
+                       if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) {
+                               TranslateMessage(&msg);
+                               DispatchMessage(&msg);
+                       }
+               }
+       }
+
+       GetNHApp()->hPopupWnd = NULL;
+}
+
+BOOL CALLBACK NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+       HDC hdc;
+       PNHRIPWindow data;
+
+       data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);
+       switch (message)
+       {
+       case WM_INITDIALOG:
+           /* set text control font */
+               hdc = GetDC(hWnd);
+               SendMessage(hWnd, WM_SETFONT,
+                       (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
+               ReleaseDC(hWnd, hdc);
+
+               SetFocus(GetDlgItem(hWnd, IDOK));
+       return FALSE;
+
+       case WM_MSNH_COMMAND:
+               onMSNHCommand(hWnd, wParam, lParam);
+       break;
+
+       case WM_PAINT:
+       {
+               SIZE bmpDims;
+               int bitmap_offset;
+               RECT clientrect;
+               RECT textrect;
+               HDC hdcBitmap;
+               HANDLE OldBitmap;
+               hdc = GetDC (hWnd);
+               hdcBitmap = CreateCompatibleDC(hdc);
+               SetBkMode (hdc, TRANSPARENT);
+               GetClientRect (hWnd, &clientrect);
+               textrect = clientrect;
+               textrect.top += 10;
+               textrect.left += 10;
+               textrect.right -= 10;
+               if (data->window_text)
+               {
+                       DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
+                               DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
+                       DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
+                               DT_LEFT | DT_NOPREFIX);
+               }
+               OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
+               SetBkMode (hdc, OPAQUE);
+               bmpDims.cx = 400;
+               bmpDims.cy = 200;
+               bitmap_offset = (textrect.right - textrect.left - bmpDims.cx) / 2;
+               BitBlt (hdc, textrect.left + bitmap_offset, textrect.bottom, bmpDims.cx,
+                       bmpDims.cy, hdcBitmap, 0, 0, SRCCOPY);
+               SetBkMode (hdc, TRANSPARENT);
+               if (data->rip_text)
+               {
+                       textrect.left += 90 + bitmap_offset;
+                       textrect.top = textrect.bottom + 60;
+                       textrect.right = textrect.left + 115;
+                       textrect.bottom = textrect.top + 120;
+                       DrawText (hdc, data->rip_text, strlen(data->rip_text), &textrect,
+                               DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
+               }
+               SelectObject (hdcBitmap, OldBitmap);
+               DeleteDC (hdcBitmap);
+               ReleaseDC(hWnd, hdc);
+       }
+       break;
+
+       case WM_COMMAND:
+               switch (LOWORD(wParam))
+        {
+          case IDOK:
+                 case IDCANCEL:
+                       mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
+                       if( GetNHApp()->hMainWnd==hWnd )
+                               GetNHApp()->hMainWnd=NULL;
+                       DestroyWindow(hWnd);
+                       SetFocus(GetNHApp()->hMainWnd);
+                       return TRUE;
+               }
+       break;
+
+       case WM_DESTROY:
+               if( data ) {
+                       if( data->window_text ) free(data->window_text);
+                       if( data->rip_text ) free(data->rip_text);
+                       if (data->rip_bmp != NULL) DeleteObject(data->rip_bmp);
+                       free(data);
+                       SetWindowLong(hWnd, GWL_USERDATA, (LONG)0);
+               }
+       break;
+
+       }
+       return FALSE;
+}
+
+void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
+{
+       PNHRIPWindow data;
+       static int InRipText = 1;
+       data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);
+       switch( wParam ) {
+               case MSNH_MSG_PUTSTR: {
+                       PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
+                       TCHAR   wbuf[BUFSZ];
+                       size_t text_size;
+
+                       if( !data->window_text ) {
+                               text_size = strlen(msg_data->text) + 4;
+                               data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0]));
+                               ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0]));
+                       } else {
+                               text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4;
+                               data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0]));
+                       }
+                       if( !data->window_text ) break;
+
+                       _tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
+                       _tcscat(data->window_text, TEXT("\r\n"));
+                       break;
+               }
+               case MSNH_MSG_DIED:
+               {
+                       data->rip_text = data->window_text;
+                       data->window_text = NULL;
+                       break;
+               }
+
+       }
+}
+
+void mswin_finish_rip_text(winid wid)
+{
+       SendMessage (mswin_hwnd_from_winid(wid), WM_MSNH_COMMAND,  MSNH_MSG_DIED, 0);
 }
index 1606d401589d2ad0fb9c17b4fa1417c7f636915a..cc4935509adb8544ee9114d89111a6e35b6bef14 100644 (file)
@@ -8,6 +8,7 @@
 #include "config.h"
 #include "global.h"
 
+void mswin_finish_rip_text(winid wid);
 HWND mswin_init_RIP_window (void);
 void mswin_display_RIP_window (HWND hwnd);
 
index 276c4177a0f39555ba0773e073419369e7072610..7f1ba15bcfb35765d9083178a5e73bfd06fe2fe5 100644 (file)
@@ -24,6 +24,8 @@
 
 #define LLEN 128
 
+extern const char *killed_by_prefix[];
+
 #ifdef _DEBUG
 extern void logDebug(const char *fmt, ...);
 #else
@@ -1067,8 +1069,15 @@ outrip(winid, int)
            -- The tombstone code.  If you want the traditional code use
               genl_outrip for the value and check the #if in rip.c.
 */
+#define STONE_LINE_LEN 16
 void mswin_outrip(winid wid, int how)
 {
+       register char **dp;
+       register char *dpx;
+       char buf[BUFSZ];
+       register int x;
+       int line;
+
        logDebug("mswin_outrip(%d)\n", wid, how);
     if ((wid >= 0) && (wid < MAXWINDOWS) ) {
                DestroyWindow(GetNHApp()->windowlist[wid].win);
@@ -1077,7 +1086,43 @@ void mswin_outrip(winid wid, int how)
                GetNHApp()->windowlist[wid].dead = 0;
        }
 
-       genl_outrip(wid, how);
+       /* Put name on stone */
+       Sprintf(buf, "%s", plname);
+       buf[STONE_LINE_LEN] = 0;
+       putstr(wid, 0, buf);
+
+       /* Put $ on stone */
+#ifndef GOLDOBJ
+       Sprintf(buf, "%ld Au", u.ugold);
+#else
+       Sprintf(buf, "%ld Au", done_money);
+#endif
+       buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */
+       putstr(wid, 0, buf);
+
+       /* Put together death description */
+       switch (killer_format) {
+               default: impossible("bad killer format?");
+               case KILLED_BY_AN:
+                       Strcpy(buf, killed_by_prefix[how]);
+                       Strcat(buf, an(killer));
+                       break;
+               case KILLED_BY:
+                       Strcpy(buf, killed_by_prefix[how]);
+                       Strcat(buf, killer);
+                       break;
+               case NO_KILLER_PREFIX:
+                       Strcpy(buf, killer);
+                       break;
+       }
+
+       /* Put death type on stone */
+       putstr(wid, 0, buf);
+
+       /* Put year on stone */
+       Sprintf(buf, "%4d", getyear());
+       putstr(wid, 0, buf);
+       mswin_finish_rip_text(wid);
 }
 
 /* handle options updates here */
index 79d7baf5bc81c092ecdb710bb2a76b3473c2ff9c..0e6decc7801d7eab654e914d1113d94adea7be05 100644 (file)
@@ -24,6 +24,7 @@
 #define IDD_PLAYER_SELECTOR             141
 #define IDB_PETMARK                     143
 #define IDB_MENU_SEL_COUNT              144
+#define IDD_NHRIP                       145
 #define IDC_TEXT_VIEW                   1000
 #define IDC_TEXT_CONTROL                1000
 #define IDC_CMD_MOVE_NW                 1001
 #define IDC_PLSEL_GENDER_LIST           1326
 #define IDC_ABOUT_VERSION               1327
 #define IDC_ABOUT_COPYRIGHT             1328
+#define IDB_RIP                         1329
 #define IDM_SAVE                        32771
 #define IDM_HELP_LONG                   32772
 #define IDM_HELP_COMMANDS               32773
index e41ce1b0578386367be379a4ae9397d94524f4f9..0d80936f7ba911c9c80a58a181693bed80aa6167 100644 (file)
@@ -50,6 +50,7 @@ typedef struct mswin_nhwindow_app {
        HBITMAP         bmpTiles;
        HBITMAP         bmpPetMark;
        HBITMAP         bmpMapTiles; /* custom tiles bitmap */
+       HBITMAP         bmpRip;
        int                     mapTile_X;      /* tile width */
        int                     mapTile_Y;      /* tile height */
        int                     mapTilesPerLine;        /* number of tile per row in the bitmap */
index 535e448de6c06289c3a391ead417fc3d7c5ae204..253c6115f0771fae5c80b5b4046206af2a37d793 100644 (file)
@@ -57,6 +57,8 @@ int APIENTRY WinMain(HINSTANCE hInstance,
        if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap");
        _nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
        if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap");
+       _nethack_app.bmpRip = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_RIP));
+       if ( _nethack_app.bmpRip == NULL ) panic("cannot load rip bitmap");
        _nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
        _nethack_app.mapTile_X = TILE_X;
        _nethack_app.mapTile_Y = TILE_Y;
index 9840a905d031f0e530323cc3244c346ed62d06f0..4ae1370e9df31b22e51da08c6fb9c6eaa7969716 100644 (file)
@@ -181,6 +181,14 @@ BEGIN
                     WS_VSCROLL | WS_TABSTOP
 END
 
+IDD_NHRIP DIALOGEX 0, 0, 281, 209
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Here lies..."
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "OK",IDOK,82,188,50,14
+END
+
 
 #ifdef APSTUDIO_INVOKED
 /////////////////////////////////////////////////////////////////////////////
@@ -224,6 +232,7 @@ IDB_MENU_SEL            BITMAP  DISCARDABLE     "mnsel.bmp"
 IDB_MENU_UNSEL          BITMAP  DISCARDABLE     "mnunsel.bmp"
 IDB_PETMARK             BITMAP  DISCARDABLE     "petmark.bmp"
 IDB_MENU_SEL_COUNT      BITMAP  DISCARDABLE     "mnselcnt.bmp"
+IDB_RIP                 BITMAP  DISCARDABLE     "rip.bmp"
 
 /////////////////////////////////////////////////////////////////////////////
 //
@@ -266,6 +275,14 @@ BEGIN
         TOPMARGIN, 7
         BOTTOMMARGIN, 157
     END
+
+    IDD_NHRIP, DIALOG
+    BEGIN
+        LEFTMARGIN, 7
+        RIGHTMARGIN, 274
+        TOPMARGIN, 7
+        BOTTOMMARGIN, 202
+    END
 END
 #endif    // APSTUDIO_INVOKED