?? ddbutton.cpp
字號:
/////////////
// DDButton.cpp : v0010
// Written by : Li Haijun
// Compiler : Microsoft Visual C++ 4.2 & DirectX
// Library : DDraw.Lib
// Copyright (C) : 1996 WayAhead Corporation
// v0010 : Oct.25.1996
// V0011 : Dec.23.1996
/////////////
// implementation file
// This file provide basic interfaces for deal with bitmap of interface
//////////////////////////////
#include "stdafx.h"
#include <stdio.h>
#include <ddraw.h>
#include "DDCompo.h" // only include this one
#include "DsApi.h" // sound
#include "DDApi.h" // surface
#include "Assert.h"
#include "Marco.h" //macro define
#include "DDButton.h"
#include "interfac.h"
#include "interfa2.h"
// to include this tempory
#include "DDComUn.h"
// to include this for to use One Fish's l_text
#include "l_text.h"
////////////////////////////
#include "l_allbmp.h"
char bmpfilename[30]="bmp\\bmp.lwc";
char listfilename[30]="bmp\\bmp.idx";
/////////////////////////////////////
/////////////////////////////////////
// to restore all button's pointer
class CDDButton * pAllButton[MAX_BUTTON];
class CDDButton * pCurrentButton; // a pointer point to the current button
class CDDButton * pPreviousButton; // a pointer point to the previous button
int nPreviousButtonState = NONE; // previous button's state,0-up,1-down,2-disable,3-focus,4-disable,5-hide
int nCurrentButtonState = NONE; // current button's state,0-up,1-down,2-disable,3-focus,4-disable,5-hide
extern class CDDCommandUnit * pCurrentCommandUnit ; // a pointer point to the current command unit
/////////////////////////////////////////////////
// this veriable is decleared only for net_work
extern BOOL GAME_bNetwork ;
/////////////////////////////////////////////////
WAVEDYNAMIC Wave; // to broadcast a sound when click a button
//constructor
CDDButton::CDDButton()
{
m_nFileNameId = NONE;
m_PromptString[0] = '\0';
m_szOneBitmap.cx = 0L;
m_szOneBitmap.cy = 0L;
m_rTotal.left = 0L;
m_rTotal.top = 0L;
m_rTotal.right = 0L;
m_rTotal.bottom = 0L;
m_rCurrent.left = 0L;
m_rCurrent.top = 0L;
m_rCurrent.right = 0L;
m_rCurrent.bottom = 0L;
m_dwX = 0; m_dwY = 0;
m_nState = 0;
m_nPreviousState = 0;
m_nPart = 0;
m_bEnableSound = TRUE;
}
//constructor
CDDButton::~CDDButton()
{
Release();
m_nFileNameId = NONE;
m_PromptString[0] = '\0';
m_bEnableSound = TRUE;
}
BOOL CDDButton::PreLoad(int FilenameId, int x, int y,
int OneBitmapWidth/*=0*/, int OneBitmapHeight/*=0*/, int ColorKeyFlag/*=FALSE*/ )
{
char fname[20];
HRESULT ddrval;
DDSURFACEDESC ddsd;
//////////////////////////////////////////////////
_itoa( FilenameId, fname, 10 );
class CPicture_imageall picture;
picture.image_open_compress(bmpfilename);
picture.image_open_index(listfilename);
picture.LoadBitmap( &m_BitmapSurface, FilenameId );
picture.image_close_index();
picture.image_close_compress();
if( ColorKeyFlag == TRUE )
{
m_BitmapSurface.SetColorKeyPAL(0);
}
// to set the value of m_FileName
m_nFileNameId = FilenameId; //set the member veriable m_FileName
/////////////////////////////////////////////////////////
//
// get size of surface.
//
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
ddrval = m_BitmapSurface.GetSurface()->GetSurfaceDesc(&ddsd);
if(ddrval != DD_OK)
return FALSE;
m_rTotal.left = m_rTotal.top = 0;
m_rTotal.right = ddsd.dwWidth;
m_rTotal.bottom = ddsd.dwHeight;
// to set the value of m_szOneBitmap
if( (OneBitmapWidth==0)&&(OneBitmapHeight==0) )
{
// I assume that all single bitmaps' height is equal to it's width
if(m_rTotal.bottom > m_rTotal.right)
m_szOneBitmap.cx = m_szOneBitmap.cy = m_rTotal.right;
else
m_szOneBitmap.cx = m_szOneBitmap.cy = m_rTotal.bottom;
// to set the value of m_rCurrent
m_rCurrent.left = m_rCurrent.top = 0;
m_rCurrent.right = m_rCurrent.bottom = m_szOneBitmap.cx;
}
else if( OneBitmapWidth * OneBitmapHeight == 0 )
return FALSE;
else
{
// I assume that all single bitmaps' height is not equal to it's width
m_szOneBitmap.cx = OneBitmapWidth;
m_szOneBitmap.cy = OneBitmapHeight;
}
//to set the value of m_dwX, m_dwY
m_dwX = x; m_dwY = y;
SetState(BUTTON_UP);
// to insert this button into pAllButton array
for( int i=0; i<MAX_BUTTON; i++ )
{
if( pAllButton[i] == NULL )
{
pAllButton[i] = this;
break;
}
}
return TRUE;
}
// to release this button's pointer
void CDDButton::Release()
{
for( int i=0; i<MAX_BUTTON; i++ )
{
if( (pAllButton[i] != NULL)&&(pAllButton[i] == this) )
{
pAllButton[i] = NULL;
break;
}
}
// release the surface that this button's bitmap used
m_BitmapSurface.Release();
}
// to set the position of left top corner of this button to show
void CDDButton::SetPosition(int PosX, int PosY)
{
//to set the value of m_dwX, m_dwY
m_dwX = PosX;
m_dwY = PosY;
}
// to set this button's ID
void CDDButton::SetID(int ID)
{
m_nID = ID ; // button id
}
// to get this button's ID
int CDDButton::GetID(void)
{
return m_nID;
}
// to set this button's state
void CDDButton::SetState(int state) // let button up or down or ...
{
if( GAME_bNetwork == TRUE && m_nID == BUTTON_PAUSE )
m_nState = BUTTON_DISABLE ;
else
m_nState = state ;
if( state == BUTTON_HIDE )
return ;
if( m_szOneBitmap.cx == m_rTotal.right )
{
m_rCurrent.left = m_rTotal.left;
m_rCurrent.top = m_rTotal.top + m_nState * m_szOneBitmap.cy;
m_rCurrent.right = m_rCurrent.left + m_szOneBitmap.cx;
m_rCurrent.bottom = m_rCurrent.top + m_szOneBitmap.cy;
}
else
{
m_rCurrent.left = m_rTotal.left + m_nState * m_szOneBitmap.cx;
m_rCurrent.top = m_rTotal.top;
m_rCurrent.right = m_rCurrent.left + m_szOneBitmap.cx;
m_rCurrent.bottom = m_rCurrent.top + m_szOneBitmap.cy;
}
}
// to set the prompt string
void CDDButton::SetPromptString( LPCTSTR lpszPromptString )
{
strcpy( m_PromptString, lpszPromptString );
int strlenth=0;
strlenth = strlen( m_PromptString ) ;
for( int i=0; i<strlenth; i++ )
{
if( m_PromptString[i] == '$' )
m_PromptString[i] = ' ' ;
}
}
// to cat the four data to the prompt string
void CDDButton::CatPromptString( int Money, int Food, int Wood, int Iron )
{
char money[50];
char food[50];
char wood[50];
char iron[50];
_itoa(Money, money, 10) ;
_itoa(Food, food, 10) ;
_itoa(Wood, wood, 10) ;
_itoa(Iron, iron, 10) ;
strcat(m_PromptString, "@") ;
strcat(m_PromptString, money) ;
strcat(m_PromptString, "@") ;
strcat(m_PromptString, food) ;
strcat(m_PromptString, "@") ;
strcat(m_PromptString, wood) ;
strcat(m_PromptString, "@") ;
strcat(m_PromptString, iron) ;
strcat(m_PromptString, "@") ;
}
// to cat the 所需計謀 value to the prompt string
void CDDButton::CatJmString( int Jm )
{
char jm[50];
_itoa(Jm, jm, 10) ;
strcat(m_PromptString, "&") ;
strcat(m_PromptString, jm) ;
strcat(m_PromptString, "&") ;
}
// to show the prompt string
void CDDButton::ShowPromptString()
{
char HotKey = '\0' ; // to store the hot kye that should be show
char TempString[256] ; // to out put this string
if( m_PromptString[0] == '\0' )
return;
// TO ADD SOME HOT KEY HERE
if(pCurrentCommandUnit != NULL)
{
if( this == pCurrentCommandUnit->m_pButton[0] )
HotKey = 'Q' ;
else if( this == pCurrentCommandUnit->m_pButton[1] )
HotKey = 'W' ;
else if( this == pCurrentCommandUnit->m_pButton[2] )
HotKey = 'E' ;
else if( this == pCurrentCommandUnit->m_pButton[3] )
HotKey = 'A' ;
else if( this == pCurrentCommandUnit->m_pButton[4] )
HotKey = 'S' ;
else if( this == pCurrentCommandUnit->m_pButton[5] )
HotKey = 'D' ;
else if( this == pCurrentCommandUnit->m_pButton[6] )
HotKey = 'Z' ;
else if( this == pCurrentCommandUnit->m_pButton[7] )
HotKey = 'X' ;
else if( this == pCurrentCommandUnit->m_pButton[8] )
HotKey = 'C' ;
}
if( HotKey != '\0' )
{
TempString[0] = '(' ;
TempString[1] = HotKey ;
TempString[2] = ')' ;
TempString[3] = '\0' ;
strcat(TempString, m_PromptString) ;
}
else
strcpy(TempString, m_PromptString) ;
FACE_Prompt( DD_GetBackBuffer(), TempString );
}
// to erase the prompt area when mouse move out the command button or mouse-left-button down on the command button
void CDDButton::ErasePromptRect()
{
if( m_PromptString[0] == '\0' )
return;
FACE_UpdateMessageRect();
}
/////////////////////////////////////////
// to set all button's state when change the command state
void CDDButton::SetAllButtonState(int state) // let button up or down or ...
{
if( m_nState != BUTTON_HIDE )
{
m_nPreviousState = m_nState; //to store current button state to previous region
m_nState = state; // to set button's state
// Show(); // to show the changed button
}
}
// to restore all button's state when change the command state
void CDDButton::RestoreAllButtonState() // let button up or down or ...
{
if( m_nState != BUTTON_HIDE )
{
m_nState = m_nPreviousState ; //to restore button's state from the previous region
// Show(); // to show this change
}
}
//to test if the given point on this button
BOOL CDDButton::OnButton( int x, int y)
{
int m_nLeftEdge = m_dwX;
int m_nRightEdge = m_nLeftEdge + (int)m_szOneBitmap.cx;
int m_nTopEdge = m_dwY;
int m_nBottomEdge = m_nTopEdge + (int)m_szOneBitmap.cy;
if( (m_nState == BUTTON_DISABLE)||(m_nState==BUTTON_HIDE) )
return FALSE;
else if( (x >= m_nLeftEdge)&&(x <= m_nRightEdge )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -