| 27 | AddSetting(GUIST_bool, "sortable"); |
| 28 | AddSetting(GUIST_CStr, "selected_column"); |
| 29 | AddSetting(GUIST_int, "selected_def"); |
| 30 | |
| 31 | // Nothing is selected as default. |
| 32 | GUI<CStr>::SetSetting(this, "selected_column", ""); |
| 33 | GUI<int>::SetSetting(this, "selected_def", -1); |
| 130 | |
| 131 | switch (Message.type) |
| 132 | { |
| 133 | case GUIM_MOUSE_PRESS_LEFT: |
| 134 | { |
| 135 | bool sortable; |
| 136 | GUI<bool>::GetSetting(this, "sortable", sortable); |
| 137 | if (!sortable) |
| 138 | break; |
| 139 | |
| 140 | CPos mouse = GetMousePos(); |
| 141 | if (!m_CachedActualSize.PointInside(mouse)) |
| 142 | break; |
| 143 | |
| 144 | float xpos = 0; |
| 145 | int set = -1; |
| 146 | for (unsigned int def = 0; def < m_ObjectsDefs.size(); ++def) |
| 147 | { |
| 148 | // Check if it's a decimal value, and if so, assume relative positioning. |
| 149 | float width = 0; |
| 150 | if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0) |
| 151 | width = m_ObjectsDefs[def].m_Width * m_TotalAvalibleColumnWidth; |
| 152 | else |
| 153 | width = m_ObjectsDefs[def].m_Width; |
| 154 | CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 4); |
| 155 | if (mouse.x >= leftTopCorner.x && |
| 156 | mouse.x < leftTopCorner.x + width && |
| 157 | mouse.y < leftTopCorner.y + m_HeadingHeight) |
| 158 | { |
| 159 | set = def; |
| 160 | break; |
| 161 | } |
| 162 | xpos += width; |
| 163 | } |
| 164 | |
| 165 | if (set != -1) |
| 166 | { |
| 167 | GUI<CStr>::SetSetting(this, "selected_column", m_ObjectsDefs[set].m_Id.substr(5)); |
| 168 | GUI<int>::SetSetting(this, "selected_def", set); |
| 169 | ScriptEvent("selectioncolumnchange"); |
| 170 | |
| 171 | CStrW soundPath; |
| 172 | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) |
| 173 | g_SoundManager->PlayAsUI(soundPath.c_str(), false); |
| 174 | } |
| 175 | break; |
| 176 | } |
| 177 | default: |
| 178 | break; |
| 179 | } |