/******************************************************************************
This source file is part of AstroMenace game
(Hardcore 3D space shooter with spaceship upgrade possibilities.)
For the latest info, see http://www.viewizard.com/
File name: Menu_Profile.cpp
Copyright (c) 2006-2007 Michael Kurinnoy, Viewizard
All Rights Reserved.
File Version: 1.2
******************************************************************************
AstroMenace game source code available under "dual licensing" model.
The licensing options available are:
* Commercial Licensing. This is the appropriate option if you are
creating proprietary applications and you are not prepared to
distribute and share the source code of your application.
Contact us for pricing at viewizard@viewizard.com
* Open Source Licensing. This is the appropriate option if you want
to share the source code of your application with everyone you
distribute it to, and you also want to give them the right to share
who uses it. You should have received a copy of the GNU General Public
License version 3 with this source codes.
If not, see .
******************************************************************************/
#include "../Game.h"
#include "../Defines.h"
// вот тут храним самый важный номер! - номер текущего профайла!!!
int CurrentProfile=-1;
char NewProfileName[128] = "";
int Pos = 0;
float LastProfileNameTime = 0.0f;
float CurrentProfileNameTransp = 0.9f;
int SoundOnProfileID = -1;
int SoundTaping = 0;
//------------------------------------------------------------------------------------
// создание новой записи
//------------------------------------------------------------------------------------
void NewRecord()
{
// заносим в новый профайл (последний)
int ProfileNum = -1;
for (int i=4; i>=0; i--)
if (!Setup.Profile[i].Used) ProfileNum = i;
// выводим диалог - все заняты!
if (ProfileNum == -1)
{
SetCurrentDialogBox(1);
return;
}
if (strlen(NewProfileName)<=0) return;
// пишем данные в профайл
Setup.Profile[ProfileNum].Used = true;
strcpy(Setup.Profile[ProfileNum].Name, NewProfileName);
Setup.Profile[ProfileNum].NPCWeaponPenalty = 3;
Setup.Profile[ProfileNum].NPCArmorPenalty = 2;
Setup.Profile[ProfileNum].NPCTargetingSpeedPenalty = 2;
Setup.Profile[ProfileNum].LimitedAmmo = 0;
Setup.Profile[ProfileNum].DestroyableWeapon = 1;
Setup.Profile[ProfileNum].WeaponTargetingMode = 0;
Setup.Profile[ProfileNum].SpaceShipControlMode = 1;
Setup.Profile[ProfileNum].Ship = 1;
Setup.Profile[ProfileNum].ShipHullUpgrade = 1;
Setup.Profile[ProfileNum].ShipHullCurrentStrength = 30;
// сброс настроек оружия
for (int i=0; i=0; i--)
if (!Setup.Profile[i].Used) ProfileNum = i;
// выводим диалог - все заняты!
if (ProfileNum == -1)
{
SetCurrentDialogBox(1);
return;
}
// пишем данные в профайл (дублируем)
Setup.Profile[ProfileNum].Used = true;
strcpy(Setup.Profile[ProfileNum].Name, Setup.Profile[BaseProfileNum].Name);
Setup.Profile[ProfileNum].NPCWeaponPenalty = Setup.Profile[BaseProfileNum].NPCWeaponPenalty;
Setup.Profile[ProfileNum].NPCArmorPenalty = Setup.Profile[BaseProfileNum].NPCArmorPenalty;
Setup.Profile[ProfileNum].NPCTargetingSpeedPenalty = Setup.Profile[BaseProfileNum].NPCTargetingSpeedPenalty;
Setup.Profile[ProfileNum].LimitedAmmo = Setup.Profile[BaseProfileNum].LimitedAmmo;
Setup.Profile[ProfileNum].DestroyableWeapon = Setup.Profile[BaseProfileNum].DestroyableWeapon;
Setup.Profile[ProfileNum].WeaponTargetingMode = Setup.Profile[BaseProfileNum].WeaponTargetingMode;
Setup.Profile[ProfileNum].SpaceShipControlMode = Setup.Profile[BaseProfileNum].SpaceShipControlMode;
Setup.Profile[ProfileNum].Ship = Setup.Profile[BaseProfileNum].Ship;
Setup.Profile[ProfileNum].ShipHullUpgrade = Setup.Profile[BaseProfileNum].ShipHullUpgrade;
Setup.Profile[ProfileNum].ShipHullCurrentStrength = Setup.Profile[BaseProfileNum].ShipHullCurrentStrength;
// сброс настроек оружия
for (int i=0; i 0xFF) // 2 байта
{
Uint16 Temp16 = (Uint16)NewChar;
Uint8 *Temp8 = (Uint8 *)(&Temp16);
NewProfileName[Pos] = Temp8[1];
Pos++;
NewProfileName[Pos] = Temp8[0];
}
else
NewProfileName[Pos] = (char)NewChar;
if (vw_FindSoundByNum(SoundTaping) != 0)
vw_FindSoundByNum(SoundTaping)->Stop(0.0f);
SoundTaping = Audio_PlayMenuSound(4,1.0f);
Pos++;
vw_SetKeys(i, false);
}
// проверяем, может спец-код
if (i == SDLK_BACKSPACE)
if (Pos>0)
{
Pos--;
// если отрицательное - 2 байта
if (NewProfileName[Pos] < 0)
{
NewProfileName[Pos] = 0;
Pos--;
}
NewProfileName[Pos] = 0;
if (vw_FindSoundByNum(SoundTaping) != 0)
vw_FindSoundByNum(SoundTaping)->Stop(0.0f);
SoundTaping = Audio_PlayMenuSound(4,1.0f);
vw_SetKeys(i, false);
}
// ввод названия
if (i == SDLK_KP_ENTER || i == SDLK_RETURN)
if (Pos>0)
{
NewRecord();
//Audio_PlayMenuSound(4,1.0f);
vw_SetKeys(i, false);
}
}
// находим положения ввода
int Size = FontSize2(NewProfileName);
RECT SrcRest, DstRest;
SetRect(&SrcRest,0,0,2,2);
SetRect(&DstRest,X1+Size+2,Y1-2,X1+26+Size,Y1+24);
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/whitepoint.tga"),
true, CurrentProfileNameTransp*MenuContentTransp);
float DeltaTime = vw_GetTime() - LastProfileNameTime;
LastProfileNameTime = vw_GetTime();
CurrentProfileNameTransp -= 2.0f*DeltaTime;
if (CurrentProfileNameTransp < 0.2f) CurrentProfileNameTransp = 0.9f;
}
//------------------------------------------------------------------------------------
// выбор текущего профайла
//------------------------------------------------------------------------------------
void ProfileMenu()
{
RECT SrcRest, DstRest;
SetRect(&SrcRest,2,2,863-2,484-2);
SetRect(&DstRest,Setup.iAspectRatioWidth/2-427,175-15,Setup.iAspectRatioWidth/2-427+863-4,175-15+484-4);
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/panel800_444_back.tga"), true, 0.9f*MenuContentTransp);
int X1 = Setup.iAspectRatioWidth/2 - 372;
int Y1 = 200;
int Prir1 = 24;
// надпись
DrawFont(X1, Y1, 0, 0, 4, MenuContentTransp, GetText("3_New_Pilot_Profile"));
Y1 += 30;
SetRect(&SrcRest,0,0,2,2);
SetRect(&DstRest,X1-2,Y1-6,X1+2+590,Y1-2+30);
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/blackpoint.tga"), true, 0.2f*MenuContentTransp);
SetRect(&DstRest,X1,Y1-4,X1+590,Y1-4+30);
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/blackpoint.tga"), true, 0.5f*MenuContentTransp);
// кнопка, создания новой записи
bool Off = false;
if (strlen(NewProfileName)<=0) Off = true;
if (DrawButton128_2(X1+616, Y1-6, GetText("1_Create"), MenuContentTransp, Off))
{
NewRecord();
}
// ввод текста
if (!isDialogBoxDrawing())
if (MenuContentTransp == 1.0f) ProfileInputText();
DrawFont2(X1, Y1, 0, 0, 0, MenuContentTransp, NewProfileName);
Y1 += Prir1;
// список для выбора записи
Y1 += Prir1;
DrawFont(X1, Y1, 0, 0, 4, MenuContentTransp, GetText("3_Pilots_Profiles"));
int SizeI = Setup.iAspectRatioWidth/2+2 + (130 - FontSize(GetText("3_Money")))/2;
DrawFont(SizeI, Y1, 0, 0, 4, MenuContentTransp, GetText("3_Money"));
SizeI = Setup.iAspectRatioWidth/2+132 + (130 - FontSize(GetText("3_Experience")))/2;
DrawFont(SizeI, Y1, 0, 0, 4, MenuContentTransp, GetText("3_Experience"));
SizeI = Setup.iAspectRatioWidth/2+262 + (130 - FontSize(GetText("3_Difficulty")))/2;
DrawFont(SizeI, Y1, 0, 0, 4, MenuContentTransp, GetText("3_Difficulty"));
Y1 += 30;
SetRect(&SrcRest,0,0,2,2);
SetRect(&DstRest,X1-2,Y1-6,X1+2+750,Y1-2+230);
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/blackpoint.tga"), true, 0.2f*MenuContentTransp);
SetRect(&DstRest,X1,Y1-4,X1+750,Y1-4+230);
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/blackpoint.tga"), true, 0.5f*MenuContentTransp);
Y1 += 230;
int TMPSoundOnProfileID = -1;
int TmpY = Y1-230+8;
for (int i=0; i<5; i++)
{
if (Setup.Profile[i].Used)
{
DrawFont(X1+10, TmpY, 0, 0, 0, MenuContentTransp, "%i.",i+1);
if (FontSize2(Setup.Profile[i].Name) > 300)
{
DrawFont2(X1+50, TmpY, 0, 300, 0, MenuContentTransp, Setup.Profile[i].Name);
char TMP[128];
for (int t=0; t<128; t++) TMP[t]=0;
int j = 0;
while(FontSize(TMP)<=300)
{
TMP[j] = Setup.Profile[i].Name[j];
j++;
}
DrawFont(X1+50+FontSize(TMP), TmpY, 0, 0, 0, MenuContentTransp, "...");
}
else
DrawFont2(X1+50, TmpY, 0, 0, 0, MenuContentTransp, Setup.Profile[i].Name);
int Size = FontSize("%i", Setup.Profile[i].Money);
int SizeI = Setup.iAspectRatioWidth/2+2 + (130 - Size)/2;
DrawFont(SizeI, TmpY, 0, 0, 0, MenuContentTransp, "%i", Setup.Profile[i].Money);
Size = FontSize("%i", Setup.Profile[i].Experience);
SizeI = Setup.iAspectRatioWidth/2+132 + (130 - Size)/2;
DrawFont(SizeI, TmpY, 0, 0, 0, MenuContentTransp, "%i", Setup.Profile[i].Experience);
Size = FontSize("%i%%", Setup.Profile[i].Difficulty);
SizeI = Setup.iAspectRatioWidth/2+262 + (130 - Size)/2;
DrawFont(SizeI, TmpY, 0, 0, 0, MenuContentTransp, "%i%%", Setup.Profile[i].Difficulty);
// проверяем, если стоим над записью
SetRect(&SrcRest,0,0,2,2);
SetRect(&DstRest,X1,Y1-233+46*i,X1+750,Y1-234+46+46*i);
if (!isDialogBoxDrawing())
if (vw_OnRect(&DstRest))
{
TMPSoundOnProfileID = i;
CurrentCursorStatus = 1;
// если только встали - нужно звуком это показать
if (SoundOnProfileID != i)
{
SoundOnProfileID = i;
Audio_PlayMenuSound(5,1.0f);
}
if (vw_GetWindowLBMouse(true))
{
// если другой - нужно сбросить миссию...
if (CurrentProfile != i) CurrentMission = Setup.Profile[i].LastMission;
CurrentProfile = i;
Setup.LastProfile = CurrentProfile;
// играем звук выбора
Audio_PlayMenuSound(6,1.0f);
}
if (CurrentProfile != i)
{
// переход по 2-му клику
if (vw_GetWindowLBDoubleMouse(true))
{
CurrentProfile = i;
Setup.LastProfile = CurrentProfile;
// если другой - нужно сбросить миссию...
CurrentMission = Setup.Profile[CurrentProfile].LastMission;
ComBuffer = MISSION;
}
SetRect(&DstRest,X1+2,Y1-233+46*i,X1+748,Y1-235+46+46*i);
if (CurrentProfile != i)
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/whitepoint.tga"), true, 0.1f*MenuContentTransp);
}
else
{
// переход по 2-му клику
if (vw_GetWindowLBDoubleMouse(true))
{
ComBuffer = MISSION;
}
}
}
}
else
{
float transp = 0.3f;
DrawFont(X1+10, TmpY, 0, 0, 0, transp*MenuContentTransp, "%i.",i+1);
DrawFont(X1+50, TmpY, 0, 0, 0, transp*MenuContentTransp, GetText("3_empty"));
}
TmpY += 46;
}
// если не стоим над профайлами - нужно сбросить флаг
if (TMPSoundOnProfileID == -1) SoundOnProfileID = -1;
// подсветка выбранного...
if (CurrentProfile != -1)
{
SetRect(&SrcRest,0,0,2,2);
SetRect(&DstRest,X1+2,Y1-233+46*CurrentProfile,X1+748,Y1-235+46+46*CurrentProfile);
vw_DrawTransparent(&DstRest, &SrcRest, vw_FindTextureByName("DATA/MENU/whitepoint.tga"), true, 0.1f*MenuContentTransp);
}
Y1 += Prir1;
// кнопка создания дубликата
Off = true;
if (CurrentProfile >= 0) Off = false;
if (DrawButton200_2(X1+6, Y1-6, GetText("1_Duplicate"), MenuContentTransp, Off))
{
DuplicateRecord();
}
// кнопка удаления записи
Off = true;
if (CurrentProfile >= 0) Off = false;
if (DrawButton128_2(X1+240, Y1-6, GetText("1_Delete"), MenuContentTransp, Off))
{
SetCurrentDialogBox(2);
}
// кнопка установки сложности
Off = true;
if (CurrentProfile >= 0) Off = false;
if (DrawButton200_2(X1+544, Y1-6, GetText("1_Difficulty"), MenuContentTransp, Off))
{
ComBuffer = DIFFICULTY;
}
int X = Setup.iAspectRatioWidth/2 + 28;
int Y = 165+100*5;
Off = true;
if (CurrentProfile >= 0) Off = false;
if (DrawButton256(X,Y, GetText("1_NEXT"), MenuContentTransp, &Button11Transp, &LastButton11UpdateTime, Off))
{
ComBuffer = MISSION;
}
X = Setup.iAspectRatioWidth/2 - 284;
if (DrawButton256(X,Y, GetText("1_MAIN_MENU"), MenuContentTransp, &Button10Transp, &LastButton10UpdateTime))
{
ComBuffer = MAIN_MENU;
}
}