1
1
use macroquad:: input:: { is_mouse_button_pressed, mouse_position, MouseButton } ;
2
- use macroquad:: prelude:: { clear_background, vec2, WHITE } ;
3
- use macroquad:: ui:: root_ui;
2
+ use macroquad:: prelude:: * ;
4
3
5
4
use server:: action:: Action ;
6
5
use server:: game:: Game ;
@@ -12,13 +11,11 @@ use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate, StateUp
12
11
use crate :: collect_ui:: { click_collect_option, collect_resources_dialog} ;
13
12
use crate :: construct_ui:: pay_construction_dialog;
14
13
use crate :: dialog_ui:: active_dialog_window;
15
- use crate :: happiness_ui:: {
16
- add_increase_happiness, increase_happiness_menu, show_increase_happiness,
17
- } ;
14
+ use crate :: happiness_ui:: { add_increase_happiness, increase_happiness_menu} ;
18
15
use crate :: hex_ui:: pixel_to_coordinate;
19
16
use crate :: log_ui:: show_log;
20
17
use crate :: map_ui:: { draw_map, show_tile_menu} ;
21
- use crate :: player_ui:: { show_global_controls, show_globals, show_player_status , show_wonders } ;
18
+ use crate :: player_ui:: { show_global_controls, show_globals} ;
22
19
use crate :: { combat_ui, dialog_ui, influence_ui, move_ui, recruit_unit_ui, status_phase_ui} ;
23
20
24
21
pub async fn init ( features : & Features ) -> State {
@@ -45,55 +42,36 @@ pub fn render_and_update(
45
42
state. update ( game, update)
46
43
}
47
44
48
- fn render ( game : & Game , state : & State , features : & Features ) -> StateUpdate {
49
- let player_index = game. active_player ( ) ;
45
+ fn render ( game : & Game , state : & mut State , features : & Features ) -> StateUpdate {
50
46
let player = & state. shown_player ( game) ;
51
47
clear_background ( WHITE ) ;
52
48
53
- draw_map ( game, state) ;
49
+ state. camera = Camera2D {
50
+ zoom : vec2 ( state. zoom , state. zoom * screen_width ( ) / screen_height ( ) ) ,
51
+ offset : state. offset ,
52
+ ..Default :: default ( )
53
+ } ;
54
+ set_camera ( & state. camera ) ;
55
+
56
+ if matches ! ( state. active_dialog, ActiveDialog :: None ) || state. active_dialog . is_map_dialog ( ) {
57
+ draw_map ( game, state) ;
58
+ }
54
59
let mut updates = StateUpdates :: new ( ) ;
55
60
let update = show_globals ( game, player) ;
56
61
updates. add ( update) ;
57
- show_player_status ( game, player_index) ;
58
- show_wonders ( game, player_index) ;
59
-
60
- if root_ui ( ) . button ( vec2 ( 1200. , 100. ) , "Advances" ) {
61
- return StateUpdate :: OpenDialog ( ActiveDialog :: AdvanceMenu ) ;
62
- } ;
63
- if root_ui ( ) . button ( vec2 ( 1200. , 130. ) , "Log" ) {
64
- return StateUpdate :: OpenDialog ( ActiveDialog :: Log ) ;
65
- } ;
66
- let d = state. game_state_dialog ( game, & ActiveDialog :: None ) ;
67
- if !matches ! ( d, ActiveDialog :: None )
68
- && d. title ( ) != state. active_dialog . title ( )
69
- && root_ui ( ) . button ( vec2 ( 1200. , 160. ) , format ! ( "Back to {}" , d. title( ) ) )
70
- {
71
- return StateUpdate :: OpenDialog ( d) ;
72
- }
73
62
74
- if features. import_export && player. can_control {
75
- if root_ui ( ) . button ( vec2 ( 1200. , 290. ) , "Import" ) {
76
- return StateUpdate :: Import ;
77
- } ;
78
- if root_ui ( ) . button ( vec2 ( 1250. , 290. ) , "Export" ) {
79
- return StateUpdate :: Export ;
80
- } ;
81
- }
82
63
if player. can_control {
83
64
if let Some ( u) = & state. pending_update {
84
65
updates. add ( dialog_ui:: show_pending_update ( u, player) ) ;
85
66
return updates. result ( ) ;
86
67
}
87
68
}
88
69
89
- if player. can_play_action {
90
- updates. add ( show_increase_happiness ( game, player_index) ) ;
91
- }
92
- updates. add ( show_global_controls ( game, state) ) ;
70
+ updates. add ( show_global_controls ( game, state, features) ) ;
93
71
94
72
updates. add ( match & state. active_dialog {
95
73
ActiveDialog :: None => StateUpdate :: None ,
96
- ActiveDialog :: Log => show_log ( game) ,
74
+ ActiveDialog :: Log => show_log ( game, player ) ,
97
75
ActiveDialog :: TileMenu ( p) => show_tile_menu ( game, * p, player) ,
98
76
ActiveDialog :: WaitingForUpdate => {
99
77
active_dialog_window ( player, "Waiting for update" , |_ui| StateUpdate :: None )
@@ -143,8 +121,9 @@ pub fn try_click(game: &Game, state: &State, player: &ShownPlayer) -> StateUpdat
143
121
return StateUpdate :: None ;
144
122
}
145
123
let ( x, y) = mouse_position ( ) ;
146
-
147
- let pos = Position :: from_coordinate ( pixel_to_coordinate ( x, y) ) ;
124
+ let pos = Position :: from_coordinate ( pixel_to_coordinate (
125
+ state. camera . screen_to_world ( vec2 ( x, y) ) ,
126
+ ) ) ;
148
127
if !game. map . tiles . contains_key ( & pos) {
149
128
return StateUpdate :: None ;
150
129
}
0 commit comments