Skip to content

Commit

Permalink
Update dependencies; add a zoom mode for higher resolution display.
Browse files Browse the repository at this point in the history
  • Loading branch information
crlf0710 committed Apr 5, 2019
1 parent d34a103 commit 6cdec45
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 245 deletions.
430 changes: 210 additions & 220 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ authors = ["CrLF0710 <[email protected]>"]
apiw = { git = "https://github.com/crlf0710/apiw-rs" }
concerto = { git = "https://github.com/crlf0710/concerto-rs" }
domino = { git = "https://github.com/crlf0710/domino-rs" }
rand = "0.5"
rand = "0.6"
chrono = "0.4"
clamp = "0.1"
smallvec = "0.6"
log = "0.4"
env_logger = "0.5"
env_logger = "0.6"


[target.'cfg(windows)'.build-dependencies]
embed-resource = "1"
embed-resource = { git = "https://github.com/nabijaczleweli/rust-embed-resource" }
8 changes: 8 additions & 0 deletions res/CharlesMine.rc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ BEGIN
MENUITEM "Start R&ecording", IDM_ADVANCED_RECORD_RECORD
MENUITEM "Start &Playback", IDM_ADVANCED_RECORD_PLAY
MENUITEM "S&top Recording/Playback\tF12", IDM_ADVANCED_RECORD_STOP
MENUITEM SEPARATOR
MENUITEM "Zoom 1x" IDM_ADVANCED_ZOOM_1x
MENUITEM "Zoom 2x" IDM_ADVANCED_ZOOM_2x
MENUITEM "Zoom 3x" IDM_ADVANCED_ZOOM_3x
END
POPUP "&Help"
BEGIN
Expand Down Expand Up @@ -208,6 +212,10 @@ BEGIN
MENUITEM "开始录像(&E)", IDM_ADVANCED_RECORD_RECORD
MENUITEM "开始回放(&P)", IDM_ADVANCED_RECORD_PLAY
MENUITEM "停止(&T)\tF12", IDM_ADVANCED_RECORD_STOP
MENUITEM SEPARATOR
MENUITEM "缩放 1x" IDM_ADVANCED_ZOOM_1x
MENUITEM "缩放 2x" IDM_ADVANCED_ZOOM_2x
MENUITEM "缩放 3x" IDM_ADVANCED_ZOOM_3x
END
POPUP "帮助(&H)"
BEGIN
Expand Down
5 changes: 4 additions & 1 deletion res/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
#define IDM_ADVANCED_RECORD_RECORD 164
#define IDM_ADVANCED_RECORD_PLAY 166
#define IDM_ADVANCED_RECORD_STOP 167
#define IDM_HELP_ABOUT 171
#define IDM_ADVANCED_ZOOM_1x 170
#define IDM_ADVANCED_ZOOM_2x 171
#define IDM_ADVANCED_ZOOM_3x 172
#define IDM_HELP_ABOUT 199
#define IDD_ABOUTBOX 201
#define IDD_CUSTOM_GAME 202
#define IDD_HERO_NAME 203
Expand Down
10 changes: 10 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ pub enum ModelCommand {

ToggleAllowMarks,

UpdateZoomRatio(model_config::ZoomRatio),

SaveMap(PathBuf),
LoadMap(PathBuf),
RestartGame,
Expand Down Expand Up @@ -738,6 +740,14 @@ impl ::domino::mvc::Model<view::View, controller::Controller> for Model {
}
token.update_view_next(ViewCommand::UpdateUIAllowMarks(model_config::AllowMarks(new_state)));
}
ModelCommand::UpdateZoomRatio(r) => {
{
let model = token.model_mut();
model.config.zoom_ratio = r;
}
token.update_view_next(ViewCommand::UpdateZoomRatio(r));
token.update_view_next(ViewCommand::UpdateUIZoomRatio(r));
}
ModelCommand::EffectNewGameButtonDown => {
token.update_view_next(ViewCommand::SetButtonPressed(true));
}
Expand Down
16 changes: 15 additions & 1 deletion src/model_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Default for BoardSetting {
}
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct AllowMarks(pub bool);

impl Default for AllowMarks {
Expand All @@ -62,10 +62,24 @@ impl Default for AllowMarks {
}
}

#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ZoomRatio {
Zoom1x,
Zoom2x,
Zoom3x,
}

impl Default for ZoomRatio {
fn default() -> Self {
ZoomRatio::Zoom1x
}
}

#[derive(Default)]
pub struct Config{
pub board_setting: BoardSetting,
pub allow_marks: AllowMarks,
pub zoom_ratio: ZoomRatio,
}

impl Config {
Expand Down
41 changes: 29 additions & 12 deletions src/ui_apiw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use apiw::application_support_functions::SaveFileDialogFlags;
pub fn ui_alert(msg: &str) {
MessageBoxBuilder::new()
.message(msg)
.invoke();
.invoke().unwrap();
}

pub struct Ui;
Expand All @@ -55,7 +55,7 @@ impl Ui {
Self::create_main_window()?;

THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;
game.mvc.process_input(ControllerInput::Initialize);
Ok(())
Expand Down Expand Up @@ -144,7 +144,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
request
.route_create(|window: &ForeignWindow, _| -> apiw::Result<bool> {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;
game.mvc.redirect_output_target(Some(window.clone()));
window.invalidate()?;
Expand All @@ -156,7 +156,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
let mut paint_dc = window.do_paint()?;

THE_GAME.with(|game| {
let game = game.try_borrow().or_else(|_| apiw::last_error())?;
let game = game.try_borrow().or_else(|_| apiw::Error::last())?;
game.mvc.sync_output_with_parameter(&mut paint_dc);
Ok(())
})?;
Expand All @@ -168,7 +168,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
THE_GAME.with(|game| {
use apiw::windows_subsystem::window::MouseEventArgType;

let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;

let mut target = None;
Expand Down Expand Up @@ -213,7 +213,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
match args.id() as isize {
resources::IDM_FILE_NEW => {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;
game.mvc.process_input(ControllerInput::ModelCommand(
ModelCommand::NewGame));
Expand All @@ -222,7 +222,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
}
resources::IDM_FILE_GAME_EASY | resources::IDM_FILE_GAME_MEDIUM | resources::IDM_FILE_GAME_HARD => {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;
let boardsetting = match args.id() as isize {
resources::IDM_FILE_GAME_EASY => model_config::BoardSetting::EASY,
Expand All @@ -237,21 +237,38 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
}
resources::IDM_FILE_MARK => {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;

game.mvc.process_input(ControllerInput::ModelCommand(
ModelCommand::ToggleAllowMarks));
Ok(())
})?;
}
},
resources::IDM_ADVANCED_ZOOM_1x | resources::IDM_ADVANCED_ZOOM_2x | resources::IDM_ADVANCED_ZOOM_3x => {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;

game.mvc.process_input(ControllerInput::ModelCommand(
ModelCommand::UpdateZoomRatio(
match args.id() as isize {
resources::IDM_ADVANCED_ZOOM_1x => model_config::ZoomRatio::Zoom1x,
resources::IDM_ADVANCED_ZOOM_2x => model_config::ZoomRatio::Zoom2x,
resources::IDM_ADVANCED_ZOOM_3x => model_config::ZoomRatio::Zoom3x,
_ => unreachable!(),
}
)));
Ok(())
})?;
},
resources::IDM_FILE_EXIT => {
window.destroy()?;
},
resources::IDM_ADVANCED_LOADMAP => {
if let Some(path) = Ui::call_open_file_dialog(window, 0, "cmm") {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;

game.mvc.process_input(ControllerInput::ModelCommand(
Expand All @@ -263,7 +280,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
resources::IDM_ADVANCED_SAVEMAP => {
if let Some(path) = Ui::call_save_file_dialog(window, 0, "cmm") {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;

game.mvc.process_input(ControllerInput::ModelCommand(
Expand All @@ -274,7 +291,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
},
resources::IDM_ADVANCED_RESTART => {
THE_GAME.with(|game| {
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
let game = &mut *game;

game.mvc.process_input(ControllerInput::ModelCommand(
Expand Down
Loading

0 comments on commit 6cdec45

Please sign in to comment.