143 | 143 | { |
144 | 144 | // If somebody clicks on the column heading |
145 | 145 | case GUIM_MOUSE_PRESS_LEFT: |
146 | 146 | { |
147 | 147 | bool sortable; |
148 | 148 | GUI<bool>::GetSetting(this, "sortable", sortable); |
149 | 149 | if (!sortable) |
150 | 150 | return; |
151 | 151 | |
152 | 152 | CPos mouse = GetMousePos(); |
153 | 153 | if (!m_CachedActualSize.PointInside(mouse)) |
154 | 154 | return; |
155 | 155 | |
156 | 156 | float xpos = 0; |
157 | 157 | for (size_t def = 0; def < m_ObjectsDefs.size(); ++def) |
158 | 158 | { |
159 | 159 | float width = m_ObjectsDefs[def].m_Width; |
160 | 160 | // Check if it's a decimal value, and if so, assume relative positioning. |
161 | 161 | if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0) |
162 | 162 | width *= m_TotalAvalibleColumnWidth; |
164 | 164 | if (mouse.x >= leftTopCorner.x && |
165 | 165 | mouse.x < leftTopCorner.x + width && |
166 | 166 | mouse.y < leftTopCorner.y + m_HeadingHeight) |
167 | 167 | { |
168 | 168 | if (def != m_SelectedDef) |
169 | 169 | { |
170 | 170 | m_SelectedColumnOrder = 1; |
171 | 171 | m_SelectedDef = def; |
172 | 172 | } |
173 | 173 | else |
174 | 174 | m_SelectedColumnOrder = -m_SelectedColumnOrder; |
175 | 175 | GUI<CStr>::SetSetting(this, "selected_column", m_ObjectsDefs[def].m_Id.substr(5)); |
176 | 176 | GUI<int>::SetSetting(this, "selected_column_order", m_SelectedColumnOrder); |
177 | 177 | GUI<int>::SetSetting(this, "selected_def", def); |
178 | 178 | ScriptEvent("selectioncolumnchange"); |
179 | 179 | |
180 | 180 | CStrW soundPath; |
181 | 181 | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) |
182 | 182 | g_SoundManager->PlayAsUI(soundPath.c_str(), false); |
183 | 183 | |