void HandleItemsPanel( UINT16 usScreenX, UINT16 usScreenY, INT8 bEvent ) { INT16 sIndex; UINT16 usQuantity; //Calc base index from scrolling index sIndex = eInfo.sScrollIndex * 2; //Determine if the index is in the first row or second row from mouse YPos. if( usScreenY >= (2 * iScreenHeightOffset + 400) ) sIndex++; //Add the converted mouse's XPos into a relative index; //Calc: starting from 110, for every 60 pixels, add 2 to the index sIndex += ((usScreenX-110-iScreenWidthOffset)/60) * 2; switch( bEvent ) { case GUI_MOVE_EVENT: if( sIndex < eInfo.sNumItems ) { if( eInfo.sHilitedItemIndex != sIndex ) gfRenderTaskbar = TRUE; //this index will now highlight in yellow. eInfo.sHilitedItemIndex = sIndex; } break; case GUI_LCLICK_EVENT: if( sIndex < eInfo.sNumItems ) { //this index will now highlight in red. if( eInfo.sSelItemIndex != sIndex ) gfRenderTaskbar = TRUE; eInfo.sSelItemIndex = sIndex; if( gfMercGetItem ) { gfMercGetItem = FALSE; gusMercsNewItemIndex = eInfo.pusItemIndex[ eInfo.sSelItemIndex ]; SetMercEditingMode( MERC_INVENTORYMODE ); ClearEditorItemsInfo(); } } break; case GUI_RCLICK_EVENT: if( gfMercGetItem ) { gfMercGetItem = FALSE; gusMercsNewItemIndex = 0xffff; SetMercEditingMode( MERC_INVENTORYMODE ); ClearEditorItemsInfo(); } else if( sIndex < eInfo.sNumItems ) { eInfo.sSelItemIndex = sIndex; gfRenderTaskbar = TRUE; if( CountNumberOfEditorPlacementsInWorld( eInfo.sSelItemIndex, &usQuantity ) ) { FindNextItemOfSelectedType(); } } break; } }
void DoTaskbar(void) { if(!iTaskMode || iTaskMode == iCurrentTaskbar ) { return; } gfRenderTaskbar = TRUE; HideEditorToolbar( iCurrentTaskbar ); //Special code when exiting previous editor tab switch( iCurrentTaskbar ) { case TASK_TERRAIN: UnclickEditorButton( TAB_TERRAIN ); HideTerrainTileButtons(); break; case TASK_BUILDINGS: UnclickEditorButton( TAB_BUILDINGS ); KillTextInputMode(); break; case TASK_ITEMS: UnclickEditorButton( TAB_ITEMS ); HideItemStatsPanel(); if( eInfo.fActive ) ClearEditorItemsInfo(); gfShowPits = FALSE; RemoveAllPits(); break; case TASK_MERCS: UnclickEditorButton( TAB_MERCS ); IndicateSelectedMerc( SELECT_NO_MERC ); SetMercEditingMode( MERC_NOMODE ); break; case TASK_MAPINFO: UnclickEditorButton( TAB_MAPINFO ); ExtractAndUpdateMapInfo(); KillTextInputMode(); HideExitGrids(); break; case TASK_OPTIONS: UnclickEditorButton( TAB_OPTIONS ); break; } //Setup the new tab mode iCurrentTaskbar = iTaskMode; ShowEditorToolbar( iTaskMode ); iTaskMode = TASK_NONE; //Special code when entering a new editor tab switch( iCurrentTaskbar ) { case TASK_MERCS: ClickEditorButton( TAB_MERCS ); ClickEditorButton( MERCS_ENEMY); iDrawMode = DRAW_MODE_ENEMY; SetMercEditingMode( MERC_TEAMMODE ); fBuildingShowRoofs = FALSE; UpdateRoofsView(); break; case TASK_TERRAIN: ClickEditorButton( TAB_TERRAIN ); ShowTerrainTileButtons(); SetEditorTerrainTaskbarMode( TERRAIN_FGROUND_TEXTURES ); break; case TASK_BUILDINGS: ClickEditorButton( TAB_BUILDINGS ); if(fBuildingShowRoofs) ClickEditorButton( BUILDING_TOGGLE_ROOF_VIEW ); if(fBuildingShowWalls) ClickEditorButton( BUILDING_TOGGLE_WALL_VIEW ); if(fBuildingShowRoomInfo) ClickEditorButton( BUILDING_TOGGLE_INFO_VIEW ); if( gfCaves ) { ClickEditorButton( BUILDING_CAVE_DRAWING ); iDrawMode = DRAW_MODE_CAVES; } else { ClickEditorButton( BUILDING_NEW_ROOM ); iDrawMode = DRAW_MODE_ROOM; } TerrainTileDrawMode = TERRAIN_TILES_BRETS_STRANGEMODE; SetEditorSmoothingMode( gMapInformation.ubEditorSmoothingType ); gusSelectionType = gusSavedBuildingSelectionType; SetupTextInputForBuildings(); break; case TASK_ITEMS: SetFont( FONT10ARIAL ); SetFontForeground( FONT_YELLOW ); ClickEditorButton( TAB_ITEMS ); ClickEditorButton( ITEMS_WEAPONS + eInfo.uiItemType - TBAR_MODE_ITEM_WEAPONS ); InitEditorItemsInfo( eInfo.uiItemType ); ShowItemStatsPanel(); gfShowPits = TRUE; AddAllPits(); iDrawMode = DRAW_MODE_PLACE_ITEM; break; case TASK_MAPINFO: ClickEditorButton( TAB_MAPINFO ); if ( gfFakeLights ) ClickEditorButton( MAPINFO_TOGGLE_FAKE_LIGHTS ); ClickEditorButton( MAPINFO_ADD_LIGHT1_SOURCE ); iDrawMode = DRAW_MODE_LIGHT; TerrainTileDrawMode = TERRAIN_TILES_BRETS_STRANGEMODE; SetupTextInputForMapInfo(); break; case TASK_OPTIONS: ClickEditorButton( TAB_OPTIONS ); TerrainTileDrawMode = TERRAIN_TILES_NODRAW; break; } }
void InitEditorItemsInfo(UINT32 uiItemType) { VSURFACE_DESC vs_desc; UINT8 *pDestBuf, *pSrcBuf; UINT32 uiSrcPitchBYTES, uiDestPitchBYTES; INVTYPE *item; SGPRect SaveRect, NewRect; HVOBJECT hVObject; UINT32 uiVideoObjectIndex; UINT16 usUselessWidth, usUselessHeight; INT16 sWidth, sOffset, sStart; INT16 i, x, y; UINT16 usCounter; CHAR16 pStr[ 100 ];//, pStr2[ 100 ]; CHAR16 pItemName[SIZE_ITEM_NAME]; UINT8 ubBitDepth; BOOLEAN fTypeMatch; INT32 iEquipCount = 0; // Check to make sure that there isn't already a valid eInfo if( eInfo.fActive ) { if( eInfo.uiItemType == uiItemType ) { //User clicked on the same item classification -- ignore return; } else { //User selected a different item classification -- delete it first. ClearEditorItemsInfo(); ClearTaskbarRegion( iScreenWidthOffset + 100, 2 * iScreenHeightOffset + 360, iScreenWidthOffset + 480, 2 * iScreenHeightOffset + 440 ); } } else { //Clear the menu area, so that the buffer doesn't get corrupted. ClearTaskbarRegion( iScreenWidthOffset + 100, 2 * iScreenHeightOffset + 360, iScreenWidthOffset + 480, 2 * iScreenHeightOffset + 440 ); } EnableEditorRegion( ITEM_REGION_ID ); eInfo.uiItemType = uiItemType; eInfo.fActive = TRUE; //Begin initialization of data. switch(uiItemType) { case TBAR_MODE_ITEM_WEAPONS: eInfo.sNumItems = eInfo.sNumWeapons; eInfo.sScrollIndex = eInfo.sSaveWeaponsScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelWeaponsIndex; break; case TBAR_MODE_ITEM_AMMO: eInfo.sNumItems = eInfo.sNumAmmo; eInfo.sScrollIndex = eInfo.sSaveAmmoScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelAmmoIndex; break; case TBAR_MODE_ITEM_ARMOUR: eInfo.sNumItems = eInfo.sNumArmour; eInfo.sScrollIndex = eInfo.sSaveArmourScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelArmourIndex; break; case TBAR_MODE_ITEM_LBEGEAR: eInfo.sNumItems = eInfo.sLBEGear; eInfo.sScrollIndex = eInfo.sSaveLBEScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelLBEIndex; break; case TBAR_MODE_ITEM_EXPLOSIVES: eInfo.sNumItems = eInfo.sNumExplosives; eInfo.sScrollIndex = eInfo.sSaveExplosivesScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelExplosivesIndex; break; case TBAR_MODE_ITEM_EQUIPMENT1: eInfo.sNumItems = eInfo.sNumEquipment1; eInfo.sScrollIndex = eInfo.sSaveEquipment1ScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelEquipment1Index; break; case TBAR_MODE_ITEM_EQUIPMENT2: eInfo.sNumItems = eInfo.sNumEquipment2; eInfo.sScrollIndex = eInfo.sSaveEquipment2ScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelEquipment2Index; break; case TBAR_MODE_ITEM_EQUIPMENT3: eInfo.sNumItems = eInfo.sNumEquipment3; eInfo.sScrollIndex = eInfo.sSaveEquipment3ScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelEquipment3Index; break; case TBAR_MODE_ITEM_TRIGGERS: eInfo.sNumItems = eInfo.sNumTriggers; eInfo.sScrollIndex = eInfo.sSaveTriggersScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelTriggersIndex; break; case TBAR_MODE_ITEM_KEYS: eInfo.sNumItems = eInfo.sNumKeys; eInfo.sScrollIndex = eInfo.sSaveKeysScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelKeysIndex; break; default: //error return; } //Allocate memory to store all the item pointers. eInfo.pusItemIndex = (UINT16*)MemAlloc( sizeof(UINT16) * eInfo.sNumItems ); //Disable the appropriate scroll buttons based on the saved scroll index if applicable //Left most scroll position DetermineItemsScrolling(); //calculate the width of the buffer based on the number of items. //every pair of items (odd rounded up) requires 60 pixels for width. //the minimum buffer size is 420. Height is always 80 pixels. eInfo.sWidth = (eInfo.sNumItems > 12) ? ((eInfo.sNumItems+1)/2)*60 : SCREEN_HEIGHT - 120; eInfo.sHeight = 80; // Create item buffer GetCurrentVideoSettings( &usUselessWidth, &usUselessHeight, &ubBitDepth ); vs_desc.fCreateFlags = VSURFACE_CREATE_DEFAULT | VSURFACE_SYSTEM_MEM_USAGE; vs_desc.usWidth = eInfo.sWidth; vs_desc.usHeight = eInfo.sHeight; vs_desc.ubBitDepth = ubBitDepth; //!!!Memory check. Create the item buffer if(!AddVideoSurface( &vs_desc, &eInfo.uiBuffer )) { eInfo.fKill = TRUE; eInfo.fActive = FALSE; return; } pDestBuf = LockVideoSurface(eInfo.uiBuffer, &uiDestPitchBYTES); pSrcBuf = LockVideoSurface(FRAME_BUFFER, &uiSrcPitchBYTES); //copy a blank chunk of the editor interface to the new buffer. for( i=0; i<eInfo.sWidth; i+=60 ) { Blt16BPPTo16BPP((UINT16 *)pDestBuf, uiDestPitchBYTES, (UINT16 *)pSrcBuf, uiSrcPitchBYTES, 0+i, 0, iScreenWidthOffset + 100, 2 * iScreenHeightOffset + 360, 60, 80 ); } UnLockVideoSurface(eInfo.uiBuffer); UnLockVideoSurface(FRAME_BUFFER); x = 0; y = 0; usCounter = 0; NewRect.iTop = 0; NewRect.iBottom = eInfo.sHeight; NewRect.iLeft = 0; NewRect.iRight = eInfo.sWidth; GetClippingRect(&SaveRect); SetClippingRect(&NewRect); if( eInfo.uiItemType == TBAR_MODE_ITEM_KEYS ) { //Keys use a totally different method for determining for( i = 0; i < eInfo.sNumItems; i++ ) { item = &Item[ KeyTable[ 0 ].usItem + LockTable[ i ].usKeyItem ]; uiVideoObjectIndex = GetInterfaceGraphicForItem( item ); GetVideoObject( &hVObject, uiVideoObjectIndex ); //Store these item pointers for later when rendering selected items. eInfo.pusItemIndex[i] = KeyTable[ 0 ].usItem + LockTable[ i ].usKeyItem; SetFont(SMALLCOMPFONT); SetFontForeground( FONT_MCOLOR_WHITE ); SetFontDestBuffer( eInfo.uiBuffer, 0, 0, eInfo.sWidth, eInfo.sHeight, FALSE ); swprintf( pStr, L"%S", LockTable[ i ].ubEditorName ); DisplayWrappedString(x, (UINT16)(y+25), 60, 2, SMALLCOMPFONT, FONT_WHITE, pStr, FONT_BLACK, TRUE, CENTER_JUSTIFIED ); UINT16 usGraphicNum = g_bUsePngItemImages ? 0 : item->ubGraphicNum; //Calculate the center position of the graphic in a 60 pixel wide area. sWidth = hVObject->pETRLEObject[usGraphicNum].usWidth; sOffset = hVObject->pETRLEObject[usGraphicNum].sOffsetX; sStart = x + (60 - sWidth - sOffset*2) / 2; BltVideoObjectOutlineFromIndex( eInfo.uiBuffer, uiVideoObjectIndex, usGraphicNum, sStart, y+2, 0, FALSE ); //cycle through the various slot positions (0,0), (0,40), (60,0), (60,40), (120,0)... if( y == 0 ) { y = 40; } else { y = 0; x += 60; } } } else for( i = 0; i < eInfo.sNumItems; i++ ) { fTypeMatch = FALSE; while( usCounter<MAXITEMS && !fTypeMatch ) { if ( Item[usCounter].usItemClass == 0 ) break; item = &Item[usCounter]; //if( Item[usCounter].fFlags & ITEM_NOT_EDITOR ) if(item->notineditor) { usCounter++; continue; } if( eInfo.uiItemType == TBAR_MODE_ITEM_TRIGGERS ) { if( i < PRESSURE_ACTION_ID ) usCounter = ( i % 2 ) ? ACTION_ITEM : SWITCH; else usCounter = ACTION_ITEM; fTypeMatch = TRUE; item = &Item[usCounter]; } else switch( item->usItemClass ) { case IC_GUN: case IC_BLADE: case IC_LAUNCHER: case IC_THROWN: case IC_THROWING_KNIFE: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_WEAPONS; break; case IC_PUNCH: if ( i != NOTHING ) { fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_WEAPONS; } else { fTypeMatch = FALSE; } break; case IC_AMMO: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_AMMO; break; case IC_ARMOUR: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_ARMOUR; break; case IC_LBEGEAR: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_LBEGEAR; break; case IC_GRENADE: case IC_BOMB: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EXPLOSIVES; break; case IC_MEDKIT: case IC_KIT: case IC_FACE: case IC_MONEY: case IC_BELTCLIP: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EQUIPMENT1; break; case IC_MISC: if( usCounter == ACTION_ITEM || usCounter == SWITCH ) break; if( iEquipCount < eInfo.sNumEquipment2 ) fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EQUIPMENT2; else fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EQUIPMENT3; iEquipCount++; break; } if( fTypeMatch ) { uiVideoObjectIndex = GetInterfaceGraphicForItem( item ); GetVideoObject( &hVObject, uiVideoObjectIndex ); //Store these item pointers for later when rendering selected items. eInfo.pusItemIndex[i] = usCounter; SetFont(SMALLCOMPFONT); SetFontForeground( FONT_MCOLOR_WHITE ); SetFontDestBuffer( eInfo.uiBuffer, 0, 0, eInfo.sWidth, eInfo.sHeight, FALSE ); if( eInfo.uiItemType != TBAR_MODE_ITEM_TRIGGERS ) { LoadItemInfo( usCounter, pItemName, NULL ); swprintf( pStr, L"%s", pItemName ); } else { if( i == PRESSURE_ACTION_ID ) { swprintf( pStr, pInitEditorItemsInfoText[0] ); } else if( i < 2 ) { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[5] ); else swprintf( pStr, pInitEditorItemsInfoText[1] ); } else if( i < 4 ) { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[6] ); else swprintf( pStr, pInitEditorItemsInfoText[2] ); } else if( i < 6 ) { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[7] ); else swprintf( pStr, pInitEditorItemsInfoText[3] ); } else { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[8], (i-4)/2 ); else swprintf( pStr, pInitEditorItemsInfoText[4], (i-4)/2 ); } } DisplayWrappedString(x, (UINT16)(y+25), 60, 2, SMALLCOMPFONT, FONT_WHITE, pStr, FONT_BLACK, TRUE, CENTER_JUSTIFIED ); UINT16 usGraphicNum = g_bUsePngItemImages ? 0 : item->ubGraphicNum; if(usGraphicNum < hVObject->usNumberOfObjects) { //Calculate the center position of the graphic in a 60 pixel wide area. sWidth = hVObject->pETRLEObject[usGraphicNum].usWidth; sOffset = hVObject->pETRLEObject[usGraphicNum].sOffsetX; sStart = x + (60 - sWidth - sOffset*2) / 2; if( sWidth && sWidth > 0 ) { BltVideoObjectOutlineFromIndex( eInfo.uiBuffer, uiVideoObjectIndex, usGraphicNum, sStart, y+2, 0, FALSE ); } //cycle through the various slot positions (0,0), (0,40), (60,0), (60,40), (120,0)... if( y == 0 ) { y = 40; } else { y = 0; x += 60; } } else { static vfs::Log& editorLog = *vfs::Log::create(L"EditorItems.log"); editorLog << L"Tried to access item [" << item->ubGraphicNum << L"/" << hVObject->usNumberOfObjects << L"]" << vfs::Log::endl; } } usCounter++; } } SetFontDestBuffer( FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE ); SetClippingRect(&SaveRect); gfRenderTaskbar = TRUE; }