Skip to content

Commit

Permalink
dev&i8n-按钮迁移到setting页面。添加新的翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhgithub committed Sep 7, 2023
1 parent 624dc67 commit 30f609f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
14 changes: 9 additions & 5 deletions assets/translation.csv
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Keyword,Comment,Chinese,English
连接异常,none,连接异常,connection_exception
用户名已存在,none,用户名已存在,Username has exits
开始,none,开始,Start_game
开始,none,开始,Start game
端口,none,端口,Port
服务器,none,服务器,Server
多人游戏,none,多人游戏,Mutiplayer
进入服务器,none,进入服务器,Enter_Server
进入服务器,none,进入服务器,Enter Server
昵称,none,昵称,Nickname
返回,none,返回,Back
设置,none,设置,setting
设置,none,设置,Setting
退出,none,退出,Exit
关于,none,关于,about
关于,none,关于,Sbout
合成列表,none,合成列表,Craft
切换英语,none,切换英语,English
切换中文,none,切换中文,Chinese
切换中文,none,切换中文,Chinese
依赖,none,依赖,Base on
规则,none,规则,Formula
输出,none,输出,Output
操作,none,操作,Actions
4 changes: 3 additions & 1 deletion src/client/state_manager/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy::{
},
window::{CursorGrabMode, PrimaryWindow, Window, WindowCloseRequested},
};
use bevy_easy_localize::Localize;
use bevy_egui::{
egui::{self, epaint::Shadow, Color32},
EguiContext, EguiContexts, EguiSet, EguiUserTextures,
Expand Down Expand Up @@ -211,6 +212,7 @@ fn panic_on_error_system(mut renet_error: EventReader<NetcodeTransportError>) {
}

fn client_do_disconnected(
localize: Res<Localize>,
client: Res<RenetClient>,
mut play_state: ResMut<NextState<PlayState>>,
mut game_state: ResMut<NextState<GameState>>,
Expand All @@ -225,7 +227,7 @@ fn client_do_disconnected(
}
notification
.toasts
.error(message)
.error(localize.get(message))
.set_duration(Some(Duration::from_secs(5)));
play_state.set(PlayState::Disabled);
game_state.set(GameState::Menu);
Expand Down
33 changes: 25 additions & 8 deletions src/client/state_manager/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use bevy_easy_localize::Localize;
use bevy_egui::{egui, EguiContext, EguiContexts, EguiUserTextures};
use std::time::Duration;

use super::{ENGLISH, CHINESE};
use super::{notification::Notification, ConnectionAddr, GameState};
use super::{CHINESE, ENGLISH};
use crate::{
client::{
player::controller::back_grab_cursor,
Expand All @@ -31,6 +31,7 @@ use crate::{
pub enum MenuState {
Main,
Test,
Settings,
Multiplayer,
#[default]
Disabled,
Expand All @@ -46,6 +47,7 @@ impl Plugin for MenuPlugin {
app.add_systems(OnEnter(GameState::Menu), (setup, back_grab_cursor));
app.add_systems(Update, menu_main.run_if(in_state(MenuState::Main)));
app.add_systems(Update, test.run_if(in_state(MenuState::Test)));
app.add_systems(Update, menu_settings.run_if(in_state(MenuState::Settings)));
app.add_systems(
Update,
menu_multiplayer.run_if(in_state(MenuState::Multiplayer)),
Expand All @@ -58,10 +60,30 @@ impl Plugin for MenuPlugin {
}
}

fn menu_multiplayer(
fn menu_settings(
mut localize: ResMut<Localize>,
mut contexts: EguiContexts,
mut menu_state: ResMut<NextState<MenuState>>,
) {
egui::CentralPanel::default().show(contexts.ctx_mut(), |ui| {
ui.heading(localize.get("设置"));
if ui.button(localize.get("切换英语")).clicked() {
localize.set_language(ENGLISH);
}
if ui.button(localize.get("切换中文")).clicked() {
localize.set_language(CHINESE);
}
if ui.button(localize.get("返回")).clicked() {
// 状态转移到 多人游戏的设置
menu_state.set(MenuState::Main);
}
});
}

fn menu_multiplayer(
localize: Res<Localize>,
mut contexts: EguiContexts,
mut menu_state: ResMut<NextState<MenuState>>,
mut connection_addr: ResMut<ConnectionAddr>,
mut notification: ResMut<Notification>,
mut game_state: ResMut<NextState<GameState>>,
Expand All @@ -77,12 +99,6 @@ fn menu_multiplayer(

ui.label(localize.get("昵称"));
ui.text_edit_singleline(&mut connection_addr.nickname);
if ui.button(localize.get("切换英语")).clicked() {
localize.set_language(ENGLISH);
}
if ui.button(localize.get("切换中文")).clicked() {
localize.set_language(CHINESE);
}
if ui.button(localize.get("开始")).clicked() {
// 这开始游戏相关数据
if connection_addr.server.is_empty() {
Expand Down Expand Up @@ -139,6 +155,7 @@ fn menu_main(
}
if ui.button(localize.get("设置")).clicked() {
// 转到设计游戏的地方
menu_state.set(MenuState::Settings);
}
if ui.button(localize.get("退出")).clicked() {
// 退出游戏
Expand Down
8 changes: 4 additions & 4 deletions src/client/ui/staff_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ pub fn staff_rules_ui(
table
.header(20.0, |mut header| {
header.col(|ui| {
ui.strong("Base On");
ui.strong(localize.get("依赖"));
});
header.col(|ui| {
ui.strong("Rule");
ui.strong(localize.get("规则"));
});
header.col(|ui| {
ui.strong("Output");
ui.strong(localize.get("输出"));
});
header.col(|ui| {
ui.strong("Action");
ui.strong(localize.get("操作"));
});
})
.body(|mut body| {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub const TOUCH_RADIUS: f32 = 5.;
pub const CLIENT_DEBUG: bool = false;
pub const CLIENT_FPS: bool = false;
// 是否每次都重新生成地形
pub const CLIENT_MAP_GEN: bool = true;
pub const CLIENT_MAP_GEN: bool = false;

// 最大物品堆放
pub const MAX_STAFF_FIXED: usize = 999;
Expand Down

0 comments on commit 30f609f

Please sign in to comment.