//Check where in the inventory the user clicks and trigger appropiate actions
void Inventory::OnClick(DX2D::Vector2f& aPointerPosition)
{
	for (unsigned int i = 0; i < myContents.Size(); ++i)
	{
		if (CommonUtilities::Intersection::PointVsRect(
			Vector2<float>(aPointerPosition.x, aPointerPosition.y)
			, Vector2<float>(myContents[i]->GetPosition().x, myContents[i]->GetPosition().y)
			, Vector2<float>(myContents[i]->GetPosition().x + myContents[i]->GetSprite()->GetSize().x
			, myContents[i]->GetPosition().y + myContents[i]->GetSprite()->GetSize().y)))
		{
			if (mySelectedItem == nullptr)
			{
				mySelectedItem = myContents[i];
				myPreviouslySelectedItem = mySelectedItem;
				UpdateSelectedItem();
				return;
			}
			else
			{
				if (Combine(mySelectedItem, myContents[i]) == true)
				{
					mySelectedItem = nullptr;
					myPreviouslySelectedItem = nullptr;
					UpdateSelectedItem();
					return;
				}
				else if (mySelectedItem == myContents[i])
				{
					DeSelect();
				}
				else
				{
					mySelectedItem = nullptr;
					myPreviouslySelectedItem = nullptr;
					UpdateSelectedItem();
					return;
				}
			}
		}
	}

	//Options area in the inventory
	Vector2f topLeft = { 0.86458f, 1 - 0.0833f };
	Vector2f botRight = { 0.97656f, 1 - 0.032407f };

	if (CommonUtilities::Intersection::PointVsRect(
		Vector2<float>(aPointerPosition.x, aPointerPosition.y), topLeft, botRight) == true)
	{
		mySelectedItem = nullptr;
		myPreviouslySelectedItem = nullptr;
		myOptionsPtr->SetActive(!myOptionsPtr->GetActive());

		Sound* SoundPtr = SoundFileHandler::GetInstance()->GetSound("ButtonClick");

		SoundPtr->SetLooping(false);
		SoundPtr->PlaySound();
		SoundPtr->SetVolume(0.4f);
	}
}
void Inventory::DeSelect()
{
	myPreviouslySelectedItem = mySelectedItem;
	mySelectedItem = nullptr;

	UpdateSelectedItem();
}
void Inventory::Init(const char* aFilePath, Options* aOptionsPtr)
{
	myBackground = new DX2D::CSprite(aFilePath);
	myEndPosition.y = 1.0f - myBackground->GetSize().y;
	myStartPosition.y = 1.0f;
	myPosition.y = myStartPosition.y;
	myMovementPerFrame = 0.3f;
	mySelectedItem = nullptr;
	myPreviouslySelectedItem = nullptr;

	myOptionsPtr = aOptionsPtr;

	myHoverText = new DX2D::CText("Text/PassionOne-Regular.ttf_sdf");

	UpdateSelectedItem();
}
//Combine one item with another
bool Inventory::Combine(Item* aItemToCombine, Item* aItemToCombineWith)
{
	if (aItemToCombine == aItemToCombineWith)
	{
		return false;
	}
	if ((aItemToCombine->IsCombinable() == true && aItemToCombineWith->IsCombinable() == true))
	{
		for (unsigned int i = 0; i < myContents.Size(); ++i)
		{
			std::string name = aItemToCombine->GetCombinableItem();
			if (aItemToCombineWith->GetName() == name)
			{
				for (unsigned short j = 0; j < myMasterItemList->GetItemList().Size(); ++j)
				{
					if (myMasterItemList->GetItemList()[j].GetName() == aItemToCombine->GetNameOfResultingItem())
					{
						myContents.RemoveCyclicAtIndex(myContents.Find(aItemToCombine));
						myContents.RemoveCyclicAtIndex(myContents.Find(aItemToCombineWith));

						myContents.Add(&myMasterItemList->GetItemList()[j]);
						mySelectedItem = nullptr;
						UpdateSelectedItem();

						myMasterItemList->GetItemList()[j].PlayCombineSound();
						std::string &str = myMasterItemList->GetItemList()[j].GetCombinationText();

						eventTalkOnCombine->myCanBeInterupted = true;
						eventTalkOnCombine->myColor = { 0.78f, 0.85f, 0.68f, 1.0f };
						eventTalkOnCombine->myAction = EventActions::Talk;
						eventTalkOnCombine->myType = EventTypes::OnClick;
						eventTalkOnCombine->mySize = 0.5f;
						eventTalkOnCombine->myText = str;
						eventTalkOnCombine->myTarget = "Player";
						eventTalkOnCombine->myShowTime = 1.0f;
						eventTalkOnCombine->myLetterLength = 0.05f;

						eventTalkOnCombine->Init(EventManager::GetInstance()->GetCurrentRoom(), EventManager::GetInstance()->GetGameWorld());

						EventManager::GetInstance()->AddEvent(eventTalkOnCombine);

						return true;
					}
				}
			}
		}
	}

	//Trigger message to indicate that they cant be combined

	int myTextIndex = rand() % myFailedCombineTexts.Size();

	if (myTextIndex == myPreviousCombineFailIndex)
	{
		if (myTextIndex == myFailedCombineTexts.Size() - 1)
		{
			--myTextIndex;
		}
		else
		{
			++myTextIndex;
		}
	}
	
	eventTalkOnCombine->myCanBeInterupted = true;
	eventTalkOnCombine->myColor = { 0.78f, 0.85f, 0.68f, 1.0f };
	eventTalkOnCombine->myAction = EventActions::Talk;
	eventTalkOnCombine->myType = EventTypes::OnClick;
	eventTalkOnCombine->mySize = 0.5f;
	eventTalkOnCombine->myText = myFailedCombineTexts[myTextIndex];
	eventTalkOnCombine->myTarget = "Player";
	eventTalkOnCombine->myShowTime = 1.0f;
	eventTalkOnCombine->myLetterLength = 0.05f;

	eventTalkOnCombine->Init(EventManager::GetInstance()->GetCurrentRoom(), EventManager::GetInstance()->GetGameWorld());

	EventManager::GetInstance()->AddEvent(eventTalkOnCombine);

	myPreviousCombineFailIndex = myTextIndex;

	return false;
}
	INT_PTR CInformationBarSettingsDialog::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
	{
		switch (uMsg) {
		case WM_INITDIALOG:
			{
				const CTSTaskCentreSettings &Settings=m_Core.GetSettings();

				Settings.MainBoard.GetInformationBarFont(&m_CurrentFont);
				m_InformationBar.SetItemMargin(m_Core.ScaleDPI(m_InformationBar.GetDefaultItemMargin()));
				m_InformationBar.SetFont(m_CurrentFont);
				m_InformationBar.Create(hDlg);

				m_ItemMargin=MapDialogUnitX(2);
				::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,
									 LB_SETITEMHEIGHT,0,m_InformationBar.GetHeight()+m_ItemMargin*2);

				CMainBoardSettings::InformationBarItemList ItemList;
				Settings.MainBoard.GetInformationBarItemList(&ItemList);
				for (size_t i=0;i<ItemList.size();i++) {
					CMainBoardSettings::InformationBarItemInfo *pItemInfo=
						new CMainBoardSettings::InformationBarItemInfo(ItemList[i]);
					::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,
										 LB_ADDSTRING,0,reinterpret_cast<LPARAM>(pItemInfo));

					InformationBarItems::CCustomInformationItem *pItem=
						new InformationBarItems::CCustomInformationItem(0);
					pItem->SetFormat(pItemInfo->Format.c_str());
					m_InformationBar.AddItem(pItem);
				}

				static const LPCTSTR TextAlignList[] = {
					TEXT("����"),TEXT("�E��"),TEXT("����"),
				};
				for (int i=0;i<_countof(TextAlignList);i++) {
					::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_TEXT_ALIGN,
										 CB_ADDSTRING,0,reinterpret_cast<LPARAM>(TextAlignList[i]));
				}

				::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_WIDTH_SPIN,
									 UDM_SETRANGE32,0,10000);

				SetItemInfo();

				SetFontInfo(hDlg,IDC_SETTINGS_INFORMATION_BAR_FONT_INFO,m_CurrentFont);

				SetTimeComboBox(hDlg,IDC_SETTINGS_INFORMATION_BAR_UPDATE_INTERVAL,
								1,10,Settings.MainBoard.GetInformationBarUpdateInterval());

				CheckItem(IDC_SETTINGS_INFORMATION_BAR_SHOW_ERROR,
						  Settings.MainBoard.GetInformationBarShowError());
				SetTimeComboBox(hDlg,IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION,
								1,10,Settings.MainBoard.GetInformationBarErrorDuration());
				EnableItems(IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION_LABEL,
							IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION,
							Settings.MainBoard.GetInformationBarShowError());
			}
			return TRUE;

		case WM_DRAWITEM:
			{
				LPDRAWITEMSTRUCT pdis=reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);

				if (wParam==IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST) {
					switch (pdis->itemAction) {
					case ODA_DRAWENTIRE:
					case ODA_SELECT:
						{
							const bool fSelected=(pdis->itemState & ODS_SELECTED)!=0;

							::FillRect(pdis->hDC,&pdis->rcItem,
								reinterpret_cast<HBRUSH>(
									static_cast<INT_PTR>((fSelected?COLOR_HIGHLIGHT:COLOR_WINDOW)+1)));

							if ((int)pdis->itemID>=0) {
								const CMainBoardSettings::InformationBarItemInfo *pItemInfo=
									reinterpret_cast<const CMainBoardSettings::InformationBarItemInfo*>(pdis->itemData);
								InformationBarItems::CCustomInformationItem *pItem=
									static_cast<InformationBarItems::CCustomInformationItem*>(m_InformationBar.GetItem(pdis->itemID));
								if (pItem==nullptr)
									break;

								pItem->SetTextAlign(CInformationBar::CItem::TextAlign(pItemInfo->TextAlign));

								RECT rcItem=pdis->rcItem;
								::InflateRect(&rcItem,-m_ItemMargin,-m_ItemMargin);
								RECT rcMargin=m_InformationBar.GetItemMargin();
								rcItem.right=rcItem.left+
									(pItemInfo->Width<0?CInformationBar::CItem::DEFAULT_WIDTH:pItemInfo->Width)+
									rcMargin.left+rcMargin.right;

								m_InformationBar.DrawItemPreview(pItem,pdis->hDC,rcItem);
							}
						}
						if ((pdis->itemState & ODS_FOCUS)==0)
							break;

					case ODA_FOCUS:
						if ((pdis->itemState & ODS_NOFOCUSRECT)==0)
							::DrawFocusRect(pdis->hDC,&pdis->rcItem);
						break;
					}
				}
			}
			return TRUE;

		case WM_COMMAND:
			switch (LOWORD(wParam)) {
			case IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST:
				if (HIWORD(wParam)==LBN_SELCHANGE) {
					SetItemInfo();
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_NEW_ITEM:
				{
					CMainBoardSettings::InformationBarItemInfo *pItemInfo=
						new CMainBoardSettings::InformationBarItemInfo;

					pItemInfo->TextAlign=0;

					LRESULT Index=::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,
													   LB_ADDSTRING,0,reinterpret_cast<LPARAM>(pItemInfo));
					::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,
										 LB_SETCURSEL,Index,0);

					InformationBarItems::CCustomInformationItem *pItem=
						new InformationBarItems::CCustomInformationItem(0);
					m_InformationBar.AddItem(pItem);

					SetItemInfo();
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_DELETE_ITEM:
				{
					LRESULT Sel=::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETCURSEL,0,0);

					if (Sel>=0) {
						delete reinterpret_cast<CMainBoardSettings::InformationBarItemInfo*>(
							::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETITEMDATA,Sel,0));
						::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_DELETESTRING,Sel,0);
						m_InformationBar.DeleteItem(Sel);
						SetItemInfo();
					}
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_MOVE_UP_ITEM:
			case IDC_SETTINGS_INFORMATION_BAR_MOVE_DOWN_ITEM:
				{
					HWND hwndList=GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST);
					bool fUp=LOWORD(wParam)==IDC_SETTINGS_INFORMATION_BAR_MOVE_UP_ITEM;
					LRESULT Sel=::SendMessage(hwndList,LB_GETCURSEL,0,0);
					LRESULT To;

					if (fUp) {
						if (Sel<1)
							return TRUE;
						To=Sel-1;
					} else {
						if (Sel<0 || Sel+1>=::SendMessage(hwndList,LB_GETCOUNT,0,0))
							return TRUE;
						To=Sel+1;
					}

					::SendMessage(hwndList,WM_SETREDRAW,FALSE,0);
					LRESULT ItemData=::SendMessage(hwndList,LB_GETITEMDATA,Sel,0);
					::SendMessage(hwndList,LB_DELETESTRING,Sel,0);
					::SendMessage(hwndList,LB_INSERTSTRING,To,ItemData);
					::SendMessage(hwndList,LB_SETCURSEL,To,0);
					UpdateItemFormat(int(Sel));
					UpdateItemFormat(int(To));
					::SendMessage(hwndList,WM_SETREDRAW,TRUE,0);
					::InvalidateRect(hwndList,nullptr,TRUE);
					SetItemInfo();
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_FORMAT:
				if (HIWORD(wParam)==EN_CHANGE) {
					CMainBoardSettings::InformationBarItemInfo *pItem=GetSelectedItem();

					if (pItem!=nullptr) {
						GetItemString(IDC_SETTINGS_INFORMATION_BAR_FORMAT,&pItem->Format);
						UpdateItemFormat((int)::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETCURSEL,0,0));
						UpdateSelectedItem();
					}
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_FORMAT_MENU:
				{
					HMENU hmenu=::CreatePopupMenu();

					InformationBarItems::CCustomInformationItem::ParameterInfo Info;
					for (int i=0;InformationBarItems::CCustomInformationItem::GetParameterInfo(i,&Info);i++) {
						WCHAR szText[128];

						TSTask::FormatString(szText,_countof(szText),L"%s\t%s",
											 Info.pszParameter,Info.pszText);
						::AppendMenu(hmenu,MF_STRING | MF_ENABLED,i+1,szText);
					}

					RECT rc;
					::GetWindowRect(GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_FORMAT_MENU),&rc);
					int Result=::TrackPopupMenu(hmenu,TPM_RETURNCMD,rc.left,rc.bottom,0,hDlg,nullptr);
					::DestroyMenu(hmenu);

					if (Result>0
							&& InformationBarItems::CCustomInformationItem::GetParameterInfo(Result-1,&Info)) {
						HWND hwndEdit=GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_FORMAT);
						DWORD Start,End;

						::SetFocus(hwndEdit);
						::SendMessage(hwndEdit,EM_GETSEL,
									  reinterpret_cast<WPARAM>(&Start),reinterpret_cast<LPARAM>(&End));
						::SendMessage(hwndEdit,EM_REPLACESEL,
									  TRUE,reinterpret_cast<LPARAM>(Info.pszParameter));
						if (End<Start)
							Start=End;
						::SendMessage(hwndEdit,EM_SETSEL,
									  Start,Start+::lstrlen(Info.pszParameter));
					}
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_TEXT_ALIGN:
				if (HIWORD(wParam)==CBN_SELCHANGE) {
					CMainBoardSettings::InformationBarItemInfo *pItem=GetSelectedItem();

					if (pItem!=nullptr) {
						pItem->TextAlign=
							(int)::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_TEXT_ALIGN,CB_GETCURSEL,0,0);
						UpdateSelectedItem();
					}
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_ITEM_WIDTH:
				if (HIWORD(wParam)==EN_CHANGE) {
					CMainBoardSettings::InformationBarItemInfo *pItem=GetSelectedItem();

					if (pItem!=nullptr) {
						pItem->Width=GetItemInt(IDC_SETTINGS_INFORMATION_BAR_ITEM_WIDTH);
						UpdateSelectedItem();
					}
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_CHOOSE_FONT:
				if (ChooseFontDialog(hDlg,&m_CurrentFont)) {
					SetFontInfo(hDlg,IDC_SETTINGS_INFORMATION_BAR_FONT_INFO,m_CurrentFont);
					m_InformationBar.SetFont(m_CurrentFont);
					::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,
										 LB_SETITEMHEIGHT,0,m_InformationBar.GetHeight()+m_ItemMargin*2);
					::InvalidateRect(GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST),nullptr,TRUE);
				}
				return TRUE;

			case IDC_SETTINGS_INFORMATION_BAR_SHOW_ERROR:
				EnableItems(IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION_LABEL,
							IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION,
							IsItemChecked(IDC_SETTINGS_INFORMATION_BAR_SHOW_ERROR));
			}
			return TRUE;

		case WM_DESTROY:
			{
				int ItemCount=(int)::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETCOUNT,0,0);
				for (int i=0;i<ItemCount;i++) {
					delete reinterpret_cast<CMainBoardSettings::InformationBarItemInfo*>(
						::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETITEMDATA,i,0));
				}
				::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_RESETCONTENT,0,0);

				m_InformationBar.DeleteAllItems();
			}
			return TRUE;
		}

		return FALSE;
	}
Пример #6
0
void CategoryDlg::OnExcludeDblClick(UINT uNotifyCode, int nID, CWindow wndCtl)
{
	UpdateSelectedItem(CListBox(wndCtl), true);
	InitializeLists();
}