diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/launcher/config.rs | 13 | ||||
| -rw-r--r-- | src/launcher/launcher.rs | 15 | ||||
| -rw-r--r-- | src/launcher/mod.rs | 19 | ||||
| -rw-r--r-- | src/main.rs | 10 | ||||
| -rw-r--r-- | src/ui/mod.rs | 29 | ||||
| -rw-r--r-- | src/utils/mod.rs | 34 |
6 files changed, 120 insertions, 0 deletions
diff --git a/src/launcher/config.rs b/src/launcher/config.rs new file mode 100644 index 0000000..fafc229 --- /dev/null +++ b/src/launcher/config.rs @@ -0,0 +1,13 @@ +pub struct Config { + pub username: String, + pub resolution: (u32, u32), +} + +impl Config { + pub fn new(username: &str, resolution: (u32, u32)) -> Self { + Config { + username: username.to_string(), + resolution, + } + } +}
\ No newline at end of file diff --git a/src/launcher/launcher.rs b/src/launcher/launcher.rs new file mode 100644 index 0000000..5ccf443 --- /dev/null +++ b/src/launcher/launcher.rs @@ -0,0 +1,15 @@ +pub struct Launcher { + pub config: crate::launcher::config::Config, +} + +impl Launcher { + pub fn new(config: crate::launcher::config::Config) -> Self { + Launcher { config } + } + + pub fn launch(&self) { + // 启动游戏的逻辑 + println!("启动游戏,用户名: {}", self.config.username); + println!("分辨率: {}x{}", self.config.resolution.0, self.config.resolution.1); + } +}
\ No newline at end of file diff --git a/src/launcher/mod.rs b/src/launcher/mod.rs new file mode 100644 index 0000000..0359d3e --- /dev/null +++ b/src/launcher/mod.rs @@ -0,0 +1,19 @@ +pub mod config; +pub mod launcher; + +pub use config::Config; +pub use launcher::Launcher; + +pub fn start() { + // 启动器的代码 + println!("启动器启动中..."); + + // 创建配置 + let config = Config::new("玩家", (1920, 1080)); + + // 创建启动器 + let launcher = Launcher::new(config); + + // 启动游戏 + launcher.launch(); +}
\ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..31e87da --- /dev/null +++ b/src/main.rs @@ -0,0 +1,10 @@ +mod launcher; +mod ui; + +fn main() { + // 初始化UI模块 + ui::init(); + + // 启动器模块的逻辑 + launcher::start(); +}
\ No newline at end of file diff --git a/src/ui/mod.rs b/src/ui/mod.rs new file mode 100644 index 0000000..778eeee --- /dev/null +++ b/src/ui/mod.rs @@ -0,0 +1,29 @@ +use gtk::prelude::*; +use gtk::{Button, Window, WindowType}; + +pub fn init() { + if gtk::init().is_err() { + println!("Failed to initialize GTK."); + return; + } + + let window = Window::new(WindowType::Toplevel); + window.set_title("Minecraft 启动器"); + window.set_default_size(350, 70); + + let button = Button::with_label("开始游戏"); + button.connect_clicked(|_| { + println!("开始游戏按钮被点击"); + }); + + window.add(&button); + + window.connect_delete_event(|_, _| { + gtk::main_quit(); + Inhibit(false) + }); + + window.show_all(); + + gtk::main(); +}
\ No newline at end of file diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..088da95 --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1,34 @@ +// utils/mod.rs +pub mod file_utils; +pub mod config_parser; + +// 文件操作相关的实用工具函数 +pub mod file_utils { + use std::fs; + use std::io::{self, Write}; + + pub fn read_file_to_string(path: &str) -> io::Result<String> { + fs::read_to_string(path) + } + + pub fn write_string_to_file(path: &str, content: &str) -> io::Result<()> { + let mut file = fs::File::create(path)?; + file.write_all(content.as_bytes()) + } +} + +// 配置解析相关的实用工具函数 +pub mod config_parser { + use std::collections::HashMap; + + pub fn parse_config(content: &str) -> HashMap<String, String> { + let mut config = HashMap::new(); + for line in content.lines() { + let mut parts = line.splitn(2, '='); + if let (Some(key), Some(value)) = (parts.next(), parts.next()) { + config.insert(key.trim().to_string(), value.trim().to_string()); + } + } + config + } +}
\ No newline at end of file |