summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterbump.cpp
blob: 969124a81c6bcfd1a5730d214858cad918e1d125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** 
 * @file llfloaterbump.cpp
 * @brief Floater showing recent bumps, hits with objects, pushes, etc.
 * @author Cory Ondrejka, James Cook
 *
 * Copyright (c) 2003-$CurrentYear$, Linden Research, Inc.
 * $License$
 */
 
#include "llviewerprecompiledheaders.h"

#include "llfloaterbump.h"

#include "llscrolllistctrl.h"

#include "llvieweruictrlfactory.h"
#include "viewer.h"		// gPacificDaylightTime

///----------------------------------------------------------------------------
/// Local function declarations, constants, enums, and typedefs
///----------------------------------------------------------------------------
extern LLLinkedList<LLMeanCollisionData>	gMeanCollisionList;

LLFloaterBump* LLFloaterBump::sInstance = NULL;

///----------------------------------------------------------------------------
/// Class LLFloaterBump
///----------------------------------------------------------------------------

// Default constructor
LLFloaterBump::LLFloaterBump() 
:	LLFloater()
{
	sInstance = this;

	gUICtrlFactory->buildFloater(this, "floater_bumps.xml");
}


// Destroys the object
LLFloaterBump::~LLFloaterBump()
{
	sInstance = NULL;
}

// static
void LLFloaterBump::show(void *contents)
{
	if (gNoRender)
	{
		return;
	}

	if (!sInstance)
	{
		sInstance = new LLFloaterBump();
	}
	
	LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(sInstance, "bump_list");
	if (!list) return;
	list->deleteAllItems();

	if (gMeanCollisionList.isEmpty())
	{
		LLString none_detected = sInstance->childGetText("none_detected");
		LLScrollListItem *item = new LLScrollListItem();
		item->addColumn(none_detected, LLFontGL::sSansSerifBold);
		list->addItem(item);		
	}
	else
	{
		for (LLMeanCollisionData* mcd = gMeanCollisionList.getFirstData();
			 mcd;
			 mcd = gMeanCollisionList.getNextData())
		{
			LLFloaterBump::add(list, mcd);
		}
	}
	
	sInstance->open();	/*Flawfinder: ignore*/
}

void LLFloaterBump::add(LLScrollListCtrl* list, LLMeanCollisionData* mcd)
{
	if (!sInstance)
	{
		new LLFloaterBump();
	}
	
	if (!mcd->mFirstName[0]
	||  list->getItemCount() >= 20)
	{
		return;
	}

	// There's only one internal tm buffer.
	struct tm* timep;
	
	// Convert to Pacific, based on server's opinion of whether
	// it's daylight savings time there.
	timep = utc_to_pacific_time(mcd->mTime, gPacificDaylightTime);
	
	LLString time = llformat("[%d:%02d]", timep->tm_hour, timep->tm_min);

	LLString action;
	switch(mcd->mType)
	{
	case MEAN_BUMP:
		action = "bump";
		break;
	case MEAN_LLPUSHOBJECT:
		action = "llpushobject";
		break;
	case MEAN_SELECTED_OBJECT_COLLIDE:
		action = "selected_object_collide";
		break;
	case MEAN_SCRIPTED_OBJECT_COLLIDE:
		action = "scripted_object_collide";
		break;
	case MEAN_PHYSICAL_OBJECT_COLLIDE:
		action = "physical_object_collide";
		break;
	default:
		llinfos << "LLFloaterBump::add unknown mean collision type "
			<< mcd->mType << llendl;
		return;
	}

	// All above action strings are in XML file
	LLUIString text = sInstance->childGetText(action);
	text.setArg("[TIME]", time);
	text.setArg("[FIRST]", mcd->mFirstName);
	text.setArg("[LAST]", mcd->mLastName);

	LLScrollListItem *item = new LLScrollListItem(TRUE, NULL, mcd->mPerp);
	item->addColumn(text, LLFontGL::sSansSerifBold);
	list->addItem(item);
}