Skip to content

Commit c45ecbe

Browse files
committed
move reconnect btn & show name input in game
1 parent 77f556c commit c45ecbe

File tree

6 files changed

+74
-64
lines changed

6 files changed

+74
-64
lines changed

src-tauri/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// pub const IPC_PORT: u16 = 45791;
1+
pub const IPC_PORT: u16 = 45791;
22

33
pub const MAX_HOSTNAME_LENGTH: u32 = 63;
44
pub const MAX_GAMEMODE_LENGTH: u32 = 39;

src/components/FeatureDisabledOverlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const FeatureDisabledOverlay = (props: IProps) => {
3030
>
3131
<Text
3232
semibold
33-
size={3}
33+
size={2}
3434
numberOfLines={2}
3535
style={{ textAlign: "center" }}
3636
color={theme.textPrimary}

src/containers/JoinServerPrompt/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ const styles = StyleSheet.create({
431431
flex: 1,
432432
},
433433
overlay: {
434-
top: sc(5),
434+
top: sc(80),
435435
bottom: sc(20),
436436
},
437437
closeButtonBigView: {

src/containers/NavBar.tsx

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { invoke } from "@tauri-apps/api";
21
import { memo, useCallback, useMemo } from "react";
32
import { useTranslation } from "react-i18next"; // ✅ use this instead
4-
import { StyleSheet, TextInput, TouchableOpacity, View } from "react-native";
3+
import { StyleSheet, TextInput, View } from "react-native";
54
import Icon from "../components/Icon";
65
import TabBar from "../components/TabBar";
7-
import Text from "../components/Text";
8-
import { IN_GAME, IN_GAME_PROCESS_ID } from "../constants/app";
96
import { images } from "../constants/images";
107
import { useGenericTempState } from "../states/genericStates";
118
import { useSettings } from "../states/settings";
@@ -47,14 +44,6 @@ const NavBar = memo(() => {
4744

4845
const dynamicStyles = useMemo(
4946
() => ({
50-
reconnectButton: [
51-
styles.reconnectContainer,
52-
{
53-
backgroundColor: theme.primary,
54-
// @ts-ignore
55-
filter: `drop-shadow(0 0 20px ${theme.primary}44)`,
56-
},
57-
],
5847
nicknameIcon: [
5948
styles.nicknameIconContainer,
6049
{ backgroundColor: theme.itemBackgroundColor },
@@ -81,13 +70,6 @@ const NavBar = memo(() => {
8170
[setListType]
8271
);
8372

84-
const handleReconnect = useCallback(() => {
85-
invoke("send_message_to_game", {
86-
id: IN_GAME_PROCESS_ID,
87-
message: "reconnect",
88-
});
89-
}, []);
90-
9173
const handleNicknameChange = useCallback(
9274
(text: string) => setNickName(text),
9375
[setNickName]
@@ -96,38 +78,25 @@ const NavBar = memo(() => {
9678
return (
9779
<View style={styles.container}>
9880
<TabBar onChange={handleTabChange} list={tabList} selected={listType} />
99-
{IN_GAME ? (
100-
<View style={styles.inputs}>
101-
<TouchableOpacity
102-
onPress={handleReconnect}
103-
style={dynamicStyles.reconnectButton}
104-
>
105-
<Text style={{ fontSize: sc(18) }} color="white" semibold>
106-
{t("reconnect")}
107-
</Text>
108-
</TouchableOpacity>
109-
</View>
110-
) : (
111-
<View style={styles.inputs}>
112-
<View style={styles.nicknameContainer}>
113-
<View style={dynamicStyles.nicknameIcon}>
114-
<Icon
115-
title={t("nickname")}
116-
image={images.icons.nickname}
117-
size={sc(16)}
118-
color={theme.textSecondary}
119-
/>
120-
</View>
121-
<TextInput
122-
value={nickName}
123-
onChangeText={handleNicknameChange}
124-
placeholder={`${t("nickname")}...`}
125-
placeholderTextColor={theme.textSecondary}
126-
style={dynamicStyles.nicknameInput}
81+
<View style={styles.inputs}>
82+
<View style={styles.nicknameContainer}>
83+
<View style={dynamicStyles.nicknameIcon}>
84+
<Icon
85+
title={t("nickname")}
86+
image={images.icons.nickname}
87+
size={sc(16)}
88+
color={theme.textSecondary}
12789
/>
12890
</View>
91+
<TextInput
92+
value={nickName}
93+
onChangeText={handleNicknameChange}
94+
placeholder={`${t("nickname")}...`}
95+
placeholderTextColor={theme.textSecondary}
96+
style={dynamicStyles.nicknameInput}
97+
/>
12998
</View>
130-
)}
99+
</View>
131100
</View>
132101
);
133102
});
@@ -166,13 +135,6 @@ const styles = StyleSheet.create({
166135
alignItems: "center",
167136
borderRadius: sc(5),
168137
},
169-
reconnectContainer: {
170-
height: sc(35),
171-
alignItems: "center",
172-
justifyContent: "center",
173-
paddingHorizontal: sc(20),
174-
borderRadius: sc(5),
175-
},
176138
});
177139

178140
NavBar.displayName = "NavBar";

src/containers/WindowTitleBar.tsx

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { invoke } from "@tauri-apps/api";
22
import { appWindow } from "@tauri-apps/api/window";
33
import { t } from "i18next";
44
import { memo, useCallback, useMemo } from "react";
5-
import { ColorValue, Pressable, StyleSheet, View } from "react-native";
5+
import {
6+
ColorValue,
7+
Pressable,
8+
StyleSheet,
9+
TouchableOpacity,
10+
View,
11+
} from "react-native";
612
import Icon from "../components/Icon";
713
import Text from "../components/Text";
814
import { IN_GAME, IN_GAME_PROCESS_ID } from "../constants/app";
@@ -167,10 +173,35 @@ const WindowTitleBar = memo(() => {
167173
alignItems: "center" as const,
168174
height: "100%",
169175
},
176+
inputs: {
177+
height: "100%",
178+
flex: 1,
179+
flexDirection: "row",
180+
alignItems: "center",
181+
justifyContent: "flex-end",
182+
marginRight: sc(10),
183+
},
184+
reconnectButton: {
185+
height: sc(35),
186+
alignItems: "center",
187+
justifyContent: "center",
188+
paddingHorizontal: sc(20),
189+
borderRadius: sc(5),
190+
backgroundColor: theme.primary,
191+
// @ts-ignore
192+
filter: `drop-shadow(0 0 20px ${theme.primary}44)`,
193+
},
170194
}),
171195
[theme.itemBackgroundColor]
172196
);
173197

198+
const handleReconnect = useCallback(() => {
199+
invoke("send_message_to_game", {
200+
id: IN_GAME_PROCESS_ID,
201+
message: "reconnect",
202+
});
203+
}, []);
204+
174205
const handleThemeToggle = useCallback(() => {
175206
setTheme(themeType === "dark" ? "light" : "dark");
176207
}, [themeType, setTheme]);
@@ -221,12 +252,25 @@ const WindowTitleBar = memo(() => {
221252
Open Multiplayer
222253
</Text>
223254
</View>
224-
<div
225-
data-tauri-drag-region={!IN_GAME}
226-
style={containerStyles.dragRegion}
227-
/>
255+
{!IN_GAME && (
256+
<div data-tauri-drag-region style={containerStyles.dragRegion} />
257+
)}
228258
{/* @ts-ignore */}
229259
<View style={containerStyles.rightSection}>
260+
{IN_GAME && (
261+
// @ts-ignore
262+
<View style={containerStyles.inputs}>
263+
<TouchableOpacity
264+
onPress={handleReconnect}
265+
// @ts-ignore
266+
style={containerStyles.reconnectButton}
267+
>
268+
<Text style={{ fontSize: sc(18) }} color="white" semibold>
269+
{t("reconnect")}
270+
</Text>
271+
</TouchableOpacity>
272+
</View>
273+
)}
230274
<CustomWindowTitleBarButtons
231275
title=""
232276
iconSize={sc(30)}

src/utils/game.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export const startGame = async (
7777
if (IN_GAME) {
7878
invoke("send_message_to_game", {
7979
id: IN_GAME_PROCESS_ID,
80-
message: `connect:${await getIpAddress(server.ip)}:${server.port}`,
80+
message: password.length
81+
? `connect:${await getIpAddress(server.ip)}:${
82+
server.port
83+
}:${nickname}:${password}`
84+
: `connect:${await getIpAddress(server.ip)}:${server.port}:${nickname}`,
8185
});
8286
return;
8387
}

0 commit comments

Comments
 (0)