Skip to content

Commit

Permalink
feat: fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
buxx committed Apr 7, 2024
1 parent 05f8361 commit 1622f14
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 17 deletions.
68 changes: 68 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@
"RUST_BACKTRACE": "1"
}
},
,
{
"type": "lldb",
"request": "launch",
"name": "Server (standalone) Demo2 --release",
"cargo": {
"args": [
"build",
"--bin=battle_server",
"--package=battle_server",
"--release"
],
"filter": {
"name": "battle_server",
"kind": "bin"
}
},
"args": [
"Demo2",
"--rep-address",
"tcp://0.0.0.0:4255",
"--bind-address",
"tcp://0.0.0.0:4256"
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down Expand Up @@ -753,6 +782,45 @@
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "Gui b Demo2 --release",
"cargo": {
"args": [
"build",
"--bin=battle_gui",
"--package=battle_gui",
"--release"
],
"filter": {
"name": "battle_gui",
"kind": "bin"
}
},
"args": [
"Demo2",
"assets/demo2_deployment.json",
"--server-rep-address",
"tcp://0.0.0.0:4255",
"--server-bind-address",
"tcp://0.0.0.0:4256",
"--side",
"b",
"--side-a-control",
"W",
"--side-a-control",
"NW",
"--side-a-control",
"SW",
"--side-b-control",
"ALL",
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"Clippy",
"consts",
"eframe",
"fullscreen",
"Fullscreen",
"ggegui",
"ggez",
"gids",
Expand Down
47 changes: 36 additions & 11 deletions battle_gui/src/engine/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use battle_core::{
audio::Sound,
types::{Offset, WindowPoint},
};
use ggez::{event::MouseButton, input::keyboard::KeyInput, winit::event::VirtualKeyCode, Context};
use ggez::{
conf::WindowMode, event::MouseButton, graphics, input::keyboard::KeyInput,
winit::event::VirtualKeyCode, Context,
};

use crate::{
debug::DebugPhysics,
engine::{event::UIEvent, message::GuiStateMessage},
graphics::{fullscreen_mode, windowed_mode},
ui::BORDER_MOVE_FACTOR,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -59,16 +63,21 @@ impl Engine {
messages.push(EngineMessage::GuiState(GuiStateMessage::PushUIEvent(
UIEvent::ImmobileCursorSince(cursor_immobile_since),
)));
if let Some(border) =
self.point_in_border(ctx, self.gui_state.current_cursor_window_point())

if (!self.gui_state.pending_order().is_empty() || self.gui_state.dragged_squad().is_some())
|| self.gui_state.is_fullscreen()
{
let (x, y) = border.modifier();
messages.push(EngineMessage::GuiState(
GuiStateMessage::ApplyOnDisplaySceneOffset(Offset::new(
-x as f32 * BORDER_MOVE_FACTOR * self.gui_state.zoom.factor(),
-y as f32 * BORDER_MOVE_FACTOR * self.gui_state.zoom.factor(),
)),
));
if let Some(border) =
self.point_in_border(ctx, self.gui_state.current_cursor_window_point())
{
let (x, y) = border.modifier();
messages.push(EngineMessage::GuiState(
GuiStateMessage::ApplyOnDisplaySceneOffset(Offset::new(
-x as f32 * BORDER_MOVE_FACTOR * self.gui_state.zoom.factor(),
-y as f32 * BORDER_MOVE_FACTOR * self.gui_state.zoom.factor(),
)),
));
}
}

messages
Expand Down Expand Up @@ -136,7 +145,7 @@ impl Engine {
messages
}

pub fn collect_key_released(&self, _ctx: &mut Context, input: KeyInput) -> Vec<EngineMessage> {
pub fn collect_key_released(&self, ctx: &mut Context, input: KeyInput) -> Vec<EngineMessage> {
let mut messages = vec![];

match input.keycode {
Expand All @@ -154,6 +163,22 @@ impl Engine {
GuiStateMessage::SetDisplayDebugGui(!self.gui_state.display_debug_gui()),
));
}
Some(VirtualKeyCode::F11) => {
if self.gui_state.is_fullscreen() {
println!("SET WINDOWED");
if let Err(error) = ctx.gfx.set_mode(windowed_mode()) {
eprintln!("ERROR : when set windowed mode: {}", error);
}
} else {
println!("SET FULLSCREEN");
if let Err(error) = ctx.gfx.set_mode(fullscreen_mode()) {
eprintln!("ERROR : when set fullscreen mode: {}", error);
}
}
messages.push(EngineMessage::GuiState(GuiStateMessage::SetFullscreenMode(
!self.gui_state.is_fullscreen(),
)));
}
Some(VirtualKeyCode::LControl) | Some(VirtualKeyCode::RControl) => messages.push(
EngineMessage::GuiState(GuiStateMessage::SetControl(self.determine_controlling())),
),
Expand Down
1 change: 1 addition & 0 deletions battle_gui/src/engine/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ pub enum GuiStateMessage {
SetIntroAck(bool),
SetSavesList(Vec<PathBuf>),
CenterSceneOn(WorldPoint),
SetFullscreenMode(bool),
}
11 changes: 11 additions & 0 deletions battle_gui/src/engine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub struct GuiState {
//
map_width: f32,
map_height: f32,
//
is_fullscreen: bool,
}

impl GuiState {
Expand Down Expand Up @@ -126,6 +128,7 @@ impl GuiState {
saves: vec![],
map_width: map.visual_width() as f32,
map_height: map.visual_height() as f32,
is_fullscreen: false,
}
}

Expand Down Expand Up @@ -414,6 +417,10 @@ impl GuiState {
//
self.middle_click_down = *point
}
GuiStateMessage::SetFullscreenMode(value) => {
//
self.is_fullscreen = *value
}
}
}

Expand Down Expand Up @@ -529,4 +536,8 @@ impl GuiState {
pub fn saves_mut(&mut self) -> &mut Vec<PathBuf> {
&mut self.saves
}

pub fn is_fullscreen(&self) -> bool {
self.is_fullscreen
}
}
12 changes: 12 additions & 0 deletions battle_gui/src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use battle_core::{
types::{Angle, Scale, SoldierIndex, SquadUuid, VehicleIndex, WindowPoint, WorldPoint},
};
use ggez::{
conf::{FullscreenType, WindowMode},
graphics::{self, Canvas, DrawParam, Image, InstanceArray, Mesh, MeshBuilder, Rect},
Context, GameError, GameResult,
};
Expand Down Expand Up @@ -701,6 +702,17 @@ impl Graphics {
}
}

pub fn fullscreen_mode() -> WindowMode {
WindowMode::default().fullscreen_type(FullscreenType::Desktop)
}

pub fn windowed_mode() -> WindowMode {
WindowMode::default()
.dimensions(1024., 768.)
.maximized(false)
.resizable(true)
}

pub fn create_batch(file_path: &str, ctx: &mut Context) -> GameResult<InstanceArray> {
let image = Image::from_path(ctx, file_path)?;
let batch = InstanceArray::new(ctx, image);
Expand Down
10 changes: 4 additions & 6 deletions battle_gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ mod utils;
use server::EmbeddedServerError;
use structopt::StructOpt;

use crate::graphics::windowed_mode;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
pub struct Opt {
Expand Down Expand Up @@ -142,12 +144,8 @@ fn main() -> Result<(), GuiError> {
ready_message,
])?;

let mut context_builder = ggez::ContextBuilder::new("Open Combat", "Bastien Sevajol")
.window_mode(
WindowMode::default()
.dimensions(1024., 768.)
.resizable(true),
);
let mut context_builder =
ggez::ContextBuilder::new("Open Combat", "Bastien Sevajol").window_mode(windowed_mode());
for resource_path in resources.resources_paths_abs() {
context_builder = context_builder.add_resource_path(resource_path);
}
Expand Down

0 comments on commit 1622f14

Please sign in to comment.