@@ -6,7 +6,7 @@ use crate::asset::*;
66use crate :: asset:: frame:: FrameId ;
77use crate :: asset:: message:: { Messages , MessageId } ;
88use crate :: fs:: FileSystem ;
9- use crate :: game:: object:: { self , EquipmentSlot , Object , InventoryItem } ;
9+ use crate :: game:: object:: { self , EquipmentSlot , Hand , Object , InventoryItem } ;
1010use crate :: game:: rpg:: Rpg ;
1111use crate :: game:: ui:: action_menu:: { self , Action } ;
1212use crate :: game:: ui:: inventory_list:: { self , InventoryList , Scroll , MouseMode } ;
@@ -85,8 +85,8 @@ impl Inventory {
8585 }
8686
8787 fn show ( & mut self , rpg : & Rpg , ui : & mut Ui ) {
88- let obj = self . world . borrow ( ) . dude_obj ( ) . unwrap ( ) ;
89- let internal = Internal :: new ( self . msgs . take ( ) . unwrap ( ) , self . world . clone ( ) , obj , ui) ;
88+ let owner = self . world . borrow ( ) . dude_obj ( ) . unwrap ( ) ;
89+ let internal = Internal :: new ( self . msgs . take ( ) . unwrap ( ) , self . world . clone ( ) , owner , ui) ;
9090 internal. sync_mouse_mode_to_ui ( ui) ;
9191 internal. sync_from_obj ( rpg, ui) ;
9292 assert ! ( self . internal. replace( internal) . is_none( ) ) ;
@@ -108,7 +108,7 @@ enum Slot {
108108struct Internal {
109109 msgs : Messages ,
110110 world : WorldRef ,
111- obj : object:: Handle ,
111+ owner : object:: Handle ,
112112 win : ui:: Handle ,
113113 mouse_mode : MouseMode ,
114114 list : ui:: Handle ,
@@ -129,7 +129,7 @@ struct Internal {
129129}
130130
131131impl Internal {
132- fn new ( msgs : Messages , world : WorldRef , obj : object:: Handle , ui : & mut Ui ) -> Self {
132+ fn new ( msgs : Messages , world : WorldRef , owner : object:: Handle , ui : & mut Ui ) -> Self {
133133 let win = ui. new_window ( Rect :: with_size ( 80 , 0 , 499 , 377 ) ,
134134 Some ( Sprite :: new ( FrameId :: INVENTORY_WINDOW ) ) ) ;
135135 ui. set_modal_window ( Some ( win) ) ;
@@ -220,7 +220,7 @@ impl Internal {
220220 Self {
221221 msgs,
222222 world,
223- obj ,
223+ owner ,
224224 win,
225225 mouse_mode : MouseMode :: Drag ,
226226 list,
@@ -255,8 +255,8 @@ impl Internal {
255255 right_hand. clear ( ) ;
256256
257257 let world = self . world . borrow ( ) ;
258- let obj = world. objects ( ) . get ( self . obj ) ;
259- for item in & obj . inventory . items {
258+ let owner = world. objects ( ) . get ( self . owner ) ;
259+ for item in & owner . inventory . items {
260260 let item_obj = & world. objects ( ) . get ( item. object ) ;
261261 let inv_list_item = Self :: make_list_item ( item, item_obj) ;
262262 match ( ) {
@@ -343,10 +343,10 @@ impl Internal {
343343 // display_stats
344344 fn update_stats ( & self , rpg : & Rpg , ui : & Ui ) {
345345 let world = self . world . borrow ( ) ;
346- let name = world. object_name ( self . obj ) . unwrap ( ) ;
347- let obj = & world. objects ( ) . get ( self . obj ) ;
346+ let name = world. object_name ( self . owner ) . unwrap ( ) ;
347+ let owner = & world. objects ( ) . get ( self . owner ) ;
348348
349- let stat = |stat| rpg. stat ( stat, obj , world. objects ( ) ) ;
349+ let stat = |stat| rpg. stat ( stat, owner , world. objects ( ) ) ;
350350 let msg = |id| & self . msgs . get ( id) . unwrap ( ) . text ;
351351
352352 let mut cols = [ BString :: new ( ) , BString :: new ( ) , BString :: new ( ) , BString :: new ( ) ] ;
@@ -395,8 +395,8 @@ impl Internal {
395395 misc. push_str ( name) ;
396396 misc. push_str ( "\n ---------------------\n \n \n \n \n \n \n \n " ) ;
397397
398- for & slot in & [ EquipmentSlot :: LeftHand , EquipmentSlot :: RightHand ] {
399- let item = obj . equipment ( slot, world. objects ( ) ) ;
398+ for & slot in & [ EquipmentSlot :: Hand ( Hand :: Left ) , EquipmentSlot :: Hand ( Hand :: Right ) ] {
399+ let item = owner . equipment ( slot, world. objects ( ) ) ;
400400 misc. push_str ( "---------------------\n " ) ;
401401 if let Some ( item) = item {
402402 let item = & world. objects ( ) . get ( item) ;
@@ -479,17 +479,17 @@ impl Internal {
479479 }
480480
481481 let mut total_weight = BString :: new ( ) ;
482- if obj . kind ( ) == EntityKind :: Critter {
482+ if owner . kind ( ) == EntityKind :: Critter {
483483 let cw = stat ( Stat :: CarryWeight ) ;
484- let w = obj . inventory . weight ( world. objects ( ) ) ;
484+ let w = owner . inventory . weight ( world. objects ( ) ) ;
485485 // Total Wt: 100/200
486486 total_weight. push_str ( msg ( MSG_TOTAL_WEIGHT ) ) ;
487487 total_weight. push ( b' ' ) ;
488488 total_weight. push_str ( w. to_bstring ( ) ) ;
489489 total_weight. push ( b'/' ) ;
490490 total_weight. push_str ( cw. to_bstring ( ) ) ;
491491 }
492- let overloaded = obj . is_overloaded ( rpg, world. objects ( ) ) ;
492+ let overloaded = owner . is_overloaded ( rpg, world. objects ( ) ) ;
493493 {
494494 let mut w = ui. widget_mut :: < Panel > ( self . total_weight ) ;
495495 let w = w. text_mut ( ) . unwrap ( ) ;
@@ -562,8 +562,8 @@ impl Internal {
562562 Some ( match ( ) {
563563 _ if widget == self . list => Slot :: Inventory ,
564564 _ if widget == self . wearing => Slot :: Equipment ( EquipmentSlot :: Armor ) ,
565- _ if widget == self . left_hand => Slot :: Equipment ( EquipmentSlot :: LeftHand ) ,
566- _ if widget == self . right_hand => Slot :: Equipment ( EquipmentSlot :: RightHand ) ,
565+ _ if widget == self . left_hand => Slot :: Equipment ( EquipmentSlot :: Hand ( Hand :: Left ) ) ,
566+ _ if widget == self . right_hand => Slot :: Equipment ( EquipmentSlot :: Hand ( Hand :: Right ) ) ,
567567 _ => return None ,
568568 } )
569569 }
@@ -589,7 +589,7 @@ impl Internal {
589589 let ( bump, existing) = match target_slot {
590590 Slot :: Inventory => ( Some ( obj) , None ) ,
591591 Slot :: Equipment ( eq_slot) => {
592- let v = world. objects ( ) . get ( self . obj )
592+ let v = world. objects ( ) . get ( self . owner )
593593 . equipment ( eq_slot, world. objects ( ) ) ;
594594 ( v, v)
595595 }
@@ -609,8 +609,8 @@ impl Internal {
609609
610610 match target_slot {
611611 EquipmentSlot :: Armor => obj. flags . insert ( Flag :: Worn ) ,
612- EquipmentSlot :: LeftHand => obj. flags . insert ( Flag :: LeftHand ) ,
613- EquipmentSlot :: RightHand => obj. flags . insert ( Flag :: RightHand ) ,
612+ EquipmentSlot :: Hand ( Hand :: Left ) => obj. flags . insert ( Flag :: LeftHand ) ,
613+ EquipmentSlot :: Hand ( Hand :: Right ) => obj. flags . insert ( Flag :: RightHand ) ,
614614 }
615615 }
616616 Slot :: Inventory => { }
@@ -621,7 +621,7 @@ impl Internal {
621621
622622 // Bump item: remove from slots and move to inventory top.
623623 if let Some ( bump) = bump {
624- let mut owner = world. objects ( ) . get_mut ( self . obj ) ;
624+ let mut owner = world. objects ( ) . get_mut ( self . owner ) ;
625625 world. objects ( ) . get_mut ( bump)
626626 . flags . remove ( Flag :: Worn | Flag :: LeftHand | Flag :: RightHand ) ;
627627 let i = owner. inventory . items . iter ( )
@@ -633,7 +633,7 @@ impl Internal {
633633 }
634634
635635 {
636- let owner = & mut world. objects ( ) . get_mut ( self . obj ) ;
636+ let owner = & mut world. objects ( ) . get_mut ( self . owner ) ;
637637 if src_slot == Slot :: Equipment ( EquipmentSlot :: Armor ) {
638638 let old_armor = world. objects ( ) . get ( obj) ;
639639 rpg. apply_armor_change ( owner, None , Some ( old_armor) , world. objects ( ) ) ;
@@ -645,6 +645,13 @@ impl Internal {
645645 }
646646
647647 self . sync_from_obj ( rpg, ui) ;
648+ self . sync_owner_fid ( rpg)
649+ }
650+
651+ fn sync_owner_fid ( & self , rpg : & Rpg ) {
652+ let world = self . world . borrow ( ) ;
653+ let mut owner = world. objects ( ) . get_mut ( self . owner ) ;
654+ owner. fid = owner. equipped_fid ( world. objects ( ) , rpg) ;
648655 }
649656}
650657
0 commit comments