Browse Source

add example

master
jkpete 3 months ago
parent
commit
e1864beed2
  1. 68
      Example/LocalMediaViewer/LocalMediaViewer.tscn
  2. 77
      Example/LocalMediaViewer/Script/ViewLocalVideoMediaViewer.cs
  3. 2
      project.godot

68
Example/LocalMediaViewer/LocalMediaViewer.tscn

@ -1,7 +1,11 @@ @@ -1,7 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://df4gmjq2o1ttn"]
[gd_scene load_steps=4 format=3 uid="uid://df4gmjq2o1ttn"]
[ext_resource type="Script" path="res://Example/LocalMediaViewer/Script/ViewLocalVideoMediaViewer.cs" id="1_hfhp3"]
[sub_resource type="VideoStreamTheora" id="VideoStreamTheora_6wg02"]
[sub_resource type="ImageTexture" id="ImageTexture_2g46x"]
[node name="LocalMediaViewer" type="Control"]
layout_mode = 3
anchors_preset = 15
@ -20,10 +24,11 @@ anchor_right = 1.0 @@ -20,10 +24,11 @@ anchor_right = 1.0
anchor_bottom = 0.8
grow_horizontal = 2
grow_vertical = 2
stream = SubResource("VideoStreamTheora_6wg02")
expand = true
metadata/_edit_use_anchors_ = true
[node name="ViewImage" type="TextureRect" parent="."]
visible = false
layout_mode = 1
anchors_preset = -1
anchor_left = 0.2
@ -31,19 +36,28 @@ anchor_right = 1.0 @@ -31,19 +36,28 @@ anchor_right = 1.0
anchor_bottom = 0.8
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("ImageTexture_2g46x")
expand_mode = 1
metadata/_edit_use_anchors_ = true
[node name="Scroll" type="ScrollContainer" parent="."]
[node name="Tab" type="TabContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_right = 0.2
anchor_bottom = 1.0
anchor_bottom = 0.8
grow_horizontal = 2
grow_vertical = 2
current_tab = 0
metadata/_edit_use_anchors_ = true
[node name="Media" type="ScrollContainer" parent="Tab"]
layout_mode = 2
metadata/_edit_use_anchors_ = true
metadata/_tab_index = 0
[node name="MediaList" type="VBoxContainer" parent="Scroll"]
[node name="MediaList" type="VBoxContainer" parent="Tab/Media"]
layout_mode = 2
size_flags_horizontal = 3
[node name="ControlList" type="HBoxContainer" parent="."]
layout_mode = 1
@ -55,3 +69,47 @@ anchor_bottom = 1.0 @@ -55,3 +69,47 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
metadata/_edit_use_anchors_ = true
[node name="ImportList" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_top = 0.8
anchor_right = 0.2
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
metadata/_edit_use_anchors_ = true
[node name="UploadImage" type="Button" parent="ImportList"]
layout_mode = 2
size_flags_horizontal = 3
text = "导入图片"
[node name="UploadVideo" type="Button" parent="ImportList"]
layout_mode = 2
size_flags_horizontal = 3
text = "导入视频"
[node name="ImportImage" type="FileDialog" parent="."]
title = "Open a File"
initial_position = 1
size = Vector2i(960, 640)
ok_button_text = "Open"
file_mode = 0
access = 2
filters = PackedStringArray("*.png", "*.jpg")
[node name="ImportVideo" type="FileDialog" parent="."]
auto_translate_mode = 1
title = "Open a File"
initial_position = 1
size = Vector2i(960, 640)
ok_button_text = "Open"
file_mode = 0
access = 2
filters = PackedStringArray("*.ogv")
[connection signal="pressed" from="ImportList/UploadImage" to="." method="OpenImportImage"]
[connection signal="pressed" from="ImportList/UploadVideo" to="." method="OpenImportVideo"]
[connection signal="file_selected" from="ImportImage" to="." method="UploadImage"]
[connection signal="file_selected" from="ImportVideo" to="." method="UploadVideo"]

77
Example/LocalMediaViewer/Script/ViewLocalVideoMediaViewer.cs

@ -1,22 +1,95 @@ @@ -1,22 +1,95 @@
using Godot;
using System;
using EGFramework;
using System.IO;
public partial class ViewLocalVideoMediaViewer : Node,IEGFramework
{
public EGLocalFileSave localFileSave { get; set; }
public VideoStreamPlayer ViewVideo { get; set; }
public TextureRect ViewImage { get; set; }
public VBoxContainer VideoList { get; set; }
public FileDialog ImportImage { get; set; }
public FileDialog ImportVideo { get; set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
ViewVideo = this.GetNode<VideoStreamPlayer>("ViewVideo");
ViewImage = this.GetNode<TextureRect>("ViewImage");
VideoList = this.GetNode<VBoxContainer>("Tab/Media/MediaList");
ImportImage = this.GetNode<FileDialog>("ImportImage");
ImportVideo = this.GetNode<FileDialog>("ImportVideo");
LoadFileSystem();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void LoadFileSystem(){
this.localFileSave = new EGLocalFileSave();
localFileSave.RootPath = "SaveData";
if(!localFileSave.IsRemoteDirectoryExist("Media")){
localFileSave.MakeDirectory("Media");
}
RefreshList();
}
public void RefreshList(){
string combinedPath = Path.Combine(localFileSave.RootPath, "Media");
VideoList.ClearChildren();
foreach (var file in localFileSave.ListRemoteFilePath("Media")){
if(file.FileName.GetStrBehindSymbol('.')!="ogv" && file.FileName.GetStrBehindSymbol('.')!="jpg" && file.FileName.GetStrBehindSymbol('.')!="png"){
continue;
}
Button button= new Button();
button.Name = file.FileName;
button.Text = file.FileName;
string combinedFile = Path.Combine(combinedPath, button.Text);
button.Connect("pressed",Callable.From(()=>{
if(button.Text.GetStrBehindSymbol('.')=="ogv"){
PlayVideo(combinedFile);
}
if(button.Text.GetStrBehindSymbol('.')=="jpg" || button.Text.GetStrBehindSymbol('.')=="png"){
PlayImage(combinedFile);
}
}));
VideoList.AddChild(button);
}
}
public void PlayVideo(string videoName){
ViewVideo.Visible = true;
ViewImage.Visible = false;
GD.Print("PlayVideo: " + videoName);
ViewVideo.Stream.File = videoName;
ViewVideo.Play();
}
public void PlayImage(string imageName){
ViewVideo.Visible = false;
ViewImage.Visible = true;
GD.Print("PlayImage: " + imageName);
Image image = Image.LoadFromFile(imageName);
ImageTexture texture = ImageTexture.CreateFromImage(image);
ViewImage.Texture = texture;
// ViewImage.Texture = imageName;
}
public void OpenImportVideo(){
ImportVideo.Popup();
}
public void OpenImportImage(){
ImportImage.Popup();
}
public void UploadVideo(string localVideoPath){
localFileSave.UploadFile(localVideoPath,"Media\\"+Path.GetFileName(localVideoPath));
RefreshList();
OS.Alert("Video Upload Success!","success");
}
public void UploadImage(string localImagePath){
localFileSave.UploadFile(localImagePath,"Media\\"+Path.GetFileName(localImagePath));
RefreshList();
OS.Alert("Image Upload Success!","success");
}
}

2
project.godot

@ -12,7 +12,7 @@ config_version=5 @@ -12,7 +12,7 @@ config_version=5
config/name="EGFramework"
config/tags=PackedStringArray("official")
run/main_scene="res://Example/UsingTest/Scene/TestEGFramework.tscn"
run/main_scene="res://Example/LocalMediaViewer/LocalMediaViewer.tscn"
config/features=PackedStringArray("4.3", "C#", "GL Compatibility")
config/icon="res://icon.svg"

Loading…
Cancel
Save