Skip to content

Commit 6cdec45

Browse files
committed
Update dependencies; add a zoom mode for higher resolution display.
1 parent d34a103 commit 6cdec45

9 files changed

+388
-245
lines changed

Diff for: Cargo.lock

+210-220
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ authors = ["CrLF0710 <[email protected]>"]
88
apiw = { git = "https://github.com/crlf0710/apiw-rs" }
99
concerto = { git = "https://github.com/crlf0710/concerto-rs" }
1010
domino = { git = "https://github.com/crlf0710/domino-rs" }
11-
rand = "0.5"
11+
rand = "0.6"
1212
chrono = "0.4"
1313
clamp = "0.1"
1414
smallvec = "0.6"
1515
log = "0.4"
16-
env_logger = "0.5"
16+
env_logger = "0.6"
1717

1818

1919
[target.'cfg(windows)'.build-dependencies]
20-
embed-resource = "1"
20+
embed-resource = { git = "https://github.com/nabijaczleweli/rust-embed-resource" }

Diff for: res/CharlesMine.rc

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ BEGIN
115115
MENUITEM "Start R&ecording", IDM_ADVANCED_RECORD_RECORD
116116
MENUITEM "Start &Playback", IDM_ADVANCED_RECORD_PLAY
117117
MENUITEM "S&top Recording/Playback\tF12", IDM_ADVANCED_RECORD_STOP
118+
MENUITEM SEPARATOR
119+
MENUITEM "Zoom 1x" IDM_ADVANCED_ZOOM_1x
120+
MENUITEM "Zoom 2x" IDM_ADVANCED_ZOOM_2x
121+
MENUITEM "Zoom 3x" IDM_ADVANCED_ZOOM_3x
118122
END
119123
POPUP "&Help"
120124
BEGIN
@@ -208,6 +212,10 @@ BEGIN
208212
MENUITEM "开始录像(&E)", IDM_ADVANCED_RECORD_RECORD
209213
MENUITEM "开始回放(&P)", IDM_ADVANCED_RECORD_PLAY
210214
MENUITEM "停止(&T)\tF12", IDM_ADVANCED_RECORD_STOP
215+
MENUITEM SEPARATOR
216+
MENUITEM "缩放 1x" IDM_ADVANCED_ZOOM_1x
217+
MENUITEM "缩放 2x" IDM_ADVANCED_ZOOM_2x
218+
MENUITEM "缩放 3x" IDM_ADVANCED_ZOOM_3x
211219
END
212220
POPUP "帮助(&H)"
213221
BEGIN

Diff for: res/Resource.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
#define IDM_ADVANCED_RECORD_RECORD 164
3939
#define IDM_ADVANCED_RECORD_PLAY 166
4040
#define IDM_ADVANCED_RECORD_STOP 167
41-
#define IDM_HELP_ABOUT 171
41+
#define IDM_ADVANCED_ZOOM_1x 170
42+
#define IDM_ADVANCED_ZOOM_2x 171
43+
#define IDM_ADVANCED_ZOOM_3x 172
44+
#define IDM_HELP_ABOUT 199
4245
#define IDD_ABOUTBOX 201
4346
#define IDD_CUSTOM_GAME 202
4447
#define IDD_HERO_NAME 203

Diff for: src/model.rs

+10
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ pub enum ModelCommand {
615615

616616
ToggleAllowMarks,
617617

618+
UpdateZoomRatio(model_config::ZoomRatio),
619+
618620
SaveMap(PathBuf),
619621
LoadMap(PathBuf),
620622
RestartGame,
@@ -738,6 +740,14 @@ impl ::domino::mvc::Model<view::View, controller::Controller> for Model {
738740
}
739741
token.update_view_next(ViewCommand::UpdateUIAllowMarks(model_config::AllowMarks(new_state)));
740742
}
743+
ModelCommand::UpdateZoomRatio(r) => {
744+
{
745+
let model = token.model_mut();
746+
model.config.zoom_ratio = r;
747+
}
748+
token.update_view_next(ViewCommand::UpdateZoomRatio(r));
749+
token.update_view_next(ViewCommand::UpdateUIZoomRatio(r));
750+
}
741751
ModelCommand::EffectNewGameButtonDown => {
742752
token.update_view_next(ViewCommand::SetButtonPressed(true));
743753
}

Diff for: src/model_config.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Default for BoardSetting {
5353
}
5454
}
5555

56-
#[derive(Copy, Clone, Debug)]
56+
#[derive(Copy, Clone, Debug, PartialEq)]
5757
pub struct AllowMarks(pub bool);
5858

5959
impl Default for AllowMarks {
@@ -62,10 +62,24 @@ impl Default for AllowMarks {
6262
}
6363
}
6464

65+
#[derive(Copy, Clone, Debug, PartialEq)]
66+
pub enum ZoomRatio {
67+
Zoom1x,
68+
Zoom2x,
69+
Zoom3x,
70+
}
71+
72+
impl Default for ZoomRatio {
73+
fn default() -> Self {
74+
ZoomRatio::Zoom1x
75+
}
76+
}
77+
6578
#[derive(Default)]
6679
pub struct Config{
6780
pub board_setting: BoardSetting,
6881
pub allow_marks: AllowMarks,
82+
pub zoom_ratio: ZoomRatio,
6983
}
7084

7185
impl Config {

Diff for: src/ui_apiw.rs

+29-12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use apiw::application_support_functions::SaveFileDialogFlags;
3535
pub fn ui_alert(msg: &str) {
3636
MessageBoxBuilder::new()
3737
.message(msg)
38-
.invoke();
38+
.invoke().unwrap();
3939
}
4040

4141
pub struct Ui;
@@ -55,7 +55,7 @@ impl Ui {
5555
Self::create_main_window()?;
5656

5757
THE_GAME.with(|game| {
58-
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
58+
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
5959
let game = &mut *game;
6060
game.mvc.process_input(ControllerInput::Initialize);
6161
Ok(())
@@ -144,7 +144,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
144144
request
145145
.route_create(|window: &ForeignWindow, _| -> apiw::Result<bool> {
146146
THE_GAME.with(|game| {
147-
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
147+
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
148148
let game = &mut *game;
149149
game.mvc.redirect_output_target(Some(window.clone()));
150150
window.invalidate()?;
@@ -156,7 +156,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
156156
let mut paint_dc = window.do_paint()?;
157157

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

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

174174
let mut target = None;
@@ -213,7 +213,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
213213
match args.id() as isize {
214214
resources::IDM_FILE_NEW => {
215215
THE_GAME.with(|game| {
216-
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
216+
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
217217
let game = &mut *game;
218218
game.mvc.process_input(ControllerInput::ModelCommand(
219219
ModelCommand::NewGame));
@@ -222,7 +222,7 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
222222
}
223223
resources::IDM_FILE_GAME_EASY | resources::IDM_FILE_GAME_MEDIUM | resources::IDM_FILE_GAME_HARD => {
224224
THE_GAME.with(|game| {
225-
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
225+
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
226226
let game = &mut *game;
227227
let boardsetting = match args.id() as isize {
228228
resources::IDM_FILE_GAME_EASY => model_config::BoardSetting::EASY,
@@ -237,21 +237,38 @@ BOOL HandleMapFile(bool bSave, UINT nFilterResID, LPCTSTR lpszDefExt, LPTSTR lps
237237
}
238238
resources::IDM_FILE_MARK => {
239239
THE_GAME.with(|game| {
240-
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
240+
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
241241
let game = &mut *game;
242242

243243
game.mvc.process_input(ControllerInput::ModelCommand(
244244
ModelCommand::ToggleAllowMarks));
245245
Ok(())
246246
})?;
247-
}
247+
},
248+
resources::IDM_ADVANCED_ZOOM_1x | resources::IDM_ADVANCED_ZOOM_2x | resources::IDM_ADVANCED_ZOOM_3x => {
249+
THE_GAME.with(|game| {
250+
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
251+
let game = &mut *game;
252+
253+
game.mvc.process_input(ControllerInput::ModelCommand(
254+
ModelCommand::UpdateZoomRatio(
255+
match args.id() as isize {
256+
resources::IDM_ADVANCED_ZOOM_1x => model_config::ZoomRatio::Zoom1x,
257+
resources::IDM_ADVANCED_ZOOM_2x => model_config::ZoomRatio::Zoom2x,
258+
resources::IDM_ADVANCED_ZOOM_3x => model_config::ZoomRatio::Zoom3x,
259+
_ => unreachable!(),
260+
}
261+
)));
262+
Ok(())
263+
})?;
264+
},
248265
resources::IDM_FILE_EXIT => {
249266
window.destroy()?;
250267
},
251268
resources::IDM_ADVANCED_LOADMAP => {
252269
if let Some(path) = Ui::call_open_file_dialog(window, 0, "cmm") {
253270
THE_GAME.with(|game| {
254-
let mut game = game.try_borrow_mut().or_else(|_| apiw::last_error())?;
271+
let mut game = game.try_borrow_mut().or_else(|_| apiw::Error::last())?;
255272
let game = &mut *game;
256273

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

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

280297
game.mvc.process_input(ControllerInput::ModelCommand(

0 commit comments

Comments
 (0)