Skip to content

Commit

Permalink
feat: add chat focus states to core
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed May 26, 2024
1 parent 3407d8a commit 3c0de87
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ order: -5

# Changelog

## Version 9

### Code Changes

- Added client-side `messenger` for handling chat focus states
- Patched issue where pressing `E` while chat is focused invoked interactions
- Patched issue where pressing native menu buttons while chatting invoked native menu functions

## Version 8

### Code Changes
Expand Down
6 changes: 6 additions & 0 deletions src/main/client/controllers/interaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as alt from 'alt-client';
import { Events } from '@Shared/events/index.js';
import { useMessenger } from '../system/messenger.js';

type InteractionCallback = (uid: string, pos: alt.Vector3) => void;

const messenger = useMessenger();
const DEFAULT_COOLDOWN = 1000;
const DEFAULT_KEY = 69; // E
const onEnterCallbacks: InteractionCallback[] = [];
Expand All @@ -26,6 +28,10 @@ function handleKeyPress(key: alt.KeyCode) {
return;
}

if (messenger.isChatFocused()) {
return;
}

timeout = Date.now() + DEFAULT_COOLDOWN;
alt.emitServer(Events.controllers.interaction.trigger, uid);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as text from './utility/text/index.js';
import { useWebview } from './webview/index.js';
import { getMinimap } from './utility/minimap/index.js';
import { isNativeMenuOpen } from './menus/native/page.js';
import { useMessenger } from './system/messenger.js';

export function useRebarClient() {
return {
Expand All @@ -25,6 +26,9 @@ export function useRebarClient() {
useClientInteraction,
},
},
messenger: {
useMessenger,
},
menus: {
useNativeMenu,
isNativeMenuOpen,
Expand Down
7 changes: 7 additions & 0 deletions src/main/client/menus/native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as native from 'natives';
import * as page from './page.js';
import { drawTextAbsolute } from '../../utility/text/index.js';
import { Color, Invoke, NativeMenu, Selection, TextInput } from '@Shared/types/nativeMenu.js';
import { useMessenger } from '../../system/messenger.js';

const messenger = useMessenger();

// Menu Display
let interval: number;
Expand All @@ -29,6 +32,10 @@ function handleControls() {
return;
}

if (messenger.isChatFocused()) {
return;
}

if (native.isControlPressed(0, CONTROLS.UP) || native.isDisabledControlPressed(0, CONTROLS.UP)) {
controlCooldown = Date.now() + controlDebounce;
page.up();
Expand Down
4 changes: 0 additions & 4 deletions src/main/client/menus/native/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ export function setMenu(_menu: NativeMenu, _onDestroy: Function) {
updatePages();

instructionalButtons.create([
{ text: ' ', input: '' },
{ text: ' ', input: '' },
{ text: ' ', input: '' },
{ text: ' ', input: '' },
{ text: 'Back / Exit', input: '~INPUT_FRONTEND_RRIGHT~' },
{ text: 'Enter', input: '~INPUT_FRONTEND_RDOWN~' },
{ text: 'Change', input: '~INPUTGROUP_CELLPHONE_NAVIGATE_LR~' },
Expand Down
21 changes: 21 additions & 0 deletions src/main/client/system/messenger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let chatIsFocused = false;

export function useMessenger() {
function focusChat() {
chatIsFocused = true;
}

function unfocusChat() {
chatIsFocused = false;
}

function isChatFocused() {
return chatIsFocused;
}

return {
focusChat,
isChatFocused,
unfocusChat,
};
}

0 comments on commit 3c0de87

Please sign in to comment.