Skip to content

Commit

Permalink
Tracerestrict: Ctrl-click slot/counter dropdowns to show recent
Browse files Browse the repository at this point in the history
See: #745
  • Loading branch information
JGRennison committed Sep 24, 2024
1 parent 1310cce commit 51fc95e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/lang/extra/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ STR_TRACE_RESTRICT_SHARE_TOOLTIP_EXTRA :{STRING}{}{BLAC
STR_TRACE_RESTRICT_SIGNAL_GUI_TOOLTIP :{BLACK}Routefinding restriction
STR_TRACE_RESTRICT_INSTRUCTION_LIST_TOOLTIP :{BLACK}Click an instruction to select it{}Ctrl+Click to scroll to the instruction's target (if any)
STR_TRACE_RESTRICT_HIGHLIGHT_TOOLTIP :{BLACK}Toggle highlighting all signals sharing this program
STR_TRACE_RESTRICT_RECENTLY_USED_TOOLTIP_EXTRA :{STRING}{}{BLACK}Ctrl+Click to list recently used
STR_TRACE_RESTRICT_WARNING_REQUIRES_REALISTIC_BRAKING :{STRING} {PUSH_COLOUR}{RED}(requires realistic braking){POP_COLOUR}
STR_TRACE_RESTRICT_WARNING_SIGNAL_MODE_CONTROL_ONLY :{STRING} {PUSH_COLOUR}{RED}(only for signal mode control actions){POP_COLOUR}
STR_TRACE_RESTRICT_WARNING_NO_SIGNAL_MODE_CONTROL :{STRING} {PUSH_COLOUR}{RED}(not for signal mode control actions){POP_COLOUR}
Expand Down
69 changes: 53 additions & 16 deletions src/tracerestrict_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,18 +726,24 @@ DropDownList GetSlotDropDownList(Owner owner, TraceRestrictSlotID slot_id, int &
GUIList<const TraceRestrictSlot*> list;
DropDownList dlist;

for (const TraceRestrictSlot *slot : TraceRestrictSlot::Iterate()) {
if (!show_other_types && slot->vehicle_type != vehtype) continue;
if (slot->owner == owner) {
list.push_back(slot);
if (_ctrl_pressed && !_recent_slots[vehtype].empty()) {
for (TraceRestrictSlotID id : _recent_slots[vehtype]) {
list.push_back(TraceRestrictSlot::Get(id));
}
} else {
for (const TraceRestrictSlot *slot : TraceRestrictSlot::Iterate()) {
if (!show_other_types && slot->vehicle_type != vehtype) continue;
if (slot->owner == owner) {
list.push_back(slot);
}
}
}

if (list.size() == 0) return dlist;
if (list.size() == 0) return dlist;

list.ForceResort();
_slot_sort_veh_type = vehtype;
list.Sort(show_other_types ? &SlotVehTypeNameSorter : &SlotNameSorter);
list.ForceResort();
_slot_sort_veh_type = vehtype;
list.Sort(show_other_types ? &SlotVehTypeNameSorter : &SlotNameSorter);
}

selected = -1;

Expand Down Expand Up @@ -773,16 +779,22 @@ DropDownList GetCounterDropDownList(Owner owner, TraceRestrictCounterID ctr_id,
GUIList<const TraceRestrictCounter*> list;
DropDownList dlist;

for (const TraceRestrictCounter *ctr : TraceRestrictCounter::Iterate()) {
if (ctr->owner == owner) {
list.push_back(ctr);
if (_ctrl_pressed && !_recent_counters.empty()) {
for (TraceRestrictCounterID id : _recent_counters) {
list.push_back(TraceRestrictCounter::Get(id));
}
} else {
for (const TraceRestrictCounter *ctr : TraceRestrictCounter::Iterate()) {
if (ctr->owner == owner) {
list.push_back(ctr);
}
}
}

if (list.size() == 0) return dlist;
if (list.size() == 0) return dlist;

list.ForceResort();
list.Sort(&CounterNameSorter);
list.ForceResort();
list.Sort(&CounterNameSorter);
}

selected = -1;

Expand Down Expand Up @@ -2784,6 +2796,31 @@ class TraceRestrictWindow: public Window {
return true;
}

case TR_WIDGET_VALUE_DROPDOWN:{
switch (GetTraceRestrictTypeProperties(this->GetSelected()).value_type) {
case TRVT_SLOT_INDEX:
SetDParam(0, STR_TRACE_RESTRICT_COND_VALUE_TOOLTIP);
GuiShowTooltips(this, STR_TRACE_RESTRICT_RECENTLY_USED_TOOLTIP_EXTRA, close_cond, 1);
return true;

default:
return false;
}
}

case TR_WIDGET_LEFT_AUX_DROPDOWN: {
switch (GetTraceRestrictTypeProperties(this->GetSelected()).value_type) {
case TRVT_SLOT_INDEX_INT:
case TRVT_COUNTER_INDEX_INT:
SetDParam(0, STR_TRACE_RESTRICT_COND_VALUE_TOOLTIP);
GuiShowTooltips(this, STR_TRACE_RESTRICT_RECENTLY_USED_TOOLTIP_EXTRA, close_cond, 1);
return true;

default:
return false;
}
}

default:
return false;
}
Expand Down

0 comments on commit 51fc95e

Please sign in to comment.