Skip to content

Commit

Permalink
menuscreen and also enchantements (how its пишется)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperErnD committed Jun 25, 2024
1 parent 0bf4c4c commit 4466a45
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 30 deletions.
3 changes: 2 additions & 1 deletion client/src/engine/app.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub fn Engine.init_from_app(app types.App) !Engine {
mut e := Engine{
app: app
ctx: types.Context{
r: unsafe { nil }
r: unsafe { nil },
cs: types.EmptyScreen{}
}
}

Expand Down
5 changes: 4 additions & 1 deletion client/src/engine/renderers/null_renderer.v
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@ pub fn (mut r NullRenderer) get_res() (int, int) {
}

pub fn (mut r NullRenderer) init_app(mut app types.App) ! {
app.init(mut types.Context{})!
app.init(mut types.Context{
r: unsafe { nil }
cs: types.EmptyScreen{}
})!
}
6 changes: 6 additions & 0 deletions client/src/engine/types/context.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ pub mut:
r Renderer
cs Screen
}

pub fn (mut ctx Context) set_screen(mut cs Screen, mut app App) ! {
ctx.cs.deinit()!
ctx.cs = cs
ctx.cs.init(mut ctx, mut app)!
}
4 changes: 2 additions & 2 deletions client/src/engine/types/screen.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module types

pub interface Screen {
mut:
init(mut Context) !
init(mut Context, mut App) !
deinit() !
update(f32, mut Context) !
draw(f32, mut Context) !
}

pub struct EmptyScreen {} // default screen

pub fn (mut es EmptyScreen) init(mut ctx Context) ! {}
pub fn (mut es EmptyScreen) init(mut ctx Context, mut app App) ! {}
pub fn (mut es EmptyScreen) deinit() ! {}
pub fn (mut es EmptyScreen) update(delta f32, mut ctx Context) ! {}
pub fn (mut es EmptyScreen) draw(delta f32, mut ctx Context) ! {}
30 changes: 4 additions & 26 deletions client/src/main.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module main

import screens
import engine
import engine.types

Expand Down Expand Up @@ -34,39 +35,16 @@ pub fn (mut c Chronical) init(mut ctx types.Context) ! {
c.player_img = ctx.r.load_image("assets/player.png")!
c.ui = engine.UI{}
c.ui.init(mut ctx.r)!

// set screen lol
ctx.set_screen(mut screens.MenuScreen{}, mut c)!
}

pub fn (mut c Chronical) deinit() ! {
}

pub fn (mut c Chronical) update(delta f32, mut ctx types.Context) ! {
//c.mui.update()
}

pub fn (mut c Chronical) draw(delta f32, mut ctx types.Context) ! {
ctx.r.begin()

ctx.r.draw_image(c.player_img, 0, 0)!

/*c.mui.begin()
if c.mui.begin_window("hello world", types.Rect{
x: 350, y: 40, w: 300, h: 200
}) {
c.mui.end_window()
}
c.mui.end()
c.mui.draw()!*/

c.ui.begin()

c.ui.label(types.Rect{ x: 0.4, y: 0.45, w: 0.2, h: 0.05 }, "Hello world!", mut types.Color{})!

c.ui.end()

ctx.r.end()


}
28 changes: 28 additions & 0 deletions client/src/screens/menu.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module screens

import engine
import engine.types

pub struct MenuScreen {
mut:
ui engine.UI
}

pub fn (mut ms MenuScreen) init(mut ctx types.Context, mut app types.App) ! {
ms.ui = engine.UI{}
ms.ui.init(mut ctx.r)!
}

pub fn (mut ms MenuScreen) deinit() ! {}
pub fn (mut ms MenuScreen) update(delta f32, mut ctx types.Context) ! {}
pub fn (mut ms MenuScreen) draw(delta f32, mut ctx types.Context) ! {
ctx.r.begin()

ms.ui.begin()

ms.ui.label(types.Rect{ x: 0.4, y: 0.45, w: 0.2, h: 0.05 }, "Hello world!", mut types.Color{})!

ms.ui.end()

ctx.r.end()
}

0 comments on commit 4466a45

Please sign in to comment.