kendallroth / cs2-city-stats

Mod to view city statistics
https://mods.paradoxplaza.com/mods/85284/Windows
1 stars 2 forks source link

Open info views from icons #5

Open kendallroth opened 4 months ago

kendallroth commented 4 months ago

Clicking on an icon should open the corresponding info view (see forum post for original request). It may be beneficial to only open if no other tool is selected (other than default empty tool), although this could maybe be a setting?

The bindings.d.ts file suggests that this might be possible using a combination of the JS bindings.

function toggleInfoviewMenu(): void;
function useInfoviewToggle(infoviewId: string): (() => void) | undefined;

// May be helpful for figuring out what infoview IDs are (contained in `Infoview.id`)
const infoviews$: ValueBinding<Infoview[]>;
const activeInfoview$: ValueBinding<ActiveInfoview | null>;

// Not sure how these differ from the previous functions, nor how the "entity" would be retrieved for them?
function setActiveInfoview(entity: Entity): void;
function clearActiveInfoview(): void;

export interface Infoview {
  entity: Entity;
  id: string;
  icon: string | null;
  locked: boolean;
  uiTag: string;
  group: number;
  requirements: UnlockingRequirements;
}
kendallroth commented 4 months ago

Took a shot at this last night but wasn't satisfied... Need to find a good way of only triggering this if no other conflicting tools/panels are open. Would be ideal to also find a way to open the infoview menu and associated infoview panel, and not keep toggling the infoview menu (no "set" method; only "toggle") 😢.

  const infoviewList = useValue(infoview.infoviews$);
  const activeTool = useValue(tool.activeTool$);
  const activeInfoview = useValue(infoview.activeInfoview$);
  const defaultToolActive = activeTool.id === tool.DEFAULT_TOOL;

  const handleStatClick = (stat: StatsPanelItem) => {
    // Avoid opening info panel if another tool is already open (would be confusing)
    // TODO: Consider removing this???
    if (!defaultToolActive) return;

    const infoView = infoviewList.find((i) => i.id === stat.infoviewId);
    if (!infoView) return;

    // logger.log(infoView);
    // logger.log(activeTool, defaultToolActive);
    // logger.log(activeInfoview);

    // TODO: Only toggle infoview menu if not already open
    if (!activeInfoview) {
      // game.toggleInfoviewMenu();
    }
    // NOTE: Currently does not open infoview menu but just the active overlay, which can lead to some odd visual glitches if selecting
    //         something in the game that closes overlay but keeps color applied
    // infoview.setActiveInfoview(infoView.entity);
  };